Add LootTableManager to the LootTableLoadEvent (#3717)

This commit is contained in:
Paulo "JCranky" Siqueira authored and LexManos committed 2017-04-07 16:22:49 -07:00
1 parent b99aa9bca4
commit be2d814155
6 files changed
+220 -7

No files matched your search

@@ -93,6 +93,7 @@ import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.GameType;
import net.minecraft.world.storage.loot.LootEntry;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.event.AnvilUpdateEvent;
@@ -1092,13 +1093,21 @@ public class ForgeHooks
LootTableContext ctx = lootContext.get().peek();
if (ctx == null)
throw new JsonParseException("Invalid call stack, could to grab json context!"); // Show I throw this? Do we care about custom deserializers outside the manager?
throw new JsonParseException("Invalid call stack, could not grab json context!"); // Should I throw this? Do we care about custom deserializers outside the manager?
return ctx;
}
@Nullable
// TODO: remove
/** @deprecated use {@link ForgeHooks#loadLootTable(Gson, ResourceLocation, String, boolean, LootTableManager)} */
@Deprecated
public static LootTable loadLootTable(Gson gson, ResourceLocation name, String data, boolean custom)
{
return loadLootTable(gson, name, data, custom, null);
}
@Nullable
public static LootTable loadLootTable(Gson gson, ResourceLocation name, String data, boolean custom, LootTableManager lootTableManager)
{
Deque<LootTableContext> que = lootContext.get();
if (que == null)
@@ -1121,7 +1130,7 @@ public class ForgeHooks
}
if (!custom)
ret = ForgeEventFactory.loadLootTable(name, ret);
ret = ForgeEventFactory.loadLootTable(name, ret, lootTableManager);
if (ret != null)
ret.freeze();
@@ -64,6 +64,7 @@ import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.storage.IPlayerFileData;
import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderBlockOverlayEvent;
@@ -645,9 +646,18 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(pre ? new PopulateChunkEvent.Pre(gen, world, rand, x, z, hasVillageGenerated) : new PopulateChunkEvent.Post(gen, world, rand, x, z, hasVillageGenerated));
}
/**
* @deprecated Use {@link #loadLootTable(ResourceLocation, LootTable, LootTableManager)}<br>
*/
@Deprecated
public static LootTable loadLootTable(ResourceLocation name, LootTable table)
{
LootTableLoadEvent event = new LootTableLoadEvent(name, table);
return loadLootTable(name, table, null);
}
public static LootTable loadLootTable(ResourceLocation name, LootTable table, LootTableManager lootTableManager)
{
LootTableLoadEvent event = new LootTableLoadEvent(name, table, lootTableManager);
if (MinecraftForge.EVENT_BUS.post(event))
return LootTable.EMPTY_LOOT_TABLE;
return event.getTable();
@@ -21,6 +21,7 @@ package net.minecraftforge.event;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
@@ -38,11 +39,21 @@ public class LootTableLoadEvent extends Event
{
private final ResourceLocation name;
private LootTable table;
private LootTableManager lootTableManager;
public LootTableLoadEvent(ResourceLocation name, LootTable table)
/**
* @deprecated Use {@link #LootTableLoadEvent(ResourceLocation, LootTable, LootTableManager)}<br>
*/
@Deprecated
public LootTableLoadEvent(ResourceLocation name, LootTable table) {
this(name, table, null);
}
public LootTableLoadEvent(ResourceLocation name, LootTable table, LootTableManager lootTableManager)
{
this.name = name;
this.table = table;
this.lootTableManager = lootTableManager;
}
public ResourceLocation getName()
@@ -55,6 +66,11 @@ public class LootTableLoadEvent extends Event
return this.table;
}
public LootTableManager getLootTableManager()
{
return this.lootTableManager;
}
public void setTable(LootTable table)
{
this.table = table;