Search in sources :

Example 1 with ITransportRailBlock

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();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITransportRailBlock(com.builtbroken.mc.api.rails.ITransportRailBlock) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.lib.transform.vector.Pos) ITransportRail(com.builtbroken.mc.api.rails.ITransportRail) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ITransportRailBlock(com.builtbroken.mc.api.rails.ITransportRailBlock) Block(net.minecraft.block.Block)

Aggregations

ITransportRail (com.builtbroken.mc.api.rails.ITransportRail)1 ITransportRailBlock (com.builtbroken.mc.api.rails.ITransportRailBlock)1 Pos (com.builtbroken.mc.lib.transform.vector.Pos)1 Block (net.minecraft.block.Block)1 Entity (net.minecraft.entity.Entity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1