Skip to content

Commit

Permalink
Fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Apr 16, 2023
1 parent 8d2b9d5 commit 27e0c72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ public void generateNoise(WorldInfo worldInfo, Random r, int chunkX, int chunkZ,
int minY = worldInfo.getMinHeight();
int xx = repeatCalc(chunkX);
int zz = repeatCalc(chunkZ);
ChunkSnapshot chunk = this.getChunk(xx,zz).snapshot();
ChunkStore chunk = this.getChunk(xx,zz);
if (chunk == null) {
// This should never be needed because islands should abut each other
//cd.setRegion(0, minY, 0, 16, 0, 16, Material.WATER);
BentoBox.getInstance().logError("No chunks found for " + xx + " " + zz);
return;
}
// Copy the chunk
copyChunkVerbatim(cd, chunk, minY, height);
copyChunkVerbatim(cd, chunk.snapshot(), minY, height);

}

Expand Down
45 changes: 23 additions & 22 deletions src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class NewAreaListener implements Listener {
private final Boxed addon;
private File structureFile;
private Queue<Item> itemsToBuild = new LinkedList<>();
private static Random rand = new Random();
private boolean pasting;
private static Gson gson = new Gson();
private record Item(String name, Structure structure, Location location, StructureRotation rot, Mirror mirror) {};
Expand Down Expand Up @@ -106,7 +107,7 @@ public void onBentoBoxReady(BentoBoxReadyEvent event) {
Structure s = Bukkit.getStructureManager().loadStructure(NamespacedKey.fromString(struct));
if (s == null) {
//addon.log("Now loading group from: " + struct);
}
}
}
}

Expand All @@ -116,12 +117,12 @@ public void onBentoBoxReady(BentoBoxReadyEvent event) {
public void onIslandCreated(IslandCreatedEvent event) {
setUpIsland(event.getIsland());
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onIslandReset(IslandResettedEvent event) {
setUpIsland(event.getIsland());
}

private void setUpIsland(Island island) {
// Check if this island is in this game
if (!(addon.inWorld(island.getWorld()))) {
Expand All @@ -130,15 +131,15 @@ private void setUpIsland(Island island) {
// Load the latest config so that admins can change it on the fly without reloading
YamlConfiguration config = YamlConfiguration.loadConfiguration(structureFile);
Location center = island.getProtectionCenter();
for (String env : config.getKeys(false)) {
for (String env : config.getKeys(false)) {
Environment e = Enums.getIfPresent(Environment.class, env.toUpperCase(Locale.ENGLISH)).orNull();
if (e == null) {
addon.logError("Error in structures.yml - unknown environment " + env);
} else {
place("structure",config.getConfigurationSection(env), center, e);
place("structure",config.getConfigurationSection(env), center, e);
}
}

}

private void place(String string, ConfigurationSection section, Location center, Environment env) {
Expand All @@ -152,12 +153,12 @@ private void place(String string, ConfigurationSection section, Location center,
String[] split = name.split(",");
if (split.length > 1) {
// Rotation
rot = Enums.getIfPresent(StructureRotation.class, split[1].strip().toUpperCase(Locale.ENGLISH)).or(StructureRotation.NONE);
rot = Enums.getIfPresent(StructureRotation.class, split[1].strip().toUpperCase(Locale.ENGLISH)).or(StructureRotation.NONE);
name = split[0];
}
if (split.length == 3) {
// Mirror
mirror = Enums.getIfPresent(Mirror.class, split[1].strip().toUpperCase(Locale.ENGLISH)).or(Mirror.NONE);
mirror = Enums.getIfPresent(Mirror.class, split[1].strip().toUpperCase(Locale.ENGLISH)).or(Mirror.NONE);
}
// Load Structure
Structure s = Bukkit.getStructureManager().loadStructure(NamespacedKey.fromString("minecraft:" + name));
Expand All @@ -167,10 +168,10 @@ private void place(String string, ConfigurationSection section, Location center,
}
// Extract coords
String[] value = vector.split(",");
if (value.length > 2) {
if (value.length > 2) {
int x = Integer.valueOf(value[0].strip()) + center.getBlockX();
int y = Integer.valueOf(value[1].strip());
int z = Integer.valueOf(value[2].strip()) + center.getBlockZ();
int z = Integer.valueOf(value[2].strip()) + center.getBlockZ();
Location l = new Location(world, x, y, z);
itemsToBuild.add(new Item(name, s, l, rot, mirror));
} else {
Expand All @@ -181,7 +182,7 @@ private void place(String string, ConfigurationSection section, Location center,

private void LoadChunksAsync(Item item) {
pasting = true;
item.structure().place(item.location(), true, item.rot(), item.mirror(), -1, 1, new Random());
item.structure().place(item.location(), true, item.rot(), item.mirror(), -1, 1, rand);
addon.log(item.name() + " placed at " + item.location().getWorld().getName() + " " + Util.xyz(item.location().toVector()));
// Find it
removeJigsaw(item.location(), item.structure(), item.rot(), item.name());
Expand All @@ -193,7 +194,7 @@ private void LoadChunksAsync(Item item) {
* @param loc - location where the structure was placed
* @param structure - structure that was placed
* @param structureRotation - rotation of structure
* @param key
* @param key
*/
public static void removeJigsaw(Location loc, Structure structure, StructureRotation structureRotation, String key) {
Location otherCorner = switch (structureRotation) {
Expand Down Expand Up @@ -224,7 +225,7 @@ public static void removeJigsaw(Location loc, Structure structure, StructureRota
b.setType(Material.WATER);
}
}
}
}
}

}
Expand Down Expand Up @@ -255,15 +256,15 @@ private static void processStructureBlock(Block b) {

private static final Map<Integer, EntityType> BUTCHER_ANIMALS = Map.of(0, EntityType.COW, 1, EntityType.SHEEP, 2, EntityType.PIG);
private static void processJigsaw(Block b, StructureRotation structureRotation) {
String data = nmsData(b);
String data = nmsData(b);
BoxedJigsawBlock bjb = gson.fromJson(data, BoxedJigsawBlock.class);
//BentoBox.getInstance().logDebug("Jigsaw: " + bjb);
//BentoBox.getInstance().logDebug("FinalState: " + bjb.getFinal_state());
String finalState = correctDirection(bjb.getFinal_state(), structureRotation);
//BentoBox.getInstance().logDebug("FinalState after rotation: " + finalState);
BlockData bd = Bukkit.createBlockData(finalState);
b.setBlockData(bd);
EntityType type =
EntityType type =
switch (bjb.getPool()) {
case "minecraft:bastion/mobs/piglin" -> EntityType.PIGLIN;
case "minecraft:bastion/mobs/hoglin" -> EntityType.HOGLIN;
Expand All @@ -274,8 +275,8 @@ private static void processJigsaw(Block b, StructureRotation structureRotation)
case "minecraft:village/common/pigs" -> EntityType.PIG;
case "minecraft:village/common/cows" -> EntityType.COW;
case "minecraft:village/common/iron_golem" -> EntityType.IRON_GOLEM;
case "minecraft:village/common/butcher_animals" -> BUTCHER_ANIMALS.get(new Random().nextInt(3));
case "minecraft:village/common/animals" -> BUTCHER_ANIMALS.get(new Random().nextInt(3));
case "minecraft:village/common/butcher_animals" -> BUTCHER_ANIMALS.get(rand.nextInt(3));
case "minecraft:village/common/animals" -> BUTCHER_ANIMALS.get(rand.nextInt(3));
default -> null;
};
if (bjb.getPool().contains("zombie/villagers")) {
Expand All @@ -284,8 +285,8 @@ private static void processJigsaw(Block b, StructureRotation structureRotation)
type = EntityType.VILLAGER;
}
// Spawn it
if (type != null && b.getWorld().spawnEntity(b.getRelative(BlockFace.UP).getLocation(), type) != null) {
//BentoBox.getInstance().logDebug("Spawned a " + type + " at " + b.getRelative(BlockFace.UP).getLocation());
if (type != null && b.getWorld().spawnEntity(b.getRelative(BlockFace.UP).getLocation(), type) != null) {
//BentoBox.getInstance().logDebug("Spawned a " + type + " at " + b.getRelative(BlockFace.UP).getLocation());
}

}
Expand Down Expand Up @@ -326,17 +327,17 @@ private static BlockFace getNewDirection(BlockFace oldDirection, StructureRotati
case NORTH -> BlockFace.EAST;
case SOUTH -> BlockFace.WEST;
case WEST -> BlockFace.NORTH;
default -> BlockFace.SELF;
default -> BlockFace.SELF;
};
} else if (sr.equals(StructureRotation.COUNTERCLOCKWISE_90)) {
return switch(oldDirection) {
case EAST -> BlockFace.NORTH;
case NORTH -> BlockFace.WEST;
case SOUTH -> BlockFace.EAST;
case WEST -> BlockFace.SOUTH;
default -> BlockFace.SELF;
default -> BlockFace.SELF;
};
}
}
return BlockFace.SELF;
}

Expand Down

0 comments on commit 27e0c72

Please sign in to comment.