Skip to content

Commit

Permalink
Fix loot table NPE (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 22, 2024
1 parent 94d8220 commit aeb7246
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.izzel.arclight.common.bridge.core.world.storage.loot;

import net.minecraft.world.level.storage.loot.LootTable;

public interface LootDataManagerBridge {

boolean bridge$isRegistered(LootTable lootTable);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.izzel.arclight.common.mixin.core.world.level.storage.loot;

import com.google.common.collect.ImmutableMap;
import io.izzel.arclight.common.bridge.core.world.storage.loot.LootDataManagerBridge;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.LootDataId;
import net.minecraft.world.level.storage.loot.LootDataManager;
import net.minecraft.world.level.storage.loot.LootDataType;
import net.minecraft.world.level.storage.loot.LootTable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -14,7 +16,7 @@
import java.util.Map;

@Mixin(LootDataManager.class)
public class LootDataManagerMixin {
public class LootDataManagerMixin implements LootDataManagerBridge {

// @formatter:off
@Shadow private Map<LootDataId<?>, ?> elements;
Expand All @@ -28,4 +30,9 @@ public class LootDataManagerMixin {
this.elements.forEach((key, lootTable) -> lootTableToKeyBuilder.put(lootTable, key.location()));
this.lootTableToKey = lootTableToKeyBuilder.buildKeepingLast();
}

@Override
public boolean bridge$isRegistered(LootTable lootTable) {
return this.lootTableToKey.containsKey(lootTable);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.izzel.arclight.common.mixin.core.world.level.storage.loot;

import io.izzel.arclight.common.bridge.core.world.storage.loot.LootDataManagerBridge;
import io.izzel.arclight.common.bridge.core.world.storage.loot.LootTableBridge;
import io.izzel.arclight.common.mod.server.ArclightServer;
import io.izzel.arclight.mixin.Eject;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -41,6 +43,9 @@ public abstract class LootTableMixin implements LootTableBridge {
if (!context.hasParam(LootContextParams.ORIGIN) && !context.hasParam(LootContextParams.THIS_ENTITY)) {
return list;
}
if (!((LootDataManagerBridge) ArclightServer.getMinecraftServer().getLootData()).bridge$isRegistered((LootTable) (Object) this)) {
return list;
}
LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, list, false);
if (event.isCancelled()) {
ci.cancel();
Expand All @@ -54,11 +59,14 @@ public void fillInventory(Container inv, LootParams lootparams, long i, boolean
LootContext context = (new LootContext.Builder(lootparams)).withOptionalRandomSeed(i).create(this.randomSequence);
ObjectArrayList<ItemStack> objectarraylist = this.getRandomItems(context);
RandomSource randomsource = context.getRandom();
LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, objectarraylist, plugin);
if (event.isCancelled()) {
return;

if (((LootDataManagerBridge) ArclightServer.getMinecraftServer().getLootData()).bridge$isRegistered((LootTable) (Object) this)) {
LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, objectarraylist, plugin);
if (event.isCancelled()) {
return;
}
objectarraylist = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(ObjectArrayList.toList());
}
objectarraylist = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(ObjectArrayList.toList());

List<Integer> list = this.getAvailableSlots(inv, randomsource);
this.shuffleAndSplitItems(objectarraylist, list.size(), randomsource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ abstract class UploadFilesTask extends DefaultTask {
}
}
link("/arclight/branches/${branch.get()}/versions-snapshot/${version.get()}/${modloader}", [type: 'object', value: sha1])
link("/arclight/branches/${branch.get()}/loaders/${modloader}/versions-snapshot/${version.get()}", [type: 'object', value: sha1])
link("/arclight/branches/${branch.get()}/latest-snapshot", [type: 'link', value: "/arclight/branches/${branch.get()}/versions-snapshot/${version.get()}", cache_seconds: 3600])
link("/arclight/branches/${branch.get()}/loaders/${modloader}/latest-snapshot", [type: 'link', value: "/arclight/branches/${branch.get()}/loaders/${modloader}/versions-snapshot/${version.get()}", cache_seconds: 3600])
if (!snapshot.get()) {
link("/arclight/branches/${branch.get()}/versions-stable/${version.get()}/${modloader}", [type: 'object', value: sha1])
link("/arclight/branches/${branch.get()}/loaders/${modloader}/versions-stable/${version.get()}", [type: 'object', value: sha1])
link("/arclight/branches/${branch.get()}/latest-stable", [type: 'link', value: "/arclight/branches/${branch.get()}/versions-stable/${version.get()}", cache_seconds: 86400])
link("/arclight/branches/${branch.get()}/loaders/${modloader}/latest-stable", [type: 'link', value: "/arclight/branches/${branch.get()}/loaders/${modloader}/versions-stable/${version.get()}", cache_seconds: 86400])
}
}

Expand Down

0 comments on commit aeb7246

Please sign in to comment.