net.minecraft.block.BlockRailBase Java Examples

The following examples show how to use net.minecraft.block.BlockRailBase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RailTools.java    From NEI-Integration with MIT License 6 votes vote down vote up
/**
 * Checks to see if a cart is being held by a ITrackLockdown.
 *
 * @param cart The cart to check
 * @return True if being held
 */
public static boolean isCartLockedDown(EntityMinecart cart) {
    int x = MathHelper.floor_double(cart.posX);
    int y = MathHelper.floor_double(cart.posY);
    int z = MathHelper.floor_double(cart.posZ);

    if (BlockRailBase.func_150049_b_(cart.worldObj, x, y - 1, z))
        y--;

    TileEntity tile = cart.worldObj.getTileEntity(x, y, z);
    if (tile instanceof ITrackTile) {
        ITrackInstance track = ((ITrackTile) tile).getTrackInstance();
        return track instanceof ITrackLockdown && ((ITrackLockdown) track).isCartLockedDown(cart);
    } else if (tile instanceof ITrackLockdown)
        return ((ITrackLockdown) tile).isCartLockedDown(cart);
    return false;
}
 
Example #2
Source File: SignalsConfig.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
public void initDefaults(){
    if(validItems.length == 0) {
        List<Item> items = new ArrayList<>();
        items.add(ModItems.RAIL_CONFIGURATOR);
        items.add(Item.getItemFromBlock(ModBlocks.RAIL_LINK));

        for(Item item : Item.REGISTRY) {
            if(item instanceof ItemBlock) {
                Block block = ((ItemBlock)item).getBlock();
                if(block instanceof BlockSignalBase || block instanceof BlockRailBase) {
                    items.add(item);
                }
            }
        }

        validItems = new String[items.size()];
        for(int i = 0; i < items.size(); i++) {
            validItems[i] = Item.REGISTRY.getNameForObject(items.get(i)).toString();
        }
    }
}
 
Example #3
Source File: TrackInstanceBase.java    From NEI-Integration with MIT License 5 votes vote down vote up
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);
}
 
Example #4
Source File: CrowbarBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    IBlockState blockState = world.getBlockState(blockPos);
    if (GTUtility.doDamageItem(stack, cost, true)) {
        if (blockState.getBlock() instanceof BlockRailBase) {
            if (world.isRemote) {
                //always return success on client side
                return EnumActionResult.SUCCESS;
            } else if (player.isSneaking()) {
                if (tryBreakRailBlock(blockState, world, blockPos, player)) {
                    GTUtility.doDamageItem(stack, cost, false);
                    return EnumActionResult.SUCCESS;
                }
                return EnumActionResult.FAIL;
            } else {
                if (tryRotateRailBlock(blockState, world, blockPos)) {
                    GTUtility.doDamageItem(stack, cost, false);
                    return EnumActionResult.SUCCESS;
                }
                return EnumActionResult.FAIL;
            }
        }
        TileEntity tileEntity = world.getTileEntity(blockPos);
        ICoverable coverable = tileEntity == null ? null : tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_COVERABLE, null);
        EnumFacing coverSide = coverable == null ? null : ICoverable.rayTraceCoverableSide(coverable, player);
        if (coverSide != null && coverable.getCoverAtSide(coverSide) != null) {
            if (world.isRemote) {
                //always return success on client side
                return EnumActionResult.SUCCESS;
            }
            boolean result = coverable.removeCover(coverSide);
            GTUtility.doDamageItem(stack, cost, false);
            return result ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
        }
    }
    return EnumActionResult.PASS;
}
 
Example #5
Source File: CrowbarBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean tryRotateRailBlock(IBlockState blockState, World world, BlockPos blockPos) {
    BlockRailBase blockRailBase = (BlockRailBase) blockState.getBlock();
    int rotation = blockState.getValue(blockRailBase.getShapeProperty()).ordinal() + 1;
    if (rotation >= BlockRailBase.EnumRailDirection.values().length) {
        rotation = 0;
    }
    return world.setBlockState(blockPos, blockState.withProperty(blockRailBase.getShapeProperty(),
        BlockRailBase.EnumRailDirection.values()[rotation]));
}
 
Example #6
Source File: MixinBlockRail.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(method = "withRotation", at = @At("HEAD"), cancellable = true)
private void fixRailRotation(IBlockState state, Rotation rot, CallbackInfoReturnable<IBlockState> cir)
{
    if (Configs.Generic.FIX_RAIL_ROTATION.getBooleanValue() && rot == Rotation.CLOCKWISE_180)
    {
        BlockRailBase.EnumRailDirection dir = null;

        if (((Object) this) instanceof BlockRail)
        {
            dir = state.getValue(BlockRail.SHAPE);
        }
        else if (((Object) this) instanceof BlockRailDetector)
        {
            dir = state.getValue(BlockRailDetector.SHAPE);
        }
        else if (((Object) this) instanceof BlockRailPowered)
        {
            dir = state.getValue(BlockRailPowered.SHAPE);
        }

        // Fix the incomplete switch statement causing the ccw_90 rotation being used instead
        // for the 180 degree rotation of the straight rails.
        if (dir == BlockRailBase.EnumRailDirection.EAST_WEST || dir == BlockRailBase.EnumRailDirection.NORTH_SOUTH)
        {
            cir.setReturnValue(state);
            cir.cancel();
        }
    }
}
 
Example #7
Source File: StructureTofuMineshaftPieces.java    From TofuCraftReload with MIT License 5 votes vote down vote up
/**
 * Adds chest to the structure and sets its contents
 */
protected boolean generateChest(World worldIn, StructureBoundingBox structurebb, Random randomIn, int x, int y, int z, ResourceLocation loot) {
    BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));

    if (structurebb.isVecInside(blockpos) && worldIn.getBlockState(blockpos).getMaterial() == Material.AIR && worldIn.getBlockState(blockpos.down()).getMaterial() != Material.AIR) {
        IBlockState iblockstate = Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, randomIn.nextBoolean() ? BlockRailBase.EnumRailDirection.NORTH_SOUTH : BlockRailBase.EnumRailDirection.EAST_WEST);
        this.setBlockState(worldIn, iblockstate, x, y, z, structurebb);
        EntityMinecartChest entityminecartchest = new EntityMinecartChest(worldIn, (double) ((float) blockpos.getX() + 0.5F), (double) ((float) blockpos.getY() + 0.5F), (double) ((float) blockpos.getZ() + 0.5F));
        entityminecartchest.setLootTable(loot, randomIn.nextLong());
        worldIn.spawnEntity(entityminecartchest);
        return true;
    } else {
        return false;
    }
}
 
Example #8
Source File: RailReplacerEventHandler.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Makes it so when a player right clicks a rail block with a different rail item, it will be replaced, without having to remove and place a rail.
 * TODO: Replace signal types
 * @param e
 */
@SubscribeEvent
public void onBlockInteraction(RightClickBlock e){
    if(!e.getWorld().isRemote && e.getFace() == EnumFacing.UP) {
        ItemStack stack = e.getEntityPlayer().getHeldItemMainhand();
        BlockRailBase railBlock = getRailBlock(stack);
        if(railBlock != null) {
            IBlockState state = e.getWorld().getBlockState(e.getPos());
            IRail rail = RailManager.getInstance().getRail(e.getWorld(), e.getPos(), state);
            if(rail != null && state.getBlock() != railBlock) {
                EnumRailDirection dir = rail.getDirection(e.getWorld(), e.getPos(), state);
                e.getWorld().destroyBlock(e.getPos(), !e.getEntityPlayer().isCreative());
                List<EntityItem> drops = e.getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(e.getPos()));
                for(EntityItem drop : drops) {
                    drop.setPickupDelay(0);
                    drop.onCollideWithPlayer(e.getEntityPlayer());
                }

                e.getWorld().setBlockState(e.getPos(), railBlock.getDefaultState());
                if(!e.getEntityPlayer().isCreative()) stack.shrink(1);

                //Set the rail orientation equal to the old rail, if possible.
                if(railBlock.getShapeProperty().getAllowedValues().contains(dir)) {
                    IBlockState curState = e.getWorld().getBlockState(e.getPos());
                    e.getWorld().setBlockState(e.getPos(), curState.withProperty(railBlock.getShapeProperty(), dir));
                }
            }
        }
    }
}
 
Example #9
Source File: RailReplacerEventHandler.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
private static BlockRailBase getRailBlock(ItemStack stack){
    if(stack.getItem() instanceof ItemBlock) {
        ItemBlock item = (ItemBlock)stack.getItem();
        return item.getBlock() instanceof BlockRailBase ? (BlockRailBase)item.getBlock() : null; //Only allow simple registered IRails to be placed
    }
    return null;
}
 
Example #10
Source File: BlockTeleportRail.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Convert the given metadata into a BlockState for this Block
 */
@Override
public IBlockState getStateFromMeta(int meta){
    return this.getDefaultState().withProperty(getShapeProperty(), BlockRailBase.EnumRailDirection.byMetadata(meta >> 1)).withProperty(FORWARD, (meta & 1) > 0);
}
 
Example #11
Source File: RailTools.java    From NEI-Integration with MIT License 4 votes vote down vote up
public static boolean isTrackFuzzyAt(World world, int x, int y, int z) {
    return BlockRailBase.func_150049_b_(world, x, y, z) ? true : (BlockRailBase.func_150049_b_(world, x, y + 1, z) ? true : BlockRailBase.func_150049_b_(world, x, y - 1, z));
}
 
Example #12
Source File: RailTools.java    From NEI-Integration with MIT License 4 votes vote down vote up
/**
 * Attempts to place a rail of the type provided. There is no need to verify
 * that the ItemStack contains a valid rail prior to calling this function.
 *
 * The function takes care of that and will return false if the ItemStack is
 * not a valid ITrackItem or an ItemBlock who's id will return true when
 * passed to BlockRailBase.isRailBlock(itemID).
 *
 * That means this function can place any Railcraft or vanilla rail and has
 * at least a decent chance of being able to place most third party rails.
 *
 * @param stack The ItemStack containing the rail
 * @param world The World object
 * @param i x-Coord
 * @param j y-Coord
 * @param k z-Coord
 * @return true if successful
 * @see ITrackItem
 */
public static boolean placeRailAt(ItemStack stack, World world, int i, int j, int k) {
    if (stack == null)
        return false;
    if (stack.getItem() instanceof ITrackItem)
        return ((ITrackItem) stack.getItem()).placeTrack(stack.copy(), world, i, j, k);
    if (stack.getItem() instanceof ItemBlock) {
        Block block = ((ItemBlock) stack.getItem()).field_150939_a;
        if (BlockRailBase.func_150051_a(block)) {
            boolean success = world.setBlock(i, j, k, block);
            if (success)
                world.playSoundEffect((float) i + 0.5F, (float) j + 0.5F, (float) k + 0.5F, block.stepSound.func_150496_b(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
            return success;
        }
    }
    return false;
}
 
Example #13
Source File: CartTools.java    From NEI-Integration with MIT License 4 votes vote down vote up
public static boolean isMinecartOnRailAt(World world, int i, int j, int k, float sensitivity, Class<? extends EntityMinecart> type, boolean subclass) {
    if (BlockRailBase.func_150049_b_(world, i, j, k))
        return isMinecartAt(world, i, j, k, sensitivity, type, subclass);
    return false;
}
 
Example #14
Source File: RailMapperBlockRail.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IRail getRail(World world, BlockPos pos, IBlockState state){
    return state.getBlock() instanceof BlockRailBase ? RAIL : null;
}
 
Example #15
Source File: RailBase.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setDirection(World world, BlockPos pos, IBlockState originalState, EnumRailDirection railDir){
    world.setBlockState(pos, originalState.withProperty(((BlockRailBase)originalState.getBlock()).getShapeProperty(), railDir), 2);
}
 
Example #16
Source File: RailBase.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EnumSet<EnumRailDirection> getValidDirections(World world, BlockPos pos, IBlockState state){
    return EnumSet.copyOf(((BlockRailBase)state.getBlock()).getShapeProperty().getAllowedValues());
}
 
Example #17
Source File: RailBase.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EnumRailDirection getDirection(World world, BlockPos pos, IBlockState state){
    return state.getValue(((BlockRailBase)state.getBlock()).getShapeProperty());
}
 
Example #18
Source File: StructureTofuMineshaftPieces.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes
 * Mineshafts at the end, it adds Fences...
 */
public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) {
    if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn)) {
        return false;
    } else {

        int i1 = this.sectionCount * 5 - 1;
        IBlockState iblockstate = this.getPlanksBlock();
        this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 0, 2, 1, i1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false);
        this.generateMaybeBox(worldIn, structureBoundingBoxIn, randomIn, 0.8F, 0, 2, 0, 2, 2, i1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false, 0);

        if (this.hasSpiders) {
            this.generateMaybeBox(worldIn, structureBoundingBoxIn, randomIn, 0.6F, 0, 0, 0, 2, 1, i1, Blocks.WEB.getDefaultState(), Blocks.AIR.getDefaultState(), false, 8);
        }

        for (int j1 = 0; j1 < this.sectionCount; ++j1) {
            int k1 = 2 + j1 * 5;
            this.placeSupport(worldIn, structureBoundingBoxIn, 0, 0, k1, 2, 2, randomIn);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 - 1);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 - 1);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 + 1);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 + 1);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 - 2);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 - 2);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 + 2);
            this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 + 2);

            if (randomIn.nextInt(100) == 0) {
                this.generateChest(worldIn, structureBoundingBoxIn, randomIn, 2, 0, k1 - 1, TofuLootTables.tofumineshaft);
            }

            if (randomIn.nextInt(100) == 0) {
                this.generateChest(worldIn, structureBoundingBoxIn, randomIn, 0, 0, k1 + 1, TofuLootTables.tofumineshaft);
            }

            if (this.hasSpiders && !this.spawnerPlaced) {
                int l1 = this.getYWithOffset(0);
                int i2 = k1 - 1 + randomIn.nextInt(3);
                int j2 = this.getXWithOffset(1, i2);
                int k2 = this.getZWithOffset(1, i2);
                BlockPos blockpos = new BlockPos(j2, l1, k2);

                if (structureBoundingBoxIn.isVecInside(blockpos) && this.getSkyBrightness(worldIn, 1, 0, i2, structureBoundingBoxIn) < 8) {
                    this.spawnerPlaced = true;
                    worldIn.setBlockState(blockpos, Blocks.MOB_SPAWNER.getDefaultState(), 2);
                    TileEntity tileentity = worldIn.getTileEntity(blockpos);

                    if (tileentity instanceof TileEntityMobSpawner) {
                        ((TileEntityMobSpawner) tileentity).getSpawnerBaseLogic().setEntityId(EntityList.getKey(EntityTofuSpider.class));
                    }
                }
            }
        }

        for (int l2 = 0; l2 <= 2; ++l2) {
            for (int i3 = 0; i3 <= i1; ++i3) {
                IBlockState iblockstate3 = this.getBlockStateFromPos(worldIn, l2, -1, i3, structureBoundingBoxIn);

                if (iblockstate3.getMaterial() == Material.AIR && this.getSkyBrightness(worldIn, l2, -1, i3, structureBoundingBoxIn) < 8) {
                    this.setBlockState(worldIn, iblockstate, l2, -1, i3, structureBoundingBoxIn);
                }
            }
        }

        if (this.hasRails) {
            IBlockState iblockstate1 = Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH);

            for (int j3 = 0; j3 <= i1; ++j3) {
                IBlockState iblockstate2 = this.getBlockStateFromPos(worldIn, 1, -1, j3, structureBoundingBoxIn);

                if (iblockstate2.getMaterial() != Material.AIR && iblockstate2.isFullBlock()) {
                    float f = this.getSkyBrightness(worldIn, 1, 0, j3, structureBoundingBoxIn) > 8 ? 0.9F : 0.7F;
                    this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, f, 1, 0, j3, iblockstate1);
                }
            }
        }

        return true;
    }
}