net.minecraft.block.BlockRail Java Examples

The following examples show how to use net.minecraft.block.BlockRail. 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: WorldGeneratorSignals.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider){
    // TODO when adding worldgen, resolve the note at https://github.com/MineMaarten/Signals/pull/80 regarding the possibility of rails not being included in the network.
    if(chunkX == 0) {
        int x = chunkX * 16 + 8;
        int y = 4;
        int startZ = chunkZ * 16;
        for(int z = startZ; z < startZ + 16; z++) {
            world.setBlockState(new BlockPos(x, y, z), Blocks.STONE.getDefaultState(), 0);
            world.setBlockState(new BlockPos(x, y + 1, z), Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, EnumRailDirection.NORTH_SOUTH), 0);
            if(z % 256 == 0) {
                world.setBlockState(new BlockPos(x + 1, y + 1, z), ModBlocks.BLOCK_SIGNAL.getDefaultState().withProperty(BlockSignalBase.FACING, EnumFacing.NORTH), 0);

            }
        }
    }
}
 
Example #2
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 #3
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 #4
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;
    }
}