@SuppressWarnings("incomplete-switch") public Trunk(World world, BlockPos pos, EnumFacing direction, IBlockState blockState, int treeHeight) { super(world, pos, direction, blockState, treeHeight); switch (this.direction) { case NORTH : case SOUTH : this.blockState = this.blockState .withProperty(BlockLog.LOG_AXIS, EnumAxis.Z); break; case EAST : case WEST : this.blockState = this.blockState .withProperty(BlockLog.LOG_AXIS, EnumAxis.X); } }
public static void generateJuniperTree(World world, BlockPos pos, Random r) { int h = generateTrunk(2, 4, ModBlocks.log_juniper.getDefaultState(), world, pos, r); EnumFacing branchOffset = EnumFacing.HORIZONTALS[r.nextInt(4)]; BlockPos branching = pos.up(h).offset(branchOffset); IBlockState log = ModBlocks.log_juniper.getDefaultState().withProperty(BlockModLog.LOG_AXIS, EnumAxis.NONE); ArrayList<BlockPos> logs = new ArrayList<BlockPos>(); if (isAirBlock(world, branching)) { world.setBlockState(branching, log, 3); logs.add(branching); } BlockPos other = branching.offset(branchOffset.getOpposite(), 2); if (isAirBlock(world, other)) { world.setBlockState(other, log, 3); logs.add(other); } for (int i = 0; i < h / 2; i++) { BlockPos current = branching.up().offset(branchOffset, i + 1); if (isAirBlock(world, current)) { logs.add(current); world.setBlockState(current, log, 3); } } IBlockState leaves = ModBlocks.leaves_juniper.getDefaultState(); for (BlockPos p : logs) { for (EnumFacing f : EnumFacing.VALUES) { BlockPos lpos1 = p.offset(f); if (isAirBlock(world, lpos1)) world.setBlockState(lpos1, leaves, 3); for (EnumFacing f2 : EnumFacing.VALUES) if (f2 != EnumFacing.DOWN) { BlockPos lpos = p.offset(f).offset(f2); if (isAirBlock(world, lpos) && r.nextDouble() < 0.8D) world.setBlockState(lpos, leaves, 3); } } } }
private static EnumAxis getLogFacing(StructureConfiguration configuration, Block foundBlock, BuildBlock block, EnumFacing assumedNorth) { EnumAxis logFacing = EnumAxis.X; if (foundBlock instanceof BlockLog) { if (block.getProperty("axis").getValue().equals("x")) { logFacing = EnumAxis.X; } else if (block.getProperty("axis").getValue().equals("y")) { logFacing = EnumAxis.Y; } else { logFacing = EnumAxis.Z; } if (logFacing != EnumAxis.Y) { logFacing = configuration.houseFacing == assumedNorth || configuration.houseFacing == assumedNorth.getOpposite() ? logFacing : logFacing == EnumAxis.X ? EnumAxis.Z : EnumAxis.X; } } return logFacing; }
public static EnumFacing getOrientation(final IBlockState state) { if (state.getPropertyNames().contains(FACING)) return state.getValue(FACING); if (state.getPropertyNames().contains(BlockLog.LOG_AXIS)) { final EnumAxis axis = state.getValue(BlockLog.LOG_AXIS); if (axis == EnumAxis.Y) return EnumFacing.UP; if (axis == EnumAxis.X) return EnumFacing.NORTH; if (axis == EnumAxis.Z) return EnumFacing.EAST; } return null; }
public static IBlockState rotate(final IBlockState state, final int count) { if (count == 0) return state; @SuppressWarnings("rawtypes") Collection<IProperty> props = state.getPropertyNames(); if (props.contains(BlockLog.LOG_AXIS)) { if (count == 1 || count == 3) { final EnumAxis axis = state.getValue(BlockLog.LOG_AXIS); if (axis == EnumAxis.Y) return state; return state.withProperty(BlockLog.LOG_AXIS, axis == EnumAxis.Z ? EnumAxis.X : EnumAxis.Z); } return state; } else if (props.contains(FACING)) { EnumFacing current = getOrientation(state); if (current == null || current == EnumFacing.UP || current == EnumFacing.DOWN) return state; for (int i = 0; i < count; i++) current = current.rotateY(); return state.withProperty(FACING, current); } return state; }
@Override public boolean generate(World world, Random rand, BlockPos pos) { int height = getTreeHeight(rand); BlockPos branchPos = pos.up(height - 1); int leavesBase = branchPos.getY() - 2 - rand.nextInt(2); boolean alternate = true; boolean irregular = true; boolean inverted = false; int maxLeavesLength = 2; // if (!BlockVolumeShape.region(0, 1, 0, 0, leavesBase, 0) // .and(-2, leavesBase + 1, -2, 2, height, 2) // .hasSpace(pos, isEmptySpace(world))) { // return false; // } for (int i = 0; i < height; i++) { setBlockInWorld(world, pos.up(i), LOG.withProperty(LOG_AXIS, EnumAxis.Y)); } int base = 4 + rand.nextInt(4); int direction = rand.nextInt(8); int lFactor; for (int i = base; i < height; ++i) { ++direction; if (direction > 7) { direction = 0; } lFactor = (int) (6 * (((height - i) / (float) height))); generateBranch(world, pos.up(i), rand, pos.getY(), direction + 1, lFactor); if (rand.nextInt(8) == 0) { ++direction; if (direction > 7) { direction = 0; } generateBranch(world, pos.up(i), rand, pos.getY(), direction + 1, lFactor); } } generateTopLeaves(world, pos, branchPos, height, leavesBase, rand, alternate, maxLeavesLength, irregular, inverted, LEAF); // if (treeType != TreeTypes.TYPE_3) { // generateResin(world, pos, height); // } return true; }
private void branchUp(World world, BlockPos pos, Random rand, int height, int base) { int fallX = 1 - rand.nextInt(3); int fallZ = 1 - rand.nextInt(3); int fallCount = 0; BlockPos upPos = pos.down(); EnumAxis woodAxis; for (int i = 0; i < height; i++) { if (rand.nextInt(3) == 0 && i > base && fallCount < 3) { fallCount++; upPos = upPos.add(fallX, 0, fallZ); if (fallX != 0) { woodAxis = EnumAxis.X; } else if (fallZ != 0) { woodAxis = EnumAxis.Z; } else { woodAxis = EnumAxis.Y; } if (rand.nextInt(3) == 0 || (fallX == 0 && fallZ == 0)) { upPos = upPos.up(); } } else { fallCount = 0; woodAxis = EnumAxis.Y; upPos = upPos.up(); } setBlockInWorld(world, upPos, LOG.withProperty(LOG_AXIS, woodAxis)); if (i == base) { generateBranchLeaves(world, upPos, rand, false, 2, true, LEAF); } if (i > base) { if (i > base + 2) { generateBranchLeaves(world, upPos.down(2), rand, false, 2, true, LEAF); } if (i > base + 1) { generateBranchLeaves(world, upPos.down(), rand, false, 3, true, LEAF); } generateBranchLeaves(world, upPos, rand, true, 4, true, LEAF); } } }