use of com.builtbroken.mc.api.rails.ITransportRailBlock in project Engine by VoltzEngine-Project.
the class EntityAbstractCart method onUpdate.
@Override
public void onUpdate() {
this.prevDistanceWalkedModified = this.distanceWalkedModified;
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
// Updates the collision box
if (invalidBox || boundingBox == null) {
validateBoundBox();
}
// Grab rail side if null
if (railSide == null) {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
Pos pos = new Pos((Entity) this).add(side);
Block block = pos.getBlock(worldObj);
final TileEntity tile = pos.getTileEntity(worldObj);
if (!(block instanceof ITransportRailBlock || tile instanceof ITransportRail)) {
railSide = side;
break;
}
}
}
Pos pos = new Pos(Math.floor(posX), Math.floor(posY), Math.floor(posZ)).floor();
Block block = pos.getBlock(world());
if (block == Blocks.air) {
pos = pos.add(railSide);
block = pos.getBlock(worldObj);
}
final TileEntity tile = pos.getTileEntity(worldObj);
if (!worldObj.isRemote) {
// Kills entity if it falls out of the world, should never happen
if (this.posY < -64.0D) {
this.kill();
return;
} else // Breaks entity if its not on a track
if (!(block instanceof ITransportRailBlock || tile instanceof ITransportRail)) {
destroyCart();
return;
}
// Moves the entity
if (motionX != 0 || motionY != 0 || motionZ != 0) {
moveEntity(motionX, motionY, motionZ);
recenterCartOnRail();
}
}
if (isAirBorne) {
motionY -= (9.8 / 20);
motionY = Math.max(-2, motionY);
}
// Handles pushing entities out of the way
doCollisionLogic();
// Updates the rail and cart position
if (tile instanceof ITransportRail) {
((ITransportRail) tile).tickRailFromCart(this);
} else if (block instanceof ITransportRailBlock) {
((ITransportRailBlock) block).tickRailFromCart(this, world(), pos.xi(), pos.yi(), pos.zi(), worldObj.getBlockMetadata(pos.xi(), pos.yi(), pos.zi()));
}
if (!worldObj.isRemote && updateClient) {
sentDescriptionPacket();
}
}
Aggregations