mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Fix loot
This commit is contained in:
parent
8bcb3d9e0e
commit
8a241bb671
@ -1,5 +1,6 @@
|
|||||||
package com.volmit.iris.gen.layer;
|
package com.volmit.iris.gen.layer;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -196,13 +197,11 @@ public class GenLayerUpdate extends BlockPopulator
|
|||||||
{
|
{
|
||||||
KList<ItemStack> items = new KList<>();
|
KList<ItemStack> items = new KList<>();
|
||||||
|
|
||||||
for(int t = 0; t < gen.getDimension().getLootTries(); t++)
|
|
||||||
{
|
|
||||||
int b = 4;
|
int b = 4;
|
||||||
for(IrisLootTable i : tables)
|
for(IrisLootTable i : tables)
|
||||||
{
|
{
|
||||||
b++;
|
b++;
|
||||||
items.addAll(i.getLoot(debug, rng.nextParallelRNG(345911 * -t), slot, x, y, z, t + b + b, mgf + b));
|
items.addAll(i.getLoot(debug, items.isEmpty(), rng.nextParallelRNG(345911), slot, x, y, z, b + b, mgf + b));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ItemStack i : items)
|
for(ItemStack i : items)
|
||||||
@ -210,12 +209,6 @@ public class GenLayerUpdate extends BlockPopulator
|
|||||||
inv.addItem(i);
|
inv.addItem(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(items.isNotEmpty())
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scramble(inv, rng);
|
scramble(inv, rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,11 +224,12 @@ public class GenLayerUpdate extends BlockPopulator
|
|||||||
if(slot != null)
|
if(slot != null)
|
||||||
{
|
{
|
||||||
KList<IrisLootTable> tables = getLootTables(rng.nextParallelRNG(4568111), b);
|
KList<IrisLootTable> tables = getLootTables(rng.nextParallelRNG(4568111), b);
|
||||||
|
InventorySlotType slott = slot;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InventoryHolder m = (InventoryHolder) b.getState();
|
InventoryHolder m = (InventoryHolder) b.getState();
|
||||||
addItems(false, m.getInventory(), rng, tables, slot, rx, b.getY(), rz, 15);
|
addItems(false, m.getInventory(), rng, tables, slott, rx, b.getY(), rz, 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(Throwable ignored)
|
catch(Throwable ignored)
|
||||||
@ -247,64 +241,49 @@ public class GenLayerUpdate extends BlockPopulator
|
|||||||
|
|
||||||
public void scramble(Inventory inventory, RNG rng)
|
public void scramble(Inventory inventory, RNG rng)
|
||||||
{
|
{
|
||||||
KList<ItemStack> v = new KList<>();
|
ItemStack[] items = inventory.getContents();
|
||||||
|
ItemStack[] nitems = new ItemStack[inventory.getSize()];
|
||||||
|
System.arraycopy(items, 0, nitems, 0, items.length);
|
||||||
|
boolean packedFull = false;
|
||||||
|
|
||||||
for(ItemStack i : inventory.getContents())
|
splitting: for(int i = 0; i < nitems.length; i++)
|
||||||
{
|
{
|
||||||
if(i == null)
|
ItemStack is = nitems[i];
|
||||||
|
|
||||||
|
if(is != null && is.getAmount() > 1 && !packedFull)
|
||||||
{
|
{
|
||||||
continue;
|
for(int j = 0; j < nitems.length; j++)
|
||||||
}
|
|
||||||
|
|
||||||
v.add(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
inventory.clear();
|
|
||||||
int sz = inventory.getSize();
|
|
||||||
int tr = 5;
|
|
||||||
|
|
||||||
while(v.isNotEmpty())
|
|
||||||
{
|
{
|
||||||
int slot = rng.i(0, sz - 1);
|
if(nitems[j] == null)
|
||||||
|
|
||||||
if(inventory.getItem(slot) == null)
|
|
||||||
{
|
{
|
||||||
tr = tr < 5 ? tr + 1 : tr;
|
int take = rng.nextInt(is.getAmount());
|
||||||
int pick = rng.i(0, v.size() - 1);
|
take = take == 0 ? 1 : take;
|
||||||
ItemStack g = v.get(pick);
|
is.setAmount(is.getAmount() - take);
|
||||||
|
nitems[j] = is.clone();
|
||||||
if(g.getAmount() == 1)
|
nitems[j].setAmount(take);
|
||||||
{
|
continue splitting;
|
||||||
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
|
packedFull = true;
|
||||||
{
|
}
|
||||||
tr--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tr <= 0)
|
for(int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Arrays.parallelSort(nitems, (a, b) -> rng.nextInt());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ItemStack i : v)
|
inventory.setContents(nitems);
|
||||||
{
|
|
||||||
inventory.addItem(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLight(Block b, FastBlockData data)
|
public void updateLight(Block b, FastBlockData data)
|
||||||
|
@ -94,8 +94,16 @@ public class IrisCompat
|
|||||||
return txf;
|
return txf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nomore = 64;
|
||||||
|
|
||||||
searching: while(true)
|
searching: while(true)
|
||||||
{
|
{
|
||||||
|
if(nomore < 0)
|
||||||
|
{
|
||||||
|
return B.parseBlockDataOrNull("STONE").getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
nomore--;
|
||||||
if(err-- <= 0)
|
if(err-- <= 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -127,9 +135,17 @@ public class IrisCompat
|
|||||||
{
|
{
|
||||||
return tx.getType();
|
return tx.getType();
|
||||||
}
|
}
|
||||||
|
nomore = 64;
|
||||||
|
|
||||||
searching: while(true)
|
searching: while(true)
|
||||||
{
|
{
|
||||||
|
if(nomore < 0)
|
||||||
|
{
|
||||||
|
return B.parseBlockDataOrNull("STONE").getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
nomore--;
|
||||||
|
|
||||||
if(err-- <= 0)
|
if(err-- <= 0)
|
||||||
{
|
{
|
||||||
return B.parseBlockDataOrNull("STONE").getType();
|
return B.parseBlockDataOrNull("STONE").getType();
|
||||||
|
@ -217,14 +217,14 @@ public class IrisLoot
|
|||||||
return new ItemStack(Material.AIR);
|
return new ItemStack(Material.AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack get(boolean debug, IrisLootTable table, RNG rng, int x, int y, int z)
|
public ItemStack get(boolean debug, boolean giveSomething, IrisLootTable table, RNG rng, int x, int y, int z)
|
||||||
{
|
{
|
||||||
if(debug)
|
if(debug)
|
||||||
{
|
{
|
||||||
chance.reset();
|
chance.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chance.aquire(() -> NoiseStyle.STATIC.create(rng)).fit(1, rarity * table.getRarity(), x, y, z) == 1)
|
if(giveSomething || chance.aquire(() -> NoiseStyle.STATIC.create(rng)).fit(1, rarity * table.getRarity(), x, y, z) == 1)
|
||||||
{
|
{
|
||||||
if(getType() == null)
|
if(getType() == null)
|
||||||
{
|
{
|
||||||
|
@ -39,14 +39,19 @@ public class IrisLootTable extends IrisRegistrant
|
|||||||
@MinNumber(1)
|
@MinNumber(1)
|
||||||
@DontObfuscate
|
@DontObfuscate
|
||||||
@Desc("The maximum amount of loot that can be picked in this table at a time.")
|
@Desc("The maximum amount of loot that can be picked in this table at a time.")
|
||||||
private int maxPicked = 3;
|
private int maxPicked = 5;
|
||||||
|
|
||||||
|
@MinNumber(0)
|
||||||
|
@DontObfuscate
|
||||||
|
@Desc("The minimum amount of loot that can be picked in this table at a time.")
|
||||||
|
private int minPicked = 1;
|
||||||
|
|
||||||
@DontObfuscate
|
@DontObfuscate
|
||||||
@Desc("The loot in this table")
|
@Desc("The loot in this table")
|
||||||
@ArrayType(min = 1, type = IrisLoot.class)
|
@ArrayType(min = 1, type = IrisLoot.class)
|
||||||
private KList<IrisLoot> loot = new KList<>();
|
private KList<IrisLoot> loot = new KList<>();
|
||||||
|
|
||||||
public KList<ItemStack> getLoot(boolean debug, RNG rng, InventorySlotType slot, int x, int y, int z, int gg, int ffs)
|
public KList<ItemStack> getLoot(boolean debug, boolean doSomething, RNG rng, InventorySlotType slot, int x, int y, int z, int gg, int ffs)
|
||||||
{
|
{
|
||||||
KList<ItemStack> lootf = new KList<>();
|
KList<ItemStack> lootf = new KList<>();
|
||||||
|
|
||||||
@ -56,7 +61,7 @@ public class IrisLootTable extends IrisRegistrant
|
|||||||
{
|
{
|
||||||
if(i.getSlotTypes().equals(slot))
|
if(i.getSlotTypes().equals(slot))
|
||||||
{
|
{
|
||||||
ItemStack item = i.get(debug, this, rng, x, y, z);
|
ItemStack item = i.get(debug, false, this, rng, x, y, z);
|
||||||
|
|
||||||
if(item != null)
|
if(item != null)
|
||||||
{
|
{
|
||||||
@ -72,6 +77,18 @@ public class IrisLootTable extends IrisRegistrant
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
lootf.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return lootf;
|
return lootf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user