Merge pull request #399 from StrangeOne101/1.17

Fixed Loot tables acting like a cucumber in the sun
This commit is contained in:
Dan 2021-07-04 21:54:27 -04:00 committed by GitHub
commit 6fc8324337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 30 deletions

View File

@ -1,5 +1,6 @@
package com.volmit.iris.object;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import com.volmit.iris.util.ArrayType;
@ -56,35 +57,21 @@ public class IrisLootTable extends IrisRegistrant
KList<ItemStack> lootf = new KList<>();
int m = 0;
int mx = rng.i(getMinPicked(), getMaxPicked());
for(IrisLoot i : loot)
{
if(i.getSlotTypes().equals(slot))
while (m < mx) {
int num = rng.i(loot.size());
IrisLoot l = loot.get(num);
if(l.getSlotTypes() == slot)
{
ItemStack item = i.get(debug, false, this, rng, x, y, z);
ItemStack item = l.get(debug, false, this, rng, x, y, z);
if(item != null)
{
lootf.add(item);
}
}
m++;
if(m > maxPicked)
{
break;
}
}
if(lootf.size() < getMinPicked())
{
for(int i = 0; i < getMinPicked() - lootf.size(); i++)
{
ItemStack item = loot.get(rng.nextParallelRNG(3945).nextInt(loot.size())).get(debug, doSomething, this, rng, x, y, z);
if(item != null)
if(item != null && item.getType() != Material.AIR)
{
lootf.add(item);
m++;
}
}
}

View File

@ -256,6 +256,12 @@ public class IrisObjectPlacement
});
}
/**
* Gets the loot table that should be used for the block
* @param data The block data of the block
* @param dataManager Iris Data Manager
* @return The loot table it should use.
*/
public IrisLootTable getTable(BlockData data, IrisDataManager dataManager) {
TableCache cache = getCache(dataManager);

View File

@ -1,5 +1,6 @@
package com.volmit.iris.scaffold.engine;
import com.volmit.iris.Iris;
import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.manager.gui.Renderer;
import com.volmit.iris.object.*;
@ -210,7 +211,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
if(B.isStorage(data))
{
RNG rx = rf.nextParallelRNG(x).nextParallelRNG(z).nextParallelRNG(y);
RNG rx = rf.nextParallelRNG(BlockPosition.toLong(x, y, z));
InventorySlotType slot = null;
if(B.isStorageChest(data))
@ -220,7 +221,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
if(slot != null)
{
KList<IrisLootTable> tables = getLootTables(rx.nextParallelRNG(4568111), block);
KList<IrisLootTable> tables = getLootTables(rx, block);
InventorySlotType slott = slot;
try
@ -350,7 +351,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
for(IrisLootTable i : tables)
{
b++;
items.addAll(i.getLoot(debug, items.isEmpty(), rng.nextParallelRNG(345911), slot, x, y, z, b + b, mgf + b));
items.addAll(i.getLoot(debug, items.isEmpty(), rng, slot, x, y, z, b + b, mgf + b));
}
for(ItemStack i : items)

View File

@ -9,6 +9,7 @@ import com.volmit.iris.scaffold.IrisWorlds;
import com.volmit.iris.scaffold.engine.Engine;
import com.volmit.iris.scaffold.engine.IrisAccess;
import com.volmit.iris.util.AxisAlignedBB;
import com.volmit.iris.util.BlockPosition;
import com.volmit.iris.util.IObjectPlacer;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.RNG;
@ -148,6 +149,7 @@ public class PlannedPiece {
getPiece().getPlacementOptions().getRotation().setEnabled(false);
int finalMinY = minY;
RNG rng = getStructure().getRng().nextParallelRNG(37555);
getObject().place(position.getX()+getObject().getCenter().getBlockX(), position.getY()+getObject().getCenter().getBlockY(), position.getZ()+getObject().getCenter().getBlockZ(), new IObjectPlacer() {
@Override
public int getHighest(int x, int z) {
@ -174,7 +176,8 @@ public class PlannedPiece {
IrisLootTable table = getPiece().getPlacementOptions().getTable(block.getBlockData(), getData());
if (table == null) return;
Engine engine = a.getCompound().getEngineForHeight(y);
engine.addItems(false, ((InventoryHolder) block.getState()).getInventory(), getStructure().getRng(),
engine.addItems(false, ((InventoryHolder) block.getState()).getInventory(),
rng.nextParallelRNG(BlockPosition.toLong(x, y, z)),
new KList<>(table), InventorySlotType.STORAGE, x, y, z, 15);
}
}
@ -215,6 +218,6 @@ public class PlannedPiece {
tile.toBukkitTry(state);
state.update();
}
}, piece.getPlacementOptions(), getStructure().getRng(), getData());
}, piece.getPlacementOptions(), rng, getData());
}
}

View File

@ -11,6 +11,15 @@ public class BlockPosition
private int y;
private int z;
//Magic numbers
private static final int m1 = 1 + MathHelper.f(MathHelper.c(30000000));
private static final int m2 = 64 - (m1 * 2);
private static final long m3 = m1 + m2;
private static final long m4 = (1L << m1) - 1L;
private static final long m5 = (1L << m2) - 1L;
private static final long m6 = (1L << m1) - 1L;
public BlockPosition(int x, int y, int z)
{
this.x = x;
@ -59,4 +68,16 @@ public class BlockPosition
{
return this.x == x && this.y == y && this.z == z;
}
public long asLong() {
return toLong(getX(), getY(), getZ());
}
public static long toLong(int x, int y, int z) {
long var3 = 0L;
var3 |= (x & m4) << m3;
var3 |= (y & m5) << 0L;
var3 |= (z & m6) << m2;
return var3;
}
}

View File

@ -132,7 +132,7 @@ public class RNG extends Random
public int i(int lowerBound, int upperBound)
{
return (int) Math.round(d(lowerBound, upperBound));
return (int) Math.floor(d(lowerBound, upperBound));
}
public int i(int upperBound)
@ -192,4 +192,8 @@ public class RNG extends Random
return pieces.get(nextInt(pieces.size()));
}
public long getSeed() {
return sx;
}
}