Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reduce the number of location objects
  • Loading branch information
md5sha256 committed Sep 10, 2021
commit a3edde3f4027e86923c574bc8b2bddc2d81ece7a
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ private void growStructure(StructureGrowEvent e) {
private void pasteTree(ChunkPopulateEvent e, int x, int z, Tree tree) {
for (int y = e.getWorld().getMaxHeight(); y > 30; y--) {
Block current = e.getWorld().getBlockAt(x, y, z);
if (!current.getType().isSolid() && current.getType() != Material.WATER && current.getType() != Material.SEAGRASS && current.getType() != Material.TALL_SEAGRASS && !(current.getBlockData() instanceof Waterlogged && ((Waterlogged) current.getBlockData()).isWaterlogged()) && tree.isSoil(current.getRelative(0, -1, 0).getType()) && isFlat(current)) {
Schematic.pasteSchematic(new Location(e.getWorld(), x, y, z), tree);
if (current.getType() != Material.WATER && current.getType() != Material.SEAGRASS && current.getType() != Material.TALL_SEAGRASS && !current.getType().isSolid() && !(current.getBlockData() instanceof Waterlogged && ((Waterlogged) current.getBlockData()).isWaterlogged()) && tree.isSoil(current.getRelative(0, -1, 0).getType()) && isFlat(current)) {
Schematic.pasteSchematic(e.getWorld(), x, y, z, tree);
break;
}
}
Expand All @@ -226,7 +226,7 @@ private void pasteTree(ChunkPopulateEvent e, int x, int z, Tree tree) {
private void growBush(ChunkPopulateEvent e, int x, int z, Berry berry, Random random, boolean isPaper) {
for (int y = e.getWorld().getMaxHeight(); y > 30; y--) {
Block current = e.getWorld().getBlockAt(x, y, z);
if (!current.getType().isSolid() && current.getType() != Material.WATER && berry.isSoil(current.getRelative(BlockFace.DOWN).getType())) {
if (current.getType() != Material.WATER && !current.getType().isSolid() && berry.isSoil(current.getRelative(BlockFace.DOWN).getType())) {
BlockStorage.store(current, berry.getItem());
switch (berry.getType()) {
case BUSH:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public short getHeight() {
}

public static void pasteSchematic(Location loc, Tree tree) {
pasteSchematic(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), tree);
}

public static void pasteSchematic(World world, int x1, int y1, int z1, Tree tree) {
Schematic schematic;

try {
Expand All @@ -127,22 +131,18 @@ public static void pasteSchematic(Location loc, Tree tree) {
short width = schematic.getWidth();
short height = schematic.getHeight();

// Performance - avoid repeatedly running Math.floorDiv in a loop
int initialBlockX = loc.getBlockX() - length / 2;
int initialBlockY = loc.getBlockY();
int initialBlockZ = loc.getBlockZ() - width / 2;

// Performance - avoid repeatedly checking if the world has been unloaded
World world = loc.getWorld();
// Performance - avoid repeatedly calculating this value in a loop
int processedX = x1 - length / 2;
int processedZ = z1 - width / 2;

for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;

int blockX = x + initialBlockX;
int blockY = y + initialBlockY;
int blockZ = z + initialBlockZ;
int blockX = x + processedX;
int blockY = y + y1;
int blockZ = z + processedZ;
Block block = world.getBlockAt(blockX, blockY, blockZ);
Material blockType = block.getType();

Expand Down