Add in a mechanism for explicit subclassing of WeightedRandomChestItem to allow for
generational style chest content generation rather than static. Cleans up some old code nicely
This commit is contained in:
parent
695b080197
commit
b386565881
2 changed files with 38 additions and 16 deletions
|
@ -3,6 +3,9 @@ package net.minecraftforge.common;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
|
@ -148,12 +151,18 @@ public class DungeonHooks
|
|||
{
|
||||
int min = theMinimumChanceToGenerateItem;
|
||||
int max = theMaximumChanceToGenerateItem;
|
||||
|
||||
|
||||
ItemStack ret = this.theItemId.copy();
|
||||
ret.stackSize = min + (rand.nextInt(max - min + 1));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final ItemStack[] generateChestContent(Random random, IInventory newInventory)
|
||||
{
|
||||
FMLLog.warning("Some mod is still using DungeonHooks.DungonLoot, tell them to stop! %s", this);
|
||||
return new ItemStack[] { generateStack(random) };
|
||||
}
|
||||
public boolean equals(ItemStack item, int min, int max)
|
||||
{
|
||||
int minCount = theMinimumChanceToGenerateItem;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
--- ../src_base/minecraft/net/minecraft/util/WeightedRandomChestContent.java
|
||||
+++ ../src_work/minecraft/net/minecraft/util/WeightedRandomChestContent.java
|
||||
@@ -1,9 +1,13 @@
|
||||
@@ -1,9 +1,14 @@
|
||||
package net.minecraft.util;
|
||||
|
||||
import java.util.Random;
|
||||
+
|
||||
+import cpw.mods.fml.common.FMLLog;
|
||||
+import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.tileentity.TileEntityDispenser;
|
||||
|
@ -14,7 +15,7 @@
|
|||
|
||||
public class WeightedRandomChestContent extends WeightedRandomItem
|
||||
{
|
||||
@@ -35,27 +39,26 @@
|
||||
@@ -35,27 +40,17 @@
|
||||
/**
|
||||
* Generates the Chest contents.
|
||||
*/
|
||||
|
@ -25,24 +26,17 @@
|
|||
{
|
||||
WeightedRandomChestContent var5 = (WeightedRandomChestContent)WeightedRandom.getRandomItem(par0Random, par1ArrayOfWeightedRandomChestContent);
|
||||
- int var6 = var5.theMinimumChanceToGenerateItem + par0Random.nextInt(var5.theMaximumChanceToGenerateItem - var5.theMinimumChanceToGenerateItem + 1);
|
||||
+ ItemStack[] stacks = var5.generateChestContent(par0Random, par2TileEntityChest);
|
||||
|
||||
- if (var5.theItemId.getMaxStackSize() >= var6)
|
||||
+ if (var5 instanceof DungeonHooks.DungeonLoot)
|
||||
+ for (ItemStack item : stacks)
|
||||
{
|
||||
- ItemStack var7 = var5.theItemId.copy();
|
||||
- var7.stackSize = var6;
|
||||
- par2TileEntityChest.setInventorySlotContents(par0Random.nextInt(par2TileEntityChest.getSizeInventory()), var7);
|
||||
+ DungeonHooks.DungeonLoot loot = (DungeonHooks.DungeonLoot)var5;
|
||||
+ par2TileEntityChest.setInventorySlotContents(par0Random.nextInt(par2TileEntityChest.getSizeInventory()), loot.generateStack(par0Random));
|
||||
+ FMLLog.warning("Some mod is still using DungeonHooks.DungonLoot, tell them to stop! %s", loot);
|
||||
+ continue;
|
||||
}
|
||||
- }
|
||||
- else
|
||||
+
|
||||
+ ItemStack[] stacks = ChestGenHooks.generateStacks(par0Random, var5.theItemId, var5.theMinimumChanceToGenerateItem, var5.theMaximumChanceToGenerateItem);
|
||||
+
|
||||
+ for (ItemStack item : stacks)
|
||||
{
|
||||
- {
|
||||
- for (int var9 = 0; var9 < var6; ++var9)
|
||||
- {
|
||||
- ItemStack var8 = var5.theItemId.copy();
|
||||
|
@ -53,12 +47,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
@@ -68,22 +71,11 @@
|
||||
@@ -68,22 +63,11 @@
|
||||
for (int var4 = 0; var4 < par3; ++var4)
|
||||
{
|
||||
WeightedRandomChestContent var5 = (WeightedRandomChestContent)WeightedRandom.getRandomItem(par0Random, par1ArrayOfWeightedRandomChestContent);
|
||||
- int var6 = var5.theMinimumChanceToGenerateItem + par0Random.nextInt(var5.theMaximumChanceToGenerateItem - var5.theMinimumChanceToGenerateItem + 1);
|
||||
+ ItemStack[] stacks = ChestGenHooks.generateStacks(par0Random, var5.theItemId, var5.theMinimumChanceToGenerateItem, var5.theMaximumChanceToGenerateItem);
|
||||
+ ItemStack[] stacks = var5.generateChestContent(par0Random, par2TileEntityDispenser);
|
||||
|
||||
- if (var5.theItemId.getMaxStackSize() >= var6)
|
||||
+ for (ItemStack item : stacks)
|
||||
|
@ -79,3 +73,22 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
@@ -109,4 +93,18 @@
|
||||
|
||||
return var2;
|
||||
}
|
||||
+
|
||||
+ // -- Forge hooks
|
||||
+ /**
|
||||
+ * Allow a mod to submit a custom implementation that can delegate item stack generation beyond simple stack lookup
|
||||
+ *
|
||||
+ * @param random The current random for generation
|
||||
+ * @param newInventory The inventory being generated (do not populate it, but you can refer to it)
|
||||
+ * @return An array of {@link ItemStack} to put into the chest
|
||||
+ */
|
||||
+ protected ItemStack[] generateChestContent(Random random, IInventory newInventory)
|
||||
+ {
|
||||
+ return ChestGenHooks.generateStacks(random, theItemId, theMinimumChanceToGenerateItem, theMaximumChanceToGenerateItem);
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue