Fix lootable rotation issues

This commit is contained in:
dfsek 2020-10-09 17:49:29 -07:00
parent d4e6f03aeb
commit 4e8ff7ffbb
2 changed files with 26 additions and 11 deletions

View File

@ -48,17 +48,23 @@ public class StructurePopulator extends BlockPopulator {
try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("StructurePasteTime")) {
struc.paste(spawn, chunk, rotation);
for(StructureContainedInventory i : struc.getInventories()) {
Debug.info("Attempting to populate loot: " + i.getUid());
Vector2 lootCoords = RotationUtil.getRotatedCoords(new Vector2(i.getX()-struc.getStructureInfo().getCenterX(), i.getZ()-struc.getStructureInfo().getCenterZ()), rotation);
Location inv = spawn.clone().add(lootCoords.getX(), 0, lootCoords.getZ());
Debug.info(spawn.toString() + " became: " + inv.toString());
Debug.info(Math.floorDiv(inv.getBlockX(), 16) + ":" + chunk.getX() + ", " + Math.floorDiv(inv.getBlockZ(), 16) + ":" + chunk.getZ() );
if(Math.floorDiv(inv.getBlockX(), 16) != chunk.getX() || Math.floorDiv(inv.getBlockZ(), 16) != chunk.getZ()) continue;
Debug.info("Target is in chunk.");
LootTable table = conf.getLoot(i.getUid());
if(table == null) continue;
Debug.info("Target has table assigned.");
table.fillInventory(((BlockInventoryHolder) inv.getBlock().getState()).getInventory(), random);
try {
Debug.info("Attempting to populate loot: " + i.getUid());
Vector2 lootCoords = RotationUtil.getRotatedCoords(new Vector2(i.getX() - struc.getStructureInfo().getCenterX(), i.getZ() - struc.getStructureInfo().getCenterZ()), rotation.inverse());
Location inv = spawn.clone().add(lootCoords.getX(), i.getY(), lootCoords.getZ());
Debug.info(Math.floorDiv(inv.getBlockX(), 16) + ":" + chunk.getX() + ", " + Math.floorDiv(inv.getBlockZ(), 16) + ":" + chunk.getZ());
if(Math.floorDiv(inv.getBlockX(), 16) != chunk.getX() || Math.floorDiv(inv.getBlockZ(), 16) != chunk.getZ())
continue;
Debug.info("Target is in chunk.");
Debug.info(spawn.toString() + " became: " + inv.toString() + " (" + rotation + ", " + inv.getBlock().getType() + ")");
LootTable table = conf.getLoot(i.getUid());
if(table == null) continue;
Debug.info("Target has table assigned.");
table.fillInventory(((BlockInventoryHolder) inv.getBlock().getState()).getInventory(), random);
} catch(ClassCastException e) {
Debug.error("Could not populate structure loot!");
Debug.stack(e);
}
}
break;
}

View File

@ -325,5 +325,14 @@ public class Structure implements Serializable {
default: throw new IllegalArgumentException();
}
}
public Rotation inverse() {
switch(this) {
case NONE: return NONE;
case CCW_90: return CW_90;
case CW_90: return CCW_90;
case CW_180: return CW_180;
default: throw new IllegalArgumentException();
}
}
}
}