initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
97
java/src/game/item/RngLoot.java
Executable file
97
java/src/game/item/RngLoot.java
Executable file
|
@ -0,0 +1,97 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import game.inventory.IInventory;
|
||||
import game.rng.Random;
|
||||
import game.rng.RngItem;
|
||||
import game.rng.WeightedList;
|
||||
import game.tileentity.TileEntityDispenser;
|
||||
|
||||
public class RngLoot extends RngItem
|
||||
{
|
||||
private ItemStack item;
|
||||
private int minStackSize;
|
||||
private int maxStackSize;
|
||||
|
||||
public RngLoot(Item item, int amount, int min, int max, int weight)
|
||||
{
|
||||
super(weight);
|
||||
this.item = new ItemStack(item, 1, amount);
|
||||
this.minStackSize = min;
|
||||
this.maxStackSize = max;
|
||||
}
|
||||
|
||||
public RngLoot(ItemStack stack, int min, int max, int weight)
|
||||
{
|
||||
super(weight);
|
||||
this.item = stack;
|
||||
this.minStackSize = min;
|
||||
this.maxStackSize = max;
|
||||
}
|
||||
|
||||
public ItemStack getItem(Random rand) {
|
||||
if(this.item == null)
|
||||
return null;
|
||||
ItemStack stack = this.item.copy();
|
||||
stack.stackSize = this.minStackSize + rand.zrange(this.maxStackSize - this.minStackSize + 1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static void generateChestContents(Random random, WeightedList<RngLoot> list, IInventory inv, int max)
|
||||
{
|
||||
for (int i = 0; i < max; ++i)
|
||||
{
|
||||
RngLoot loot = (RngLoot)list.pick(random);
|
||||
int j = loot.minStackSize + random.zrange(loot.maxStackSize - loot.minStackSize + 1);
|
||||
|
||||
if (loot.item.getMaxStackSize() >= j)
|
||||
{
|
||||
ItemStack itemstack1 = loot.item.copy();
|
||||
itemstack1.stackSize = j;
|
||||
inv.setInventorySlotContents(random.zrange(inv.getSizeInventory()), itemstack1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int k = 0; k < j; ++k)
|
||||
{
|
||||
ItemStack itemstack = loot.item.copy();
|
||||
itemstack.stackSize = 1;
|
||||
inv.setInventorySlotContents(random.zrange(inv.getSizeInventory()), itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateDispenserContents(Random random, WeightedList<RngLoot> list, TileEntityDispenser dispenser, int max)
|
||||
{
|
||||
for (int i = 0; i < max; ++i)
|
||||
{
|
||||
RngLoot loot = (RngLoot)list.pick(random);
|
||||
int j = loot.minStackSize + random.zrange(loot.maxStackSize - loot.minStackSize + 1);
|
||||
|
||||
if (loot.item.getMaxStackSize() >= j)
|
||||
{
|
||||
ItemStack itemstack1 = loot.item.copy();
|
||||
itemstack1.stackSize = j;
|
||||
dispenser.setInventorySlotContents(random.zrange(dispenser.getSizeInventory()), itemstack1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int k = 0; k < j; ++k)
|
||||
{
|
||||
ItemStack itemstack = loot.item.copy();
|
||||
itemstack.stackSize = 1;
|
||||
dispenser.setInventorySlotContents(random.zrange(dispenser.getSizeInventory()), itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static WeightedList<RngLoot> addToList(WeightedList<RngLoot> items, RngLoot... add)
|
||||
{
|
||||
WeightedList<RngLoot> list = new WeightedList(items);
|
||||
Collections.addAll(list, add);
|
||||
return list;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue