Skip to content

Commit

Permalink
Fix duplicate registration error for empty loot table (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD authored Jun 22, 2024
1 parent 1bd3d19 commit 6481868
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/java/net/neoforged/neoforge/event/EventHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.DynamicOps;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenCustomHashSet;
import java.io.File;
import java.util.EnumSet;
Expand Down Expand Up @@ -100,6 +101,7 @@
import net.minecraft.world.level.portal.PortalShape;
import net.minecraft.world.level.storage.PlayerDataStorage;
import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.level.storage.loot.LootDataType;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -680,12 +682,18 @@ public static boolean onProjectileImpact(Projectile projectile, HitResult ray) {
return NeoForge.EVENT_BUS.post(new ProjectileImpactEvent(projectile, ray)).isCanceled();
}

/**
* Fires the {@link LootTableLoadEvent} for non-empty loot tables and returns the table if the event was not
* canceled and the table was not set to {@link LootTable#EMPTY} in the event. Otherwise returns {@code null}
* which maps to an empty {@link Optional} in {@link LootDataType#deserialize(ResourceLocation, DynamicOps, Object)}
*/
@Nullable
public static LootTable loadLootTable(ResourceLocation name, LootTable table) {
if (table == LootTable.EMPTY) // Empty table has a null name, and shouldn't be modified anyway.
return table;
return null;
LootTableLoadEvent event = new LootTableLoadEvent(name, table);
if (NeoForge.EVENT_BUS.post(event).isCanceled())
return LootTable.EMPTY;
if (NeoForge.EVENT_BUS.post(event).isCanceled() || event.getTable() == LootTable.EMPTY)
return null;
return event.getTable();
}

Expand Down

0 comments on commit 6481868

Please sign in to comment.