From cb0296a09fea9a565966c392edeeeb4b7ae3d580 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 25 Jan 2015 23:10:08 -0700 Subject: [PATCH] working on augmentation --- .../plot/generator/AugmentedPopulator.java | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java index 6992cb20f..f208bba2c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java @@ -3,7 +3,9 @@ package com.intellectualcrafters.plot.generator; import java.util.HashSet; import java.util.Random; +import org.bukkit.Bukkit; import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.generator.BlockPopulator; @@ -19,27 +21,58 @@ import com.intellectualcrafters.plot.util.PlotHelper; public class AugmentedPopulator extends BlockPopulator { - public final PlotGenerator generator; public final PlotWorld plotworld; public final PlotManager manager; + public final PlotGenerator generator; + private final int botx; + private final int botz; + private final int topx; + private final int topz; - public BlockWrapper getBlock(int i, int j, short[][] result) { + public BlockWrapper getBlock(int X, int Z, int i, int j, short[][] result, boolean check) { int y_1 = (i << 4); int y_2 = (j >> 8); int y = y_1 + y_2; int z_1 = (j - ((y & 0xF) << 8)); int z = (z_1 >> 4); - int x = z_1 - (z << 4); + int x; + if (check) { + if (z < botz || z > topz) { + return null; + } + x = z_1 - (z << 4); + if (x < botx || x > topx) { + return null; + } + } + else { + x = z_1 - (z << 4); + } + short id = result[i][j]; return new BlockWrapper(x, y, z, id, (byte) 0); } - public AugmentedPopulator(PlotGenerator generator, PlotWorld plotworld, PlotManager manager) { + public AugmentedPopulator(String world, PlotGenerator generator, PlotCluster cluster) { this.generator = generator; - this.plotworld = plotworld; - this.manager = manager; + this.plotworld = generator.getNewPlotWorld(world); + this.manager = generator.getPlotManager(); + + World bukkitWorld = Bukkit.getWorld(world); + + Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1()); + Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1,0,1); + + this.botx = bot.getBlockX(); + this.botz = bot.getBlockZ(); + + this.topx = top.getBlockX(); + this.topz = top.getBlockZ(); + + // Add the populator + bukkitWorld.getPopulators().add(this); } @Override @@ -51,15 +84,40 @@ public class AugmentedPopulator extends BlockPopulator { int Z = chunk.getZ(); int x = X << 4; int z = Z << 4; + int x2 = x + 15; + int z2 = z + 15; + + boolean inX1 = (x > botx && x < topx); + boolean inX2 = (x2 > botx && x2 < topx); + boolean inZ1 = (z > botz && z < topz); + boolean inZ2 = (z2 > botz && z2 < topz); + + + boolean inX = inX1 || inX2; + boolean inZ = inZ1 || inZ2; + + if (!inX || !inZ) { + return; + } + boolean check; + if (!inX1 || !inX2 || !inZ1 || inZ2) { + check = true; + } + else { + check = false; + } short[][] result = generator.generateExtBlockSections(world, rand, X, Z, null); int d2_length = result[0].length; for(int i = 0; i < result.length; i++) { for(int j = 0; j < d2_length; j++) { - BlockWrapper blockInfo = getBlock(i, j, result); + BlockWrapper blockInfo = getBlock(x, z, i, j, result, check); + if (blockInfo == null) { + continue; + } PlotBlock plotblock = new PlotBlock((short) blockInfo.id, (byte) 0 ); Block block = world.getBlockAt(x + blockInfo.x, blockInfo.y, z + blockInfo.z); PlotHelper.setBlock(block, plotblock); } } } -} +} \ No newline at end of file