Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Add classes and fields to ForgeHooks, which might be used by hacky mods #161

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public static boolean onPlayerAttackTarget(PlayerEntity player, Entity target) {
return EntityEvents.attackEntity(player, target);
}

@SuppressWarnings({ "rawtypes", "unused" })
private static ThreadLocal<?> lootContext = LootHooks.lootContext;

// Need to have the class here to make some mod hacks work
public static class LootTableContext extends LootHooks.LootTableContext {
private LootTableContext(Identifier name, boolean custom) {
super(name, custom);
}
}

@Nullable
public static LootTable loadLootTable(Gson gson, Identifier name, JsonObject data, boolean custom, LootManager lootTableManager) {
return LootHooks.loadLootTable(gson, name, data, custom, lootTableManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import org.spongepowered.asm.mixin.Unique;

import net.minecraft.loot.LootManager;
import net.minecraft.loot.LootTable;
Expand All @@ -41,8 +40,8 @@

// NOTE: this class is more or less a direct copy of parts of Forge's ForgeHooks.
public class LootHooks {
@Unique
private static ThreadLocal<Deque<LootTableContext>> lootContext = new ThreadLocal<Deque<LootTableContext>>();
// Made public for Patchwork's own use
public static ThreadLocal<Deque<LootTableContext>> lootContext = new ThreadLocal<Deque<LootTableContext>>();

public static LootTable loadLootTable(Gson gson, Identifier name, JsonElement data, boolean custom, LootManager lootTableManager) {
Deque<LootTableContext> que = lootContext.get();
Expand Down Expand Up @@ -105,15 +104,16 @@ public static String readPoolName(JsonObject json) {
return ctx.poolCount == 1 ? "main" : "pool" + (ctx.poolCount - 1);
}

private static class LootTableContext {
// Made public for Patchwork's own use
public static class LootTableContext {
public final Identifier name;
public final boolean custom;
private final boolean vanilla;
public int poolCount = 0;
public int entryCount = 0;
private HashSet<String> entryNames = Sets.newHashSet();

private LootTableContext(Identifier name, boolean custom) {
protected LootTableContext(Identifier name, boolean custom) {
this.name = name;
this.custom = custom;
this.vanilla = "minecraft".equals(this.name.getNamespace());
Expand Down