mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 20:52:34 +00:00
Fix loot tables not having their ids set.
This commit is contained in:
6 files changed
+100
-22
No files matched your search
@@ -1,13 +1,15 @@
|
||||
--- a/net/minecraft/world/level/storage/loot/LootDataType.java
|
||||
+++ b/net/minecraft/world/level/storage/loot/LootDataType.java
|
||||
@@ -42,7 +_,10 @@
|
||||
@@ -42,7 +_,12 @@
|
||||
dataresult.error().ifPresent((p_297003_) -> {
|
||||
LOGGER.error("Couldn't parse element {}:{} - {}", this.directory, p_279253_, p_297003_.message());
|
||||
});
|
||||
- return dataresult.result();
|
||||
+ var ret = dataresult.result();
|
||||
+ if (this == TABLE && ret.isPresent())
|
||||
+ ret = Optional.ofNullable((T)net.minecraftforge.event.ForgeEventFactory.onLoadLootTable(p_279253_, (LootTable)ret.get()));
|
||||
+ if (ret.orElse(null) instanceof LootTable table) {
|
||||
+ table.setLootTableId(p_279253_);
|
||||
+ ret = Optional.ofNullable((T)net.minecraftforge.event.ForgeEventFactory.onLoadLootTable(p_279253_, table));
|
||||
+ }
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"entries": [
|
||||
"global_loot_test:dungeon_loot",
|
||||
"global_loot_test:bamboo_silk",
|
||||
"global_loot_test:multiply_loot",
|
||||
"global_loot_test:wheat_harvest",
|
||||
"global_loot_test:smelting"
|
||||
],
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"type": "global_loot_test:dungeon_loot",
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "forge:loot_table_id",
|
||||
"loot_table_id": "minecraft:chests/simple_dungeon"
|
||||
}
|
||||
]
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "global_loot_test:multiply_loot",
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "forge:loot_table_id",
|
||||
"loot_table_id": "global_loot_test:blocks/test"
|
||||
}
|
||||
]
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"bonus_rolls": 0.0,
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
],
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "global_loot_test:test"
|
||||
}
|
||||
],
|
||||
"rolls": 1.0
|
||||
}
|
||||
],
|
||||
"random_sequence": "global_loot_test:blocks/test"
|
||||
}
|
||||
@@ -14,8 +14,12 @@ import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.ExtraCodecs;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.loot.BlockLootSubProvider;
|
||||
import net.minecraft.data.loot.LootTableProvider;
|
||||
import net.minecraft.gametest.framework.GameTest;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
@@ -24,7 +28,9 @@ import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
@@ -36,7 +42,7 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;
|
||||
import net.minecraftforge.common.data.GlobalLootModifierProvider;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.loot.LootModifier;
|
||||
@@ -52,7 +58,9 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -63,7 +71,7 @@ public class GlobalLootModifiersTest extends BaseTestMod {
|
||||
|
||||
private static final DeferredRegister<Codec<? extends IGlobalLootModifier>> GLM = DeferredRegister.create(ForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, MODID);
|
||||
static {
|
||||
GLM.register("dungeon_loot", DungeonLootEnhancerModifier.CODEC);
|
||||
GLM.register("multiply_loot", MultiplyDropsModifier.CODEC);
|
||||
GLM.register("smelting", SmeltingEnchantmentModifier.CODEC);
|
||||
GLM.register("wheat_harvest", WheatSeedsConverterModifier.CODEC);
|
||||
GLM.register("silk_touch_bamboo", SilkTouchTestModifier.CODEC);
|
||||
@@ -72,6 +80,11 @@ public class GlobalLootModifiersTest extends BaseTestMod {
|
||||
private static final DeferredRegister<Enchantment> ENCHANTS = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, MODID);
|
||||
private static final RegistryObject<Enchantment> SMELT = ENCHANTS.register("smelt", () -> new SmelterEnchantment(Rarity.UNCOMMON, EnchantmentCategory.DIGGER, EquipmentSlot.MAINHAND));
|
||||
|
||||
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
|
||||
private static final RegistryObject<Block> TEST_BLOCK = BLOCKS.register("test", () -> new Block(BlockBehaviour.Properties.of()));
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
private static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties()));
|
||||
|
||||
public GlobalLootModifiersTest() {
|
||||
testItem(() -> {
|
||||
var smelt = new ItemStack(Items.IRON_AXE);
|
||||
@@ -83,13 +96,13 @@ public class GlobalLootModifiersTest extends BaseTestMod {
|
||||
@SubscribeEvent
|
||||
public void runData(GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(event.includeServer(), new DataProvider(event.getGenerator().getPackOutput(), MODID));
|
||||
event.getGenerator().addProvider(event.includeServer(), new LootProvider(event.getGenerator().getPackOutput()));
|
||||
}
|
||||
|
||||
@GameTest(template = "forge:empty3x3x3")
|
||||
public static void test_smelting_modifier(GameTestHelper helper) {
|
||||
var center = new BlockPos(1, 1, 1);
|
||||
helper.setBlock(center, Blocks.OAK_LOG);
|
||||
helper.assertBlock(center, block -> block == Blocks.OAK_LOG, "Failed to set log");
|
||||
|
||||
var smelt = new ItemStack(Items.IRON_AXE);
|
||||
EnchantmentHelper.setEnchantments(Map.of(SMELT.get(), 1), smelt);
|
||||
@@ -103,6 +116,24 @@ public class GlobalLootModifiersTest extends BaseTestMod {
|
||||
helper.succeed();
|
||||
}
|
||||
|
||||
@GameTest(template = "forge:empty3x3x3")
|
||||
public static void table_name_condition(GameTestHelper helper) {
|
||||
var center = new BlockPos(1, 1, 1);
|
||||
var player = helper.makeMockServerPlayer();
|
||||
|
||||
// Should be doubled
|
||||
helper.setBlock(center, TEST_BLOCK.get());
|
||||
player.gameMode.destroyBlock(helper.absolutePos(center));
|
||||
helper.assertItemEntityCountIs(TEST_ITEM.get(), center, 1.0, 2);
|
||||
|
||||
// Should not be modified
|
||||
helper.setBlock(center, Blocks.OAK_LOG);
|
||||
player.gameMode.destroyBlock(helper.absolutePos(center));
|
||||
helper.assertItemEntityCountIs(Items.OAK_LOG, center, 1.0, 1);
|
||||
|
||||
helper.succeed();
|
||||
}
|
||||
|
||||
private static class DataProvider extends GlobalLootModifierProvider {
|
||||
public DataProvider(PackOutput output, String modid) {
|
||||
super(output, modid);
|
||||
@@ -128,9 +159,9 @@ public class GlobalLootModifiersTest extends BaseTestMod {
|
||||
3, Items.WHEAT_SEEDS, Items.WHEAT)
|
||||
);
|
||||
|
||||
add("dungeon_loot", new DungeonLootEnhancerModifier(
|
||||
add("multiply_loot", new MultiplyDropsModifier(
|
||||
new LootItemCondition[] {
|
||||
LootTableIdCondition.builder(new ResourceLocation("chests/simple_dungeon")).build()
|
||||
LootTableIdCondition.builder(TEST_BLOCK.get().getLootTable()).build()
|
||||
}, 2)
|
||||
);
|
||||
|
||||
@@ -143,6 +174,30 @@ public class GlobalLootModifiersTest extends BaseTestMod {
|
||||
}
|
||||
}
|
||||
|
||||
private static class LootProvider extends LootTableProvider {
|
||||
public LootProvider(PackOutput out) {
|
||||
super(out, Set.of(), List.of(
|
||||
new LootTableProvider.SubProviderEntry(BlockLoot::new, LootContextParamSets.BLOCK)
|
||||
));
|
||||
}
|
||||
|
||||
private static class BlockLoot extends BlockLootSubProvider implements IConditionBuilder {
|
||||
public BlockLoot() {
|
||||
super(Set.of(), FeatureFlags.REGISTRY.allFlags());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<Block> getKnownBlocks() {
|
||||
return List.of(TEST_BLOCK.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generate() {
|
||||
this.dropSelf(TEST_BLOCK.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class SmelterEnchantment extends Enchantment {
|
||||
protected SmelterEnchantment(Rarity rarityIn, EnchantmentCategory typeIn, EquipmentSlot... slots) {
|
||||
super(rarityIn, typeIn, slots);
|
||||
@@ -281,15 +336,15 @@ public class GlobalLootModifiersTest extends BaseTestMod {
|
||||
}
|
||||
}
|
||||
|
||||
private static class DungeonLootEnhancerModifier extends LootModifier {
|
||||
public static final Supplier<Codec<DungeonLootEnhancerModifier>> CODEC = Suppliers.memoize(() -> RecordCodecBuilder.create(inst -> codecStart(inst)
|
||||
private static class MultiplyDropsModifier extends LootModifier {
|
||||
public static final Supplier<Codec<MultiplyDropsModifier>> CODEC = Suppliers.memoize(() -> RecordCodecBuilder.create(inst -> codecStart(inst)
|
||||
.and(ExtraCodecs.POSITIVE_INT.optionalFieldOf("multiplication_factor", 2).forGetter(m -> m.multiplicationFactor))
|
||||
.apply(inst, DungeonLootEnhancerModifier::new)
|
||||
.apply(inst, MultiplyDropsModifier::new)
|
||||
));
|
||||
|
||||
private final int multiplicationFactor;
|
||||
|
||||
public DungeonLootEnhancerModifier(final LootItemCondition[] conditionsIn, final int multiplicationFactor) {
|
||||
public MultiplyDropsModifier(final LootItemCondition[] conditionsIn, final int multiplicationFactor) {
|
||||
super(conditionsIn);
|
||||
this.multiplicationFactor = multiplicationFactor;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user