mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-10 17:56:08 +00:00
Parallax 2
This commit is contained in:
@@ -24,7 +24,6 @@ import com.volmit.iris.object.LootMode;
|
||||
import com.volmit.iris.util.B;
|
||||
import com.volmit.iris.util.IrisStructureResult;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KSet;
|
||||
import com.volmit.iris.util.PrecisionStopwatch;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
@@ -81,7 +80,7 @@ public class GenLayerUpdate extends BlockPopulator
|
||||
}
|
||||
}
|
||||
|
||||
public void injectTables(KSet<IrisLootTable> list, IrisLootReference r)
|
||||
public void injectTables(KList<IrisLootTable> list, IrisLootReference r)
|
||||
{
|
||||
if(r.getMode().equals(LootMode.CLEAR) || r.getMode().equals(LootMode.REPLACE))
|
||||
{
|
||||
@@ -91,15 +90,16 @@ public class GenLayerUpdate extends BlockPopulator
|
||||
list.addAll(r.getLootTables(gen));
|
||||
}
|
||||
|
||||
public KSet<IrisLootTable> getLootTables(Block b)
|
||||
public KList<IrisLootTable> getLootTables(RNG rng, Block b)
|
||||
{
|
||||
int rx = b.getX();
|
||||
int rz = b.getZ();
|
||||
IrisRegion region = gen.sampleRegion(rx, rz);
|
||||
IrisBiome biomeSurface = gen.sampleTrueBiome(rx, rz).getBiome();
|
||||
IrisBiome biomeUnder = gen.sampleTrueBiome(rx, b.getY(), rz).getBiome();
|
||||
KSet<IrisLootTable> tables = new KSet<>();
|
||||
KList<IrisLootTable> tables = new KList<IrisLootTable>();
|
||||
IrisStructureResult structure = gen.getStructure(rx, b.getY(), rz);
|
||||
double multiplier = 1D * gen.getDimension().getLoot().getMultiplier() * region.getLoot().getMultiplier() * biomeSurface.getLoot().getMultiplier() * biomeUnder.getLoot().getMultiplier();
|
||||
injectTables(tables, gen.getDimension().getLoot());
|
||||
injectTables(tables, region.getLoot());
|
||||
injectTables(tables, biomeSurface.getLoot());
|
||||
@@ -109,20 +109,38 @@ public class GenLayerUpdate extends BlockPopulator
|
||||
{
|
||||
injectTables(tables, structure.getStructure().getLoot());
|
||||
injectTables(tables, structure.getTile().getLoot());
|
||||
multiplier *= structure.getStructure().getLoot().getMultiplier() * structure.getTile().getLoot().getMultiplier();
|
||||
}
|
||||
|
||||
if(tables.isNotEmpty())
|
||||
{
|
||||
int target = (int) Math.round(tables.size() * multiplier);
|
||||
|
||||
while(tables.size() < target && tables.isNotEmpty())
|
||||
{
|
||||
tables.add(tables.get(rng.i(tables.size() - 1)));
|
||||
}
|
||||
|
||||
while(tables.size() > target && tables.isNotEmpty())
|
||||
{
|
||||
tables.remove(rng.i(tables.size() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
return tables;
|
||||
}
|
||||
|
||||
public void addItems(boolean debug, Inventory inv, RNG rng, KSet<IrisLootTable> tables, InventorySlotType slot, int x, int y, int z)
|
||||
public void addItems(boolean debug, Inventory inv, RNG rng, KList<IrisLootTable> tables, InventorySlotType slot, int x, int y, int z, int mgf)
|
||||
{
|
||||
KList<ItemStack> items = new KList<>();
|
||||
|
||||
for(int t = 0; t < gen.getDimension().getLootTries(); t++)
|
||||
{
|
||||
int b = 4;
|
||||
for(IrisLootTable i : tables)
|
||||
{
|
||||
items.addAll(i.getLoot(debug, rng.nextParallelRNG(345911 * -t), slot, x, y, z));
|
||||
b++;
|
||||
items.addAll(i.getLoot(debug, rng.nextParallelRNG(345911 * -t), slot, x, y, z, t + b + b, mgf + b));
|
||||
}
|
||||
|
||||
for(ItemStack i : items)
|
||||
@@ -135,6 +153,8 @@ public class GenLayerUpdate extends BlockPopulator
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scramble(inv, rng);
|
||||
}
|
||||
|
||||
public void updateStorage(Block b, BlockData data, int rx, int rz, RNG rng)
|
||||
@@ -148,12 +168,12 @@ public class GenLayerUpdate extends BlockPopulator
|
||||
|
||||
if(slot != null)
|
||||
{
|
||||
KSet<IrisLootTable> tables = getLootTables(b);
|
||||
KList<IrisLootTable> tables = getLootTables(rng.nextParallelRNG(4568111), b);
|
||||
|
||||
try
|
||||
{
|
||||
InventoryHolder m = (InventoryHolder) b.getState();
|
||||
addItems(false, m.getInventory(), rng, tables, slot, rx, b.getY(), rz);
|
||||
addItems(false, m.getInventory(), rng, tables, slot, rx, b.getY(), rz, 15);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
@@ -164,6 +184,68 @@ public class GenLayerUpdate extends BlockPopulator
|
||||
}
|
||||
}
|
||||
|
||||
private void scramble(Inventory inventory, RNG rng)
|
||||
{
|
||||
KList<ItemStack> v = new KList<>();
|
||||
|
||||
for(ItemStack i : inventory.getContents())
|
||||
{
|
||||
if(i == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
v.add(i);
|
||||
}
|
||||
|
||||
inventory.clear();
|
||||
int sz = inventory.getSize();
|
||||
int tr = 5;
|
||||
|
||||
while(v.isNotEmpty())
|
||||
{
|
||||
int slot = rng.i(0, sz - 1);
|
||||
|
||||
if(inventory.getItem(slot) == null)
|
||||
{
|
||||
tr = tr < 5 ? tr + 1 : tr;
|
||||
int pick = rng.i(0, v.size() - 1);
|
||||
ItemStack g = v.get(pick);
|
||||
|
||||
if(g.getAmount() == 1)
|
||||
{
|
||||
v.remove(pick);
|
||||
inventory.setItem(pick, g);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
int portion = rng.i(1, g.getAmount() - 1);
|
||||
ItemStack port = g.clone();
|
||||
port.setAmount(portion);
|
||||
g.setAmount(g.getAmount() - portion);
|
||||
v.add(g);
|
||||
inventory.setItem(slot, port);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
tr--;
|
||||
}
|
||||
|
||||
if(tr <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(ItemStack i : v)
|
||||
{
|
||||
inventory.addItem(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLight(Block b, BlockData data)
|
||||
{
|
||||
b.setType(Material.AIR, false);
|
||||
|
||||
Reference in New Issue
Block a user