Skip to content

Commit

Permalink
fix chest loot pos for ruined portal
Browse files Browse the repository at this point in the history
  • Loading branch information
hube12 committed May 23, 2021
1 parent 60a25bb commit f215061
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/main/java/kaptainwutax/featureutils/loot/ILoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface ILoot {

default HashMap<Generator.ILootType, List<List<ItemStack>>> getLoot(long structureSeed, Generator generator, ChunkRand rand, boolean indexed) {
if (!isCorrectGenerator(generator)) return null;
List<Pair<Generator.ILootType, BPos>> lootPositions = generator.getChestsPos();
List<Pair<Generator.ILootType, BPos>> lootPositions = generator.getLootPos();

HashMap<CPos, LinkedList<Pair<Generator.ILootType, BPos>>> posLinkedListHashMap = new HashMap<>();
for (Pair<Generator.ILootType, BPos> lootPos : lootPositions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public boolean generate(ChunkGenerator generator, CPos cPos, ChunkRand rand) {

public abstract boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkRand rand);


public abstract List<Pair<ILootType, BPos>> getChestsPos();

public abstract List<Pair<ILootType, BPos>> getLootPos();

public List<Pair<ILootType, CPos>> getChestsChunkPos() {
return this.getChestsPos().stream().map(e -> new Pair<>(e.getFirst(), e.getSecond().toChunkPos())).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkR
return true;
}

@Override
public List<Pair<ILootType, BPos>> getLootPos() {
return getChestsPos();
}

@Override
public List<Pair<ILootType, BPos>> getChestsPos() {
return Collections.singletonList(new Pair<>(LootType.BURIED_CHEST, cPos.toBlockPos().add(9, 90, 9)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkR
return true;
}


@Override
public List<Pair<ILootType, BPos>> getLootPos() {
return getChestsPos();
}

@Override
public List<Pair<ILootType, BPos>> getChestsPos() {
//piece.getInside(...,...);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkR
return true;
}


@Override
public List<Pair<ILootType, BPos>> getLootPos() {
return getChestsPos();
}

/**
* Get the chest block pos, should always be called after generate else will return an empty list
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ public List<Pair<ILootType, BPos>> getChestsPos() {
return null;
}

@Override
public List<Pair<ILootType, BPos>> getLootPos() {
return getChestsPos();
}

@Override
public ILootType[] getLootTypes() {
return new ILootType[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class RuinedPortalGenerator extends Generator {
private boolean cold = false;
private boolean buried = false;
private int height;
private CPos cPos;

private static final Predicate<Location> isLand = l -> l != Location.ON_OCEAN_FLOOR;
private final HashSet<Biome> DESERT_BIOME = new HashSet<Biome>() {{
Expand Down Expand Up @@ -124,11 +125,17 @@ public void reset() {
this.generator = null;
this.overgrown = false;
this.cold = false;
this.cPos=null;
}

@Override
@SuppressWarnings("unchecked")

public boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkRand rand) {
return this.generateStructure(generator,chunkX,chunkZ,rand);
}

@SuppressWarnings("unchecked")
public boolean generateStructure(ChunkGenerator generator, int chunkX, int chunkZ, ChunkRand rand){
RuinedPortal ruinedPortal = new RuinedPortal(generator.getBiomeSource().getDimension(), this.getVersion());
if (!ruinedPortal.canStart((RegionStructure.Data<RuinedPortal>) ruinedPortal.at(chunkX, chunkZ), generator.getWorldSeed(), rand)) return false;
// instantiate the biome type
Expand Down Expand Up @@ -215,6 +222,7 @@ public boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkR
}
chunkBB.encompass(piece);
this.generator = generator; // have to store it to check lava sadly
this.cPos=new CPos(chunkX,chunkZ);
return true;
}

Expand Down Expand Up @@ -263,7 +271,6 @@ private static int findSuitableY(ChunkGenerator generator, Location location, Pr
List<BPos> corners = Arrays.asList(new BPos(blockBox.minX, 0, blockBox.minZ), new BPos(blockBox.maxX, 0, blockBox.minZ), new BPos(blockBox.minX, 0, blockBox.maxZ), new BPos(blockBox.maxX, 0, blockBox.maxZ));
List<Block[]> columns = corners.stream().map(e -> generator.getColumnAt(e.getX(), e.getZ())).collect(Collectors.toList());


int dig;
for (dig = y; dig > 15; --dig) {
int cornerMatch = 0;
Expand Down Expand Up @@ -333,6 +340,16 @@ public List<Pair<ILootType, BPos>> getChestsPos() {
return res;
}

@Override
public List<Pair<ILootType, BPos>> getLootPos() {
HashMap<LootType, BPos> lootPos = STRUCTURE_TO_LOOT.get(type);
List<Pair<ILootType, BPos>> res = new ArrayList<>();
for (LootType lootType : lootPos.keySet()) {
res.add(new Pair<>(lootType,this.cPos.toBlockPos()));
}
return res;
}

private List<Pair<Block, BPos>> processBlocks(List<BPos> obsidianPos){
List<Pair<Block, BPos>> res = new ArrayList<>();
ChunkRand rand = new ChunkRand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkR
return true;
}

@Override
public List<Pair<ILootType, BPos>> getLootPos() {
return getChestsPos();
}

@Override
public List<Pair<ILootType, BPos>> getChestsPos() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkR
return this.generateRecursively(generator.getWorldSeed(), chunkX, chunkZ, rand, piece -> true);
}

@Override
public List<Pair<ILootType, BPos>> getLootPos() {
return getChestsPos();
}

@Override
public List<Pair<ILootType, BPos>> getChestsPos() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public boolean generate(ChunkGenerator generator, int chunkX, int chunkZ, ChunkR
return true;
}

@Override
public List<Pair<ILootType, BPos>> getLootPos() {
return getChestsPos();
}

@Override
public List<Pair<ILootType, BPos>> getChestsPos() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public class LootTestRuinedPortal {
private BiomeSource biomeSource;
private ChunkGenerator generator;

public void setup(Dimension dimension,long worldseed, CPos cPos, MCVersion version) {
public void setup(Dimension dimension, long worldseed, CPos cPos, MCVersion version) {
biomeSource = BiomeSource.of(dimension, version, worldseed);
generator = ChunkGenerator.of(dimension, biomeSource);
structureGenerator = new RuinedPortalGenerator(version);
ChunkRand rand = new ChunkRand().asChunkRandDebugger();
structureGenerator.generate(generator, cPos, rand);
loots = structureGenerator.getChestsPos();
portal = ((RuinedPortalGenerator)structureGenerator).getPortal();
portal = ((RuinedPortalGenerator) structureGenerator).getPortal();
}

@Test
public void testCorrectChest1() {
setup(Dimension.OVERWORLD,123L, new BPos(-311, 0, 121).toChunkPos(), MCVersion.v1_16_5);
setup(Dimension.OVERWORLD, 123L, new BPos(-311, 0, 121).toChunkPos(), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(-315, 81, 127)));
}};
Expand All @@ -54,7 +54,7 @@ public void testCorrectChest1() {

@Test
public void testCorrectChest2() {
setup(Dimension.OVERWORLD,1476413308176291228L, new BPos(153, 0, 121).toChunkPos(), MCVersion.v1_16_5);
setup(Dimension.OVERWORLD, 1476413308176291228L, new BPos(153, 0, 121).toChunkPos(), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(150, 67, 128)));
}};
Expand All @@ -65,7 +65,7 @@ public void testCorrectChest2() {

@Test
public void testCorrectChest3() {
setup(Dimension.OVERWORLD,7948314503011477316L, new CPos(8, 10), MCVersion.v1_16_5);
setup(Dimension.OVERWORLD, 7948314503011477316L, new CPos(8, 10), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(128, 78, 162)));
}};
Expand All @@ -76,7 +76,7 @@ public void testCorrectChest3() {

@Test
public void testCorrectChest4() {
setup(Dimension.OVERWORLD,7948314503011477316L,new CPos(7,101), MCVersion.v1_16_5);
setup(Dimension.OVERWORLD, 7948314503011477316L, new CPos(7, 101), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(113, 38, 1629)));
}};
Expand All @@ -87,7 +87,7 @@ public void testCorrectChest4() {

@Test
public void testCorrectChest5() {
setup(Dimension.NETHER,7948314503011477316L,new CPos(3,5), MCVersion.v1_16_5);
setup(Dimension.NETHER, 7948314503011477316L, new CPos(3, 5), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
// this blocks doesn't generate (removed by lava)
//add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(53, 28, 82)));
Expand All @@ -97,10 +97,10 @@ public void testCorrectChest5() {

@Test
public void testCorrectChest10() {
setup(Dimension.OVERWORLD,-7387955057302025707L,new CPos(9,7), MCVersion.v1_16_1);
setup(Dimension.OVERWORLD, -7387955057302025707L, new CPos(9, 7), MCVersion.v1_16_1);
// 20w27a fixed the netherrack spread that remove chest (we don't support it)
//assertTrue(loots.isEmpty());
setup(Dimension.OVERWORLD,-7387955057302025707L,new CPos(9,7), MCVersion.v1_16_2);
setup(Dimension.OVERWORLD, -7387955057302025707L, new CPos(9, 7), MCVersion.v1_16_2);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(145, 69, 116)));
}};
Expand All @@ -111,7 +111,7 @@ public void testCorrectChest10() {

@Test
public void testCorrectChest6() {
setup(Dimension.NETHER,7948314503011477316L,new CPos(-11,-13), MCVersion.v1_16_5);
setup(Dimension.NETHER, 7948314503011477316L, new CPos(-11, -13), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(-170, 50, -192)));
}};
Expand All @@ -122,7 +122,7 @@ public void testCorrectChest6() {

@Test
public void testCorrectChest7() {
setup(Dimension.NETHER,7948314503011477316L,new CPos(25,9), MCVersion.v1_16_5);
setup(Dimension.NETHER, 7948314503011477316L, new CPos(25, 9), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(405, 102, 146)));
}};
Expand All @@ -133,7 +133,7 @@ public void testCorrectChest7() {

@Test
public void testCorrectChest8() {
setup(Dimension.NETHER,7948314503011477316L,new CPos(-23,8), MCVersion.v1_16_5);
setup(Dimension.NETHER, 7948314503011477316L, new CPos(-23, 8), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(-366, 34, 139)));
}};
Expand All @@ -142,29 +142,48 @@ public void testCorrectChest8() {
}
}

@Test
public void testCorrectChest12() {
setup(Dimension.OVERWORLD, 239648, new BPos(64, 0, 112).toChunkPos(), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(-366, 34, 139)));
}};
RuinedPortal ruinedPortal = new RuinedPortal(this.biomeSource.getDimension(), this.biomeSource.getVersion());
ChunkRand rand=new ChunkRand();
ChunkRand rand1=rand.asChunkRandDebugger();
HashMap<Generator.ILootType, List<List<ItemStack>>> lootTypeListHashMap = ruinedPortal.getLoot(this.biomeSource.getWorldSeed(), this.structureGenerator, rand1, false);
assertTrue(lootTypeListHashMap.containsKey(RuinedPortalGenerator.LootType.RUINED_PORTAL));
List<List<ItemStack>> l = lootTypeListHashMap.get(RuinedPortalGenerator.LootType.RUINED_PORTAL);
assertEquals(1, l.size());
List<ItemStack> loot = l.get(0);
long hashcode = 0;
for (ItemStack stack : loot) hashcode += stack.hashCode();
assertEquals(-1138008234, hashcode, "Something changed in loot");
}

@Test
public void testCorrectChest11() {
setup(Dimension.NETHER,-7002427602017045587L,new BPos(-400,0,1632).toChunkPos(), MCVersion.v1_16_5);
setup(Dimension.NETHER, -7002427602017045587L, new BPos(-400, 0, 1632).toChunkPos(), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(-399, 28, 1634)));
}};
for (Pair<RuinedPortalGenerator.LootType, BPos> check : checks) {
assertTrue(loots.contains(check), String.format("Missing loot %s at pos %s for loots: %s", check.getFirst(), check.getSecond(), Arrays.toString(loots.toArray())));
}
RuinedPortal ruinedPortal=new RuinedPortal(this.biomeSource.getDimension(),this.biomeSource.getVersion());
HashMap<Generator.ILootType, List<List<ItemStack>>> lootTypeListHashMap= ruinedPortal.getLoot(this.biomeSource.getWorldSeed(),this.structureGenerator,new ChunkRand(),false);
RuinedPortal ruinedPortal = new RuinedPortal(this.biomeSource.getDimension(), this.biomeSource.getVersion());
HashMap<Generator.ILootType, List<List<ItemStack>>> lootTypeListHashMap = ruinedPortal.getLoot(this.biomeSource.getWorldSeed(), this.structureGenerator, new ChunkRand(), false);
assertTrue(lootTypeListHashMap.containsKey(RuinedPortalGenerator.LootType.RUINED_PORTAL));
List<List<ItemStack>> l=lootTypeListHashMap.get(RuinedPortalGenerator.LootType.RUINED_PORTAL);
List<List<ItemStack>> l = lootTypeListHashMap.get(RuinedPortalGenerator.LootType.RUINED_PORTAL);
assertEquals(1, l.size());
List<ItemStack> loot=l.get(0);
long hashcode=0;
for (ItemStack stack : loot) hashcode+=stack.hashCode();
assertEquals(-910440243,hashcode,"Something changed in loot");
List<ItemStack> loot = l.get(0);
long hashcode = 0;
for (ItemStack stack : loot) hashcode += stack.hashCode();
assertEquals(-910440243, hashcode, "Something changed in loot");
}

@Test
public void testPortal() {
setup(Dimension.OVERWORLD,7948314503011477316L,new CPos(64,40), MCVersion.v1_16_5);
setup(Dimension.OVERWORLD, 7948314503011477316L, new CPos(64, 40), MCVersion.v1_16_5);
List<Pair<RuinedPortalGenerator.LootType, BPos>> checks = new ArrayList<Pair<RuinedPortalGenerator.LootType, BPos>>() {{
add(new Pair<>(RuinedPortalGenerator.LootType.RUINED_PORTAL, new BPos(1035, 65, 642)));
}};
Expand All @@ -183,7 +202,7 @@ public void testPortal() {
add(new Pair<>(Blocks.CRYING_OBSIDIAN, new BPos(1036, 65, 645)));
add(new Pair<>(Blocks.CRYING_OBSIDIAN, new BPos(1036, 65, 644)));
}};
RuinedPortalGenerator ruinedPortalGenerator= (RuinedPortalGenerator) structureGenerator;
RuinedPortalGenerator ruinedPortalGenerator = (RuinedPortalGenerator) structureGenerator;
for (Pair<Block, BPos> block : blocks) {
assertTrue(portal.contains(block), String.format("Missing loot %s at pos %s for loots: %s", block.getFirst(), block.getSecond(), Arrays.toString(portal.toArray())));
}
Expand Down

0 comments on commit f215061

Please sign in to comment.