Files
2019-02-24 22:29:41 +08:00

113 lines
5.5 KiB
Diff

--- ../src-base/minecraft/net/minecraft/world/storage/loot/LootPool.java
+++ ../src-work/minecraft/net/minecraft/world/storage/loot/LootPool.java
@@ -21,17 +21,19 @@
public class LootPool
{
- private final LootEntry[] lootEntries;
- private final LootCondition[] poolConditions;
+ private final List<LootEntry> lootEntries;
+ private final List<LootCondition> poolConditions;
private RandomValueRange rolls;
private RandomValueRange bonusRolls;
+ private final String name;
- public LootPool(LootEntry[] lootEntriesIn, LootCondition[] poolConditionsIn, RandomValueRange rollsIn, RandomValueRange bonusRollsIn)
+ public LootPool(LootEntry[] lootEntriesIn, LootCondition[] poolConditionsIn, RandomValueRange rollsIn, RandomValueRange bonusRollsIn, String name)
{
- this.lootEntries = lootEntriesIn;
- this.poolConditions = poolConditionsIn;
+ this.lootEntries = Lists.newArrayList(lootEntriesIn);
+ this.poolConditions = Lists.newArrayList(poolConditionsIn);
this.rolls = rollsIn;
this.bonusRolls = bonusRollsIn;
+ this.name = name;
}
protected void createLootRoll(Collection<ItemStack> stacks, Random rand, LootContext context)
@@ -83,21 +85,74 @@
}
}
+ //======================== FORGE START =============================================
+ private boolean isFrozen = false;
+ public void freeze()
+ {
+ this.isFrozen = true;
+ }
+ public boolean isFrozen(){ return this.isFrozen; }
+ private void checkFrozen()
+ {
+ if (this.isFrozen())
+ throw new RuntimeException("Attempted to modify LootPool after being frozen!");
+ }
+
+ public String getName(){ return this.name; }
+ public RandomValueRange getRolls() { return this.rolls; }
+ public RandomValueRange getBonusRolls() { return this.bonusRolls; }
+ public void setRolls (RandomValueRange v){ checkFrozen(); this.rolls = v; }
+ public void setBonusRolls(RandomValueRange v){ checkFrozen(); this.bonusRolls = v; }
+
+ public LootEntry getEntry(String name)
+ {
+ for (LootEntry entry : this.lootEntries)
+ if (name.equals(entry.getEntryName()))
+ return entry;
+ return null;
+ }
+ public LootEntry removeEntry(String name)
+ {
+ checkFrozen();
+ for (LootEntry entry : this.lootEntries)
+ {
+ if (name.equals(entry.getEntryName()))
+ {
+ this.lootEntries.remove(entry);
+ return entry;
+ }
+ }
+ return null;
+ }
+ public void addEntry(LootEntry entry)
+ {
+ checkFrozen();
+ for (LootEntry e : this.lootEntries)
+ if (e == entry || e.getEntryName().equals(entry.getEntryName()))
+ throw new RuntimeException("Attempted to add a duplicate entry to pool: " + e.getEntryName());
+ this.lootEntries.add(entry);
+ }
+ //TODO: Allow modifications of conditions? If so need a way to uniquely identify them.
+ //======================== FORGE END ===============================================
+
public static class Serializer implements JsonDeserializer<LootPool>, JsonSerializer<LootPool>
{
public LootPool deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "loot pool");
+ String name = net.minecraftforge.common.ForgeHooks.readPoolName(jsonobject);
LootEntry[] alootentry = (LootEntry[])JsonUtils.deserializeClass(jsonobject, "entries", p_deserialize_3_, LootEntry[].class);
LootCondition[] alootcondition = (LootCondition[])JsonUtils.deserializeClass(jsonobject, "conditions", new LootCondition[0], p_deserialize_3_, LootCondition[].class);
RandomValueRange randomvaluerange = (RandomValueRange)JsonUtils.deserializeClass(jsonobject, "rolls", p_deserialize_3_, RandomValueRange.class);
RandomValueRange randomvaluerange1 = (RandomValueRange)JsonUtils.deserializeClass(jsonobject, "bonus_rolls", new RandomValueRange(0.0F, 0.0F), p_deserialize_3_, RandomValueRange.class);
- return new LootPool(alootentry, alootcondition, randomvaluerange, randomvaluerange1);
+ return new LootPool(alootentry, alootcondition, randomvaluerange, randomvaluerange1, name);
}
public JsonElement serialize(LootPool p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
JsonObject jsonobject = new JsonObject();
+ if (p_serialize_1_.name != null && !p_serialize_1_.name.startsWith("custom#"))
+ jsonobject.add("name", p_serialize_3_.serialize(p_serialize_1_.name));
jsonobject.add("entries", p_serialize_3_.serialize(p_serialize_1_.lootEntries));
jsonobject.add("rolls", p_serialize_3_.serialize(p_serialize_1_.rolls));
@@ -106,7 +161,7 @@
jsonobject.add("bonus_rolls", p_serialize_3_.serialize(p_serialize_1_.bonusRolls));
}
- if (!ArrayUtils.isEmpty((Object[])p_serialize_1_.poolConditions))
+ if (!p_serialize_1_.poolConditions.isEmpty())
{
jsonobject.add("conditions", p_serialize_3_.serialize(p_serialize_1_.poolConditions));
}