@Override public void onDynamicUpdate(Block block, long updateTime, int data) { if (block.translate(BlockFace.TOP).getLight() < this.getMinimumLightToGrow()) { block.dynamicUpdate(updateTime + getGrowthTime(block), true); return; } int chance = VanillaBlockMaterial.getCropGrowthChance(block) + 1; final Random rand = GenericMath.getRandom(); if (rand.nextInt(chance) == 0) { if (isFullyGrown(block)) { for (int i = 0; i < BlockFaces.NESW.size(); i++) { Block spread = block.translate(BlockFaces.NESW.get(i)); BlockMaterial material = spread.getMaterial(); if (material == VanillaMaterials.AIR) { BlockMaterial belowSpread = spread.translate(BlockFace.BOTTOM).getMaterial(); if (belowSpread.isMaterial( VanillaMaterials.FARMLAND, VanillaMaterials.DIRT, VanillaMaterials.GRASS)) { spread.setMaterial(this.getLastStageMaterial()); break; } } else if (material == getLastStageMaterial()) { break; } } } else { block.addData(1); } } block.dynamicUpdate(updateTime + getGrowthTime(block), true); }
private boolean findFrame(Block origin, boolean withEnderEye) { for (BlockFace face : BlockFaces.NESW) { Block frame = origin.translate(face, 2); BlockFace facing = face.getOpposite(); if (!isEndFrame(frame, facing, withEnderEye)) { return false; } if (!isEndFrame(frame.translate(BlockFaces.NESW.previous(face)), facing, withEnderEye)) { return false; } if (!isEndFrame(frame.translate(BlockFaces.NESW.next(face)), facing, withEnderEye)) { return false; } } return true; }
@Override public void placeObject(World w, int x, int y, int z) { Block origin = w.getBlock(x, y, z); // Generate the frames for (BlockFace face : BlockFaces.NESW) { Block frame = origin.translate(face, 2); BlockFace facing = face.getOpposite(); // Place the three pieces placeFrame(frame, facing); placeFrame(frame.translate(BlockFaces.NESW.previous(face)), facing); placeFrame(frame.translate(BlockFaces.NESW.next(face)), facing); } // Set to a random state setRandomActive(origin, 0.1f); }
/** * Finds the center of the end portal object * * @param frameBlock to start looking from * @return Center origin block */ private Block getOrigin(Block frameBlock) { if (!frameBlock.isMaterial(VanillaMaterials.END_PORTAL_FRAME)) { return null; } BlockFace facing = VanillaMaterials.END_PORTAL_FRAME.getFacing(frameBlock); // Rotates the facing 90 degrees to the left BlockFace lookDirection = BlockFaces.NESW.previous(facing); // Get the corner piece Block corner = frameBlock; for (int i = 0; i < 4 && isEndFrame(corner, facing, false); i++) { corner = corner.translate(lookDirection); } // Now go two steps back and two steps towards the middle (facing) return corner.translate(lookDirection, -2).translate(facing, 2); }