Search in sources :

Example 6 with BlockRailBase

use of net.minecraft.block.BlockRailBase in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class TrackInstanceBase method switchTrack.

protected void switchTrack(boolean flag) {
    int x = tileEntity.xCoord;
    int y = tileEntity.yCoord;
    int z = tileEntity.zCoord;
    BlockRailBase blockTrack = (BlockRailBase) getBlock();
    blockTrack.new Rail(getWorld(), x, y, z).func_150655_a(getWorld().isBlockIndirectlyGettingPowered(x, y, z), flag);
}
Also used : BlockRailBase(net.minecraft.block.BlockRailBase)

Example 7 with BlockRailBase

use of net.minecraft.block.BlockRailBase in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class RailUtility method placeOnRail.

/**
     * <h2>rail placement from item</h2>
     * basic functionality to place a train or rollingstock on the rails on item use.
     */
public static boolean placeOnRail(GenericRailTransport entity, EntityPlayer playerEntity, World worldObj, int posX, int posY, int posZ) {
    //be sure there is a rail at the location
    if (RailUtility.isRailBlockAt(worldObj, posX, posY, posZ) && !worldObj.isRemote) {
        //define the direction
        int playerMeta = MathHelper.floor_double((playerEntity.rotationYaw / 90.0F) + 2.5D) & 3;
        //check rail axis
        if (((BlockRailBase) worldObj.getBlock(posX, posY, posZ)).getBasicRailMetadata(worldObj, null, posX, posY, posZ) == 1) {
            //check player direction
            if (playerMeta == 3) {
                //check if the transport can be placed in the area
                if (!RailUtility.isRailBlockAt(worldObj, posX + MathHelper.floor_double(entity.getRenderBogieOffsets().get(entity.getRenderBogieOffsets().size() - 1) + 1.0D), posY, posZ) && !RailUtility.isRailBlockAt(worldObj, posX + MathHelper.floor_double(entity.getRenderBogieOffsets().get(0) - 1.0D), posY, posZ)) {
                    playerEntity.addChatMessage(new ChatComponentText("Place on a straight piece of track that is of sufficient length"));
                    return false;
                }
                entity.rotationYaw = 0;
                //spawn the entity
                worldObj.spawnEntityInWorld(entity);
                return true;
            } else //same as above, but reverse direction.
            if (playerMeta == 1) {
                if (!RailUtility.isRailBlockAt(worldObj, posX - MathHelper.floor_double(entity.getRenderBogieOffsets().get(entity.getRenderBogieOffsets().size() - 1) + 1.0D), posY, posZ) && !RailUtility.isRailBlockAt(worldObj, posX - MathHelper.floor_double(entity.getRenderBogieOffsets().get(0) - 1.0D), posY, posZ)) {
                    playerEntity.addChatMessage(new ChatComponentText("Place on a straight piece of track that is of sufficient length"));
                    return false;
                }
                entity.rotationYaw = 180;
                worldObj.spawnEntityInWorld(entity);
                return true;
            }
        } else //same as above but a different axis.
        if (((BlockRailBase) worldObj.getBlock(posX, posY, posZ)).getBasicRailMetadata(worldObj, null, posX, posY, posZ) == 0) {
            if (playerMeta == 0) {
                if (!RailUtility.isRailBlockAt(worldObj, posX, posY, posZ + MathHelper.floor_double(entity.getRenderBogieOffsets().get(entity.getRenderBogieOffsets().size() - 1) + 1.0D)) && !RailUtility.isRailBlockAt(worldObj, posX, posY, posZ + MathHelper.floor_double(entity.getRenderBogieOffsets().get(0) - 1.0D))) {
                    playerEntity.addChatMessage(new ChatComponentText("Place on a straight piece of track that is of sufficient length"));
                    return false;
                }
                entity.rotationYaw = 90;
                worldObj.spawnEntityInWorld(entity);
                return true;
            } else if (playerMeta == 2) {
                if (!RailUtility.isRailBlockAt(worldObj, posX, posY, posZ - MathHelper.floor_double(entity.getRenderBogieOffsets().get(entity.getRenderBogieOffsets().size() - 1) + 1.0D)) && !RailUtility.isRailBlockAt(worldObj, posX, posY, posZ - MathHelper.floor_double(entity.getRenderBogieOffsets().get(0) - 1.0D))) {
                    playerEntity.addChatMessage(new ChatComponentText("Place on a straight piece of track that is of sufficient length"));
                    return false;
                }
                entity.rotationYaw = 270;
                worldObj.spawnEntityInWorld(entity);
                return true;
            }
        }
    }
    return false;
}
Also used : ChatComponentText(net.minecraft.util.ChatComponentText) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 8 with BlockRailBase

use of net.minecraft.block.BlockRailBase in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class EntityBogie method minecartMove.

/**
     * <h2> movement management</h2>
     * this is modified movement from the super class, should be more efficient, and reliable, but generally does the same thing, minus ability to collide.
     * @see EntityMinecart#onUpdate()
     * Some features are replaced using our own for compatibility with ZoraNoDensha
     * @see RailUtility
     */
public void minecartMove(float yaw, float pitch, boolean brake, boolean isRunning, boolean isTrain) {
    //define the yaw from the super
    this.setRotation(yaw, pitch);
    //client only, update position
    if (this.worldObj.isRemote) {
        if (motionProgress > 0) {
            this.posX += (prevPosX - this.posX) / motionProgress;
            this.posY += (((prevPosY - this.posY) + yOffset) / motionProgress);
            this.posZ += (prevPosZ - this.posZ) / motionProgress;
            --motionProgress;
        }
    } else //server only
    {
        //update old position, add the gravity, and get the block below this,
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
        int floorX = MathHelper.floor_double(this.posX);
        int floorY = MathHelper.floor_double(this.posY);
        int floorZ = MathHelper.floor_double(this.posZ);
        //compensate for y offsets based on current position, just in case the movement is too steep.
        if (!BlockRailBase.func_150049_b_(this.worldObj, floorX, floorY, floorZ)) {
            if (BlockRailBase.func_150049_b_(this.worldObj, floorX, floorY - 1, floorZ)) {
                --floorY;
            } else if (worldObj.getBlock(floorX, floorY, floorZ) instanceof BlockAir && worldObj.getBlock(floorX, floorY - 1, floorZ) instanceof BlockAir && posY > -64) {
                posY -= 0.1D;
            }
        }
        //apply brake
        if (brake) {
            if (motionX < 0.1 && motionX > -0.1) {
                motionX = 0;
                this.cartVelocityX = 0;
            } else {
                this.motionX *= 0.75;
                this.cartVelocityX *= 0.75;
            }
            if (motionZ < 0.1 && motionZ > -0.1) {
                motionZ = 0;
                this.cartVelocityZ = 0;
            } else {
                this.motionZ *= 0.75;
                this.cartVelocityZ *= 0.75;
            }
        } else if (isRunning && !isTrain) {
            if (motionX < 0.05 && motionX > -0.05) {
                motionX = 0;
                this.cartVelocityX = 0;
            } else {
                this.motionX *= 0.75;
                this.cartVelocityX *= 0.75;
            }
            if (motionZ < 0.05 && motionZ > -0.05) {
                motionZ = 0;
                this.cartVelocityZ = 0;
            } else {
                this.motionZ *= 0.75;
                this.cartVelocityZ *= 0.75;
            }
        }
        //update on normal rails
        if (worldObj.getBlock(floorX, floorY, floorZ) instanceof BlockRailBase) {
            Block block = this.worldObj.getBlock(floorX, floorY, floorZ);
            moveBogie(this.motionX, this.motionZ, floorX, floorY, floorZ, block);
            this.fallDistance = 0.0F;
            if (block == Blocks.activator_rail) {
                this.onActivatorRailPass(floorX, floorY, floorZ, (worldObj.getBlockMetadata(floorX, floorY, floorZ) & 8) != 0);
            }
        //update on ZnD rails, and ones that don't extend block rail base.
        } else {
            super.onUpdate();
        }
    }
}
Also used : BlockAir(net.minecraft.block.BlockAir) Block(net.minecraft.block.Block) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 9 with BlockRailBase

use of net.minecraft.block.BlockRailBase in project Railcraft by Railcraft.

the class RenderTrack method renderWorldBlock.

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderblocks) {
    int meta = ((BlockRailBase) block).getBasicRailMetadata(world, null, x, y, z);
    IIcon icon;
    TileEntity tile = world.getTileEntity(x, y, z);
    ITrackInstance track = null;
    if (tile instanceof TileTrack) {
        track = ((TileTrack) tile).getTrackInstance();
        icon = renderblocks.getIconSafe(track.getIcon());
    } else {
        icon = Blocks.RAIL.getIcon(0, 0);
    }
    if (renderblocks.hasOverrideBlockTexture()) {
        icon = renderblocks.overrideBlockTexture;
    }
    float minU = icon.getMinU();
    float minV = icon.getMinV();
    float maxU = icon.getMaxU();
    float maxV = icon.getMaxV();
    double pix = 0.0625D;
    double vertX1 = x + 1;
    double vertX2 = x + 1;
    double vertX3 = x + 0;
    double vertX4 = x + 0;
    double vertZ1 = z + 0;
    double vertZ2 = z + 1;
    double vertZ3 = z + 1;
    double vertZ4 = z + 0;
    double vertY1 = y + pix;
    double vertY2 = y + pix;
    double vertY3 = y + pix;
    double vertY4 = y + pix;
    if (meta != 1 && meta != 2 && meta != 3 && meta != 7) {
        if (meta == 8) {
            vertX1 = vertX2 = x + 0;
            vertX3 = vertX4 = x + 1;
            vertZ1 = vertZ4 = z + 1;
            vertZ2 = vertZ3 = z + 0;
        } else if (meta == 9) {
            vertX1 = vertX4 = x + 0;
            vertX2 = vertX3 = x + 1;
            vertZ1 = vertZ2 = z + 0;
            vertZ3 = vertZ4 = z + 1;
        }
    } else {
        vertX1 = vertX4 = x + 1;
        vertX2 = vertX3 = x + 0;
        vertZ1 = vertZ2 = z + 1;
        vertZ3 = vertZ4 = z + 0;
    }
    if (meta != 2 && meta != 4) {
        if (meta == 3 || meta == 5) {
            vertY2++;
            vertY3++;
        }
    } else {
        vertY1++;
        vertY4++;
    }
    if (track != null) {
        if (track instanceof ITrackSwitch) {
            ITrackSwitch switchTrack = (ITrackSwitch) track;
            if (switchTrack.isMirrored()) {
                float temp = minU;
                minU = maxU;
                maxU = temp;
                temp = minV;
                minV = maxV;
                maxV = temp;
            }
        } else if (track instanceof TrackGated) {
            renderGatedTrack(renderblocks, (TrackGated) track, x, y, z, meta);
        }
    }
    Tessellator tess = Tessellator.instance;
    tess.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
    tess.setColorOpaque_F(1.0F, 1.0F, 1.0F);
    tess.addVertexWithUV(vertX1, vertY1, vertZ1, maxU, minV);
    tess.addVertexWithUV(vertX2, vertY2, vertZ2, maxU, maxV);
    tess.addVertexWithUV(vertX3, vertY3, vertZ3, minU, maxV);
    tess.addVertexWithUV(vertX4, vertY4, vertZ4, minU, minV);
    tess.addVertexWithUV(vertX4, vertY4, vertZ4, minU, minV);
    tess.addVertexWithUV(vertX3, vertY3, vertZ3, minU, maxV);
    tess.addVertexWithUV(vertX2, vertY2, vertZ2, maxU, maxV);
    tess.addVertexWithUV(vertX1, vertY1, vertZ1, maxU, minV);
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileTrack(mods.railcraft.common.blocks.tracks.TileTrack) ITrackSwitch(mods.railcraft.api.tracks.ITrackSwitch) Tessellator(net.minecraft.client.renderer.Tessellator) TrackGated(mods.railcraft.common.blocks.tracks.outfitted.kits.TrackGated) ITrackInstance(mods.railcraft.api.tracks.ITrackInstance) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 10 with BlockRailBase

use of net.minecraft.block.BlockRailBase in project Railcraft by Railcraft.

the class RenderCart method getPosOffset.

private Vec3d getPosOffset(EntityMinecart cart, double x, double y, double z, double offset) {
    int i = MathHelper.floor_double(x);
    int j = MathHelper.floor_double(y);
    int k = MathHelper.floor_double(z);
    if (BlockRailBase.isRailBlock(cart.worldObj, new BlockPos(i, j - 1, k))) {
        --j;
    }
    IBlockState iblockstate = cart.worldObj.getBlockState(new BlockPos(i, j, k));
    if (BlockRailBase.isRailBlock(iblockstate)) {
        BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = ((BlockRailBase) iblockstate.getBlock()).getRailDirection(cart.worldObj, new BlockPos(i, j, k), iblockstate, cart);
        y = (double) j;
        if (blockrailbase$enumraildirection.isAscending()) {
            y = (double) (j + 1);
        }
        int[][] aint = MATRIX[blockrailbase$enumraildirection.getMetadata()];
        double d0 = (double) (aint[1][0] - aint[0][0]);
        double d1 = (double) (aint[1][2] - aint[0][2]);
        double d2 = Math.sqrt(d0 * d0 + d1 * d1);
        d0 = d0 / d2;
        d1 = d1 / d2;
        x = x + d0 * offset;
        z = z + d1 * offset;
        if (aint[0][1] != 0 && MathHelper.floor_double(x) - i == aint[0][0] && MathHelper.floor_double(z) - k == aint[0][2]) {
            y += (double) aint[0][1];
        } else if (aint[1][1] != 0 && MathHelper.floor_double(x) - i == aint[1][0] && MathHelper.floor_double(z) - k == aint[1][2]) {
            y += (double) aint[1][1];
        }
        return getPos(cart, x, y, z);
    } else {
        return null;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) BlockRailBase(net.minecraft.block.BlockRailBase)

Aggregations

BlockRailBase (net.minecraft.block.BlockRailBase)18 Block (net.minecraft.block.Block)11 Vec3 (net.minecraft.util.Vec3)5 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 List (java.util.List)2 IBlockState (net.minecraft.block.state.IBlockState)2 Entity (net.minecraft.entity.Entity)2 EntityMinecart (net.minecraft.entity.item.EntityMinecart)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 WorldServer (net.minecraft.world.WorldServer)2 MinecartUpdateEvent (net.minecraftforge.event.entity.minecart.MinecartUpdateEvent)2 BlockRailReception (club.nsdn.nyasamarailway.block.rail.special.BlockRailReception)1 BlockRailReceptionAnti (club.nsdn.nyasamarailway.block.rail.special.BlockRailReceptionAnti)1 RailMonoMagnetReception (club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReception)1 RailMonoMagnetReceptionAnti (club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReceptionAnti)1 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)1 NoteTypes (com.microsoft.Malmo.Schemas.NoteTypes)1 ShapeTypes (com.microsoft.Malmo.Schemas.ShapeTypes)1