Posted June 20, 20169 yr I have a vine like block that is sometimes placed wrong when they are generated. https://cdn.discordapp.com/attachments/169862391947984898/194522309338464258/2016-06-20_11.39.39.png[/img] The ones on the middle bottom are just placed on air blocks. Here's the generation class: public class BiomeFeatureFrost implements IBiomeFeature { private final String name; private final int rarity; public BiomeFeatureFrost(String name, int rarity) { this.name = name; this.rarity = rarity; } @Override public boolean generate(World world, Random rand, BlockPos pos) { for(int r = 0; r < this.rarity; r++) { int x = rand.nextInt(16) + 8; int y = rand.nextInt(128); int z = rand.nextInt(16) + 8; BlockPos newPos = pos.add(x, y, z); for(; newPos.getY() < 128; newPos = newPos.up()) { if(world.isAirBlock(newPos)) { for(EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL.facings()) { if(NetherExContent.Blocks.frost.canPlaceBlockOnSide(world, newPos, enumfacing)) { IBlockState iblockstate = NetherExContent.Blocks.frost.getDefaultState().withProperty(BlockFrost.NORTH, enumfacing == EnumFacing.NORTH).withProperty(BlockFrost.EAST, enumfacing == EnumFacing.EAST).withProperty(BlockFrost.SOUTH, enumfacing == EnumFacing.SOUTH).withProperty(BlockFrost.WEST, enumfacing == EnumFacing.WEST); world.setBlockState(newPos, iblockstate, 3); break; } } } else { newPos = newPos.add(rand.nextInt(4) - rand.nextInt(4), 0, rand.nextInt(4) - rand.nextInt(4)); } } } return true; } @Override public String getName() { return name; } } And the block class: public class BlockFrost extends BlockMod { public static final PropertyBool NORTH = PropertyBool.create("north"); public static final PropertyBool EAST = PropertyBool.create("east"); public static final PropertyBool SOUTH = PropertyBool.create("south"); public static final PropertyBool WEST = PropertyBool.create("west"); private static final PropertyBool UP = PropertyBool.create("up"); private static final PropertyBool[] ALL_FACES = new PropertyBool[]{UP, NORTH, SOUTH, WEST, EAST}; private static final AxisAlignedBB UP_AABB = new AxisAlignedBB(0.0D, 0.9375D, 0.0D, 1.0D, 1.0D, 1.0D); private static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.0625D, 1.0D, 1.0D); private static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.9375D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); private static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.0625D); private static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.9375D, 1.0D, 1.0D, 1.0D); public BlockFrost() { super(Material.VINE, "frost"); this.setSoundType(SoundType.PLANT); this.setTickRandomly(true); } private static PropertyBool getPropertyFor(EnumFacing side) { switch(side) { case UP: return UP; case NORTH: return NORTH; case SOUTH: return SOUTH; case EAST: return EAST; case WEST: return WEST; default: throw new IllegalArgumentException(side + " is an invalid choice"); } } private static int getNumSpreadFaces(IBlockState state) { int i = 0; for(PropertyBool propertybool : ALL_FACES) { if(state.getValue(propertybool)) { ++i; } } return i; } @Override public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) { return NULL_AABB; } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { state = state.getActualState(source, pos); int i = 0; AxisAlignedBB axisalignedbb = FULL_BLOCK_AABB; if(state.getValue(UP)) { axisalignedbb = UP_AABB; ++i; } if(state.getValue(NORTH)) { axisalignedbb = NORTH_AABB; ++i; } if(state.getValue(EAST)) { axisalignedbb = EAST_AABB; ++i; } if(state.getValue(SOUTH)) { axisalignedbb = SOUTH_AABB; ++i; } if(state.getValue(WEST)) { axisalignedbb = WEST_AABB; ++i; } return i == 1 ? axisalignedbb : FULL_BLOCK_AABB; } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { return state.withProperty(UP, worldIn.getBlockState(pos.up()).isBlockNormalCube()); } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos) { return true; } @Override public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) { switch(side) { case UP: return this.canSpreadFrostOn(worldIn.getBlockState(pos.up())); case NORTH: case SOUTH: case EAST: case WEST: return this.canSpreadFrostOn(worldIn.getBlockState(pos.offset(side.getOpposite()))); default: return false; } } private boolean canSpreadFrostOn(IBlockState state) { return state.isFullCube() && state.getMaterial().blocksMovement(); } private boolean recheckSpreadSides(World worldIn, BlockPos pos, IBlockState state) { IBlockState iblockstate = state; for(EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) { PropertyBool propertybool = getPropertyFor(enumfacing); if(state.getValue(propertybool) && !this.canSpreadFrostOn(worldIn.getBlockState(pos.offset(enumfacing)))) { IBlockState iblockstate1 = worldIn.getBlockState(pos.up()); if(iblockstate1.getBlock() != this || !iblockstate1.getValue(propertybool)) { state = state.withProperty(propertybool, false); } } } if(getNumSpreadFaces(state) == 0) { return false; } else { if(iblockstate != state) { worldIn.setBlockState(pos, state, 2); } return true; } } @Override public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) { if(!worldIn.isRemote && !this.recheckSpreadSides(worldIn, pos, state)) { this.dropBlockAsItem(worldIn, pos, state, 0); worldIn.setBlockToAir(pos); } } @Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if(!worldIn.isRemote) { if(worldIn.rand.nextInt(4) == 0) { int i = 4; int j = 5; boolean flag = false; label62: for(int k = -i; k <= i; ++k) { for(int l = -i; l <= i; ++l) { for(int i1 = -1; i1 <= 1; ++i1) { if(worldIn.getBlockState(pos.add(k, i1, l)).getBlock() == this) { --j; if(j <= 0) { flag = true; break label62; } } } } } EnumFacing enumfacing1 = EnumFacing.random(rand); BlockPos blockpos2 = pos.up(); if(enumfacing1 == EnumFacing.UP && pos.getY() < 255 && worldIn.isAirBlock(blockpos2)) { if(!flag) { IBlockState iblockstate2 = state; for(EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL) { if(rand.nextBoolean() || !this.canSpreadFrostOn(worldIn.getBlockState(blockpos2.offset(enumfacing2)))) { iblockstate2 = iblockstate2.withProperty(getPropertyFor(enumfacing2), false); } } if(iblockstate2.getValue(NORTH) || iblockstate2.getValue(EAST) || iblockstate2.getValue(SOUTH) || iblockstate2.getValue(WEST)) { worldIn.setBlockState(blockpos2, iblockstate2, 2); } } } else if(enumfacing1.getAxis().isHorizontal() && !state.getValue(getPropertyFor(enumfacing1))) { if(!flag) { BlockPos blockpos4 = pos.offset(enumfacing1); IBlockState iblockstate3 = worldIn.getBlockState(blockpos4); Block block1 = iblockstate3.getBlock(); if(block1.getMaterial(iblockstate3) == Material.AIR) { EnumFacing enumfacing3 = enumfacing1.rotateY(); EnumFacing enumfacing4 = enumfacing1.rotateYCCW(); boolean flag1 = state.getValue(getPropertyFor(enumfacing3)); boolean flag2 = state.getValue(getPropertyFor(enumfacing4)); BlockPos blockpos = blockpos4.offset(enumfacing3); BlockPos blockpos1 = blockpos4.offset(enumfacing4); if(flag1 && this.canSpreadFrostOn(worldIn.getBlockState(blockpos))) { worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing3), true), 2); } else if(flag2 && this.canSpreadFrostOn(worldIn.getBlockState(blockpos1))) { worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing4), true), 2); } else if(flag1 && worldIn.isAirBlock(blockpos) && this.canSpreadFrostOn(worldIn.getBlockState(pos.offset(enumfacing3)))) { worldIn.setBlockState(blockpos, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), true), 2); } else if(flag2 && worldIn.isAirBlock(blockpos1) && this.canSpreadFrostOn(worldIn.getBlockState(pos.offset(enumfacing4)))) { worldIn.setBlockState(blockpos1, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), true), 2); } else if(this.canSpreadFrostOn(worldIn.getBlockState(blockpos4.up()))) { worldIn.setBlockState(blockpos4, this.getDefaultState(), 2); } } else if(block1.getMaterial(iblockstate3).isOpaque() && iblockstate3.isFullCube()) { worldIn.setBlockState(pos, state.withProperty(getPropertyFor(enumfacing1), true), 2); } } } else { if(pos.getY() > 1) { BlockPos blockpos3 = pos.down(); IBlockState iblockstate = worldIn.getBlockState(blockpos3); Block block = iblockstate.getBlock(); if(block.getMaterial(iblockstate) == Material.AIR) { IBlockState iblockstate1 = state; for(EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) { if(rand.nextBoolean()) { iblockstate1 = iblockstate1.withProperty(getPropertyFor(enumfacing), false); } } if(iblockstate1.getValue(NORTH) || iblockstate1.getValue(EAST) || iblockstate1.getValue(SOUTH) || iblockstate1.getValue(WEST)) { worldIn.setBlockState(blockpos3, iblockstate1, 2); } } else if(block == this) { IBlockState iblockstate4 = iblockstate; for(EnumFacing enumfacing5 : EnumFacing.Plane.HORIZONTAL) { PropertyBool propertybool = getPropertyFor(enumfacing5); if(rand.nextBoolean() && state.getValue(propertybool)) { iblockstate4 = iblockstate4.withProperty(propertybool, true); } } if(iblockstate4.getValue(NORTH) || iblockstate4.getValue(EAST) || iblockstate4.getValue(SOUTH) || iblockstate4.getValue(WEST)) { worldIn.setBlockState(blockpos3, iblockstate4, 2); } } } } } } } @Override public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { IBlockState iblockstate = this.getDefaultState().withProperty(UP, false).withProperty(NORTH, false).withProperty(EAST, false).withProperty(SOUTH, false).withProperty(WEST, false); return facing.getAxis().isHorizontal() ? iblockstate.withProperty(getPropertyFor(facing.getOpposite()), true) : iblockstate; } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return null; } @Override public int quantityDropped(Random random) { return 0; } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(SOUTH, (meta & 1) > 0).withProperty(WEST, (meta & 2) > 0).withProperty(NORTH, (meta & 4) > 0).withProperty(EAST, (meta & > 0); } @Override @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } @Override public int getMetaFromState(IBlockState state) { int i = 0; if(state.getValue(SOUTH)) { i |= 1; } if(state.getValue(WEST)) { i |= 2; } if(state.getValue(NORTH)) { i |= 4; } if(state.getValue(EAST)) { i |= 8; } return i; } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, UP, NORTH, EAST, SOUTH, WEST); } @Override public IBlockState withRotation(IBlockState state, Rotation rot) { switch(rot) { case CLOCKWISE_180: return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST)).withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST)); case COUNTERCLOCKWISE_90: return state.withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH)); case CLOCKWISE_90: return state.withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH)).withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH)); default: return state; } } @Override public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { switch(mirrorIn) { case LEFT_RIGHT: return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH)); case FRONT_BACK: return state.withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST)); default: return super.withMirror(state, mirrorIn); } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.