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

Commit

Permalink
Add classes and fields to ForgeHooks, which might be use by hacky mods (
Browse files Browse the repository at this point in the history
  • Loading branch information
rikka0w0 committed Jul 30, 2020
1 parent f76e5db commit 2d2cc76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit 2d2cc76

Please sign in to comment.