From 955425a3158e31d9bdc370dea14cbda453546110 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 24 Jan 2015 16:42:17 -0700 Subject: [PATCH] Started work on augmenting classic world generation *Will require major restructuring to support this functionality --- .../plot/generator/AugmentedPopulator.java | 81 +++++++++++++++++++ .../plot/object/PlotRegion.java | 12 +++ 2 files changed, 93 insertions(+) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotRegion.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java new file mode 100644 index 000000000..5003be506 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java @@ -0,0 +1,81 @@ +package com.intellectualcrafters.plot.generator; + +import java.util.HashSet; +import java.util.Random; + +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.generator.BlockPopulator; + +import com.intellectualcrafters.plot.object.BlockWrapper; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotRegion; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.PlotHelper; + +public class AugmentedPopulator extends BlockPopulator { + + public final PlotGenerator generator; + public final PlotWorld plotworld; + public final PlotManager manager; + public HashSet regions; + + + public BlockWrapper getBlock(int i, int j, short[][] result) { + 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); + + short id = result[i][j]; + return new BlockWrapper(x, y, z, id, (byte) 0); + } + + public AugmentedPopulator(PlotGenerator generator, PlotWorld plotworld, PlotManager manager, HashSet regions) { + this.generator = generator; + this.plotworld = plotworld; + this.manager = manager; + this.regions = regions; + } + + // Check if the augmented populator contains the plot id + public boolean contains(PlotId id) { + // TODO check if any regions contain the id + return false; + } + + /** + * Returns false if the proposed region overlaps with an existing region + */ + public boolean addRegion(PlotRegion region) { + boolean contains = false; //TODO check if any regions contain these plots + if (contains) {// contains + return false; + } + return regions.add(region); + } + + @Override + public void populate(World world, Random rand, Chunk chunk) { + int X = chunk.getX(); + int Z = chunk.getZ(); + int x = X << 4; + int z = Z << 4; + 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); + 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); + } + } + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotRegion.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotRegion.java new file mode 100644 index 000000000..d9ae3c4c5 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotRegion.java @@ -0,0 +1,12 @@ +package com.intellectualcrafters.plot.object; + +public class PlotRegion { + + public final PlotId pos1; + public final PlotId pos2; + + public PlotRegion(PlotId pos1, PlotId pos2) { + this.pos1 = pos1; + this.pos2 = pos2; + } +}