Skip to content

Commit

Permalink
Working on Speed change on asphalt block. will need to move to slabs …
Browse files Browse the repository at this point in the history
…once slabs are implemented
  • Loading branch information
TechStack committed Mar 4, 2015
1 parent 12fa2dd commit 531729b
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.projectreddog.machinemod.block;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;

import com.projectreddog.machinemod.entity.EntityMachineModRideable;
import com.projectreddog.machinemod.reference.Reference;

public class BlockMachineAsphalt extends BlockMachineMod {
Expand All @@ -12,4 +20,37 @@ public BlockMachineAsphalt() {
this.setHardness(15f);// not sure on the hardness
this.setStepSound(soundTypeStone);
}

public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
float f = 0.125F;
return new AxisAlignedBB((double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), (double) (pos.getX() + 1), (double) ((float) (pos.getY() + 1) - f), (double) (pos.getZ() + 1));
}

/**
* Called When an Entity Collided with the Block
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entity) {
double savedSpeed = Math.sqrt(entity.motionZ * entity.motionZ + entity.motionX * entity.motionX);
if (!(entity instanceof EntityPlayer)) {
// not a player
if (!(entity instanceof EntityMachineModRideable)) {
// not a machine mod rideable
return;

} else if (!((EntityMachineModRideable) entity).isPlayerAccelerating && !((EntityMachineModRideable) entity).isPlayerBreaking) {
// is a machine mod rideable but no movment
return;
}

} else if (((EntityPlayer) entity).moveForward < .8f && ((EntityPlayer) entity).moveStrafing < .8f) {
return;
// player no longer trying to move
}

if (savedSpeed != 0) {

entity.motionZ = entity.motionZ * .4 / savedSpeed;
entity.motionX = entity.motionX * .4 / savedSpeed;
}
}
}

0 comments on commit 531729b

Please sign in to comment.