Allow pack makers to blacklist blocks from Fortune-enchanted hammers
This commit is contained in:
parent
9b8363e9e4
commit
95a79811e6
|
|
@ -1,7 +1,7 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
id 'idea'
|
id 'idea'
|
||||||
id 'net.neoforged.moddev' version '2.0.71'
|
id 'net.neoforged.moddev' version '2.0.107'
|
||||||
id("com.modrinth.minotaur") version '2.+'
|
id("com.modrinth.minotaur") version '2.+'
|
||||||
id("com.matthewprenger.cursegradle") version '1.4.0'
|
id("com.matthewprenger.cursegradle") version '1.4.0'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
## Ex Deorum 3.9
|
||||||
|
- Add `#exdeorum:hammer_fortune_blacklist` and `#exdeorum:compressed_hammer_fortune_blacklist` item tags, allowing pack makers to prevent Fortune from affecting a block's hammer or compressed hammer drops
|
||||||
|
|
||||||
## Ex Deorum 3.8
|
## Ex Deorum 3.8
|
||||||
- Fix memory leak in VisualUpdateTracker (#153)
|
- Fix memory leak in VisualUpdateTracker (#153)
|
||||||
- Added Hungarian translation (#147)
|
- Added Hungarian translation (#147)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// 1.21.1 2025-06-03T14:16:11.5378401 Tags for minecraft:item mod id exdeorum
|
// 1.21.1 2025-09-01T13:22:27.1441593 Tags for minecraft:item mod id exdeorum
|
||||||
6c72957356b1d59a27be736fa1da54a5a9795ef7 data/exdeorum/tags/item/barrels.json
|
6c72957356b1d59a27be736fa1da54a5a9795ef7 data/exdeorum/tags/item/barrels.json
|
||||||
6afa16b45f76c0defa1675d07586e2c6e6b0be69 data/exdeorum/tags/item/compressed/andesite.json
|
6afa16b45f76c0defa1675d07586e2c6e6b0be69 data/exdeorum/tags/item/compressed/andesite.json
|
||||||
31b46613766e4cdc53196850495ab1019f61cb48 data/exdeorum/tags/item/compressed/blackstone.json
|
31b46613766e4cdc53196850495ab1019f61cb48 data/exdeorum/tags/item/compressed/blackstone.json
|
||||||
|
|
@ -22,9 +22,11 @@ fc279d9fa656ad00c5504b3f313586ca34fc4477 data/exdeorum/tags/item/compressed/red_
|
||||||
2de46f3e2e91a340f1b71ea5b600f8383a7ce875 data/exdeorum/tags/item/compressed/sands.json
|
2de46f3e2e91a340f1b71ea5b600f8383a7ce875 data/exdeorum/tags/item/compressed/sands.json
|
||||||
874b33131f557d077ab366fc6506c41369151a40 data/exdeorum/tags/item/compressed/soul_sand.json
|
874b33131f557d077ab366fc6506c41369151a40 data/exdeorum/tags/item/compressed/soul_sand.json
|
||||||
dad00c75d1a0b74a2f843bead336ee278e9cecba data/exdeorum/tags/item/compressed_hammers.json
|
dad00c75d1a0b74a2f843bead336ee278e9cecba data/exdeorum/tags/item/compressed_hammers.json
|
||||||
|
35133e95f1c8fdd7a1c21afcc231fc0bffefb9a8 data/exdeorum/tags/item/compressed_hammer_fortune_blacklist.json
|
||||||
5feb54ce68fa657af5ce696f75b8c7a6d04cc7a7 data/exdeorum/tags/item/crooks.json
|
5feb54ce68fa657af5ce696f75b8c7a6d04cc7a7 data/exdeorum/tags/item/crooks.json
|
||||||
74eefeb986d633d26ad42202c4a6b5e71463c425 data/exdeorum/tags/item/end_cake_materials.json
|
74eefeb986d633d26ad42202c4a6b5e71463c425 data/exdeorum/tags/item/end_cake_materials.json
|
||||||
be46bf2abe731d5ee5bd15ce72f222b2b9a49385 data/exdeorum/tags/item/hammers.json
|
be46bf2abe731d5ee5bd15ce72f222b2b9a49385 data/exdeorum/tags/item/hammers.json
|
||||||
|
35133e95f1c8fdd7a1c21afcc231fc0bffefb9a8 data/exdeorum/tags/item/hammer_fortune_blacklist.json
|
||||||
008b4a382f07b9c0f9a07c78bedb949b4400e011 data/exdeorum/tags/item/ore_chunks.json
|
008b4a382f07b9c0f9a07c78bedb949b4400e011 data/exdeorum/tags/item/ore_chunks.json
|
||||||
b90bd3c642e69b9e800c58a9f8f53e369652e6ba data/exdeorum/tags/item/pebbles.json
|
b90bd3c642e69b9e800c58a9f8f53e369652e6ba data/exdeorum/tags/item/pebbles.json
|
||||||
10f2167f7a9472e5df6870bad71b95869fc64b9a data/exdeorum/tags/item/random_shard_drops.json
|
10f2167f7a9472e5df6870bad71b95869fc64b9a data/exdeorum/tags/item/random_shard_drops.json
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"values": []
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"values": []
|
||||||
|
}
|
||||||
|
|
@ -152,7 +152,9 @@ public class MechanicalHammerBlockEntity extends AbstractMachineBlockEntity<Mech
|
||||||
@SuppressWarnings("DataFlowIssue")
|
@SuppressWarnings("DataFlowIssue")
|
||||||
LootContext ctx = RecipeUtil.emptyLootContext((ServerLevel) this.level);
|
LootContext ctx = RecipeUtil.emptyLootContext((ServerLevel) this.level);
|
||||||
var resultCount = recipe.resultAmount.getInt(ctx);
|
var resultCount = recipe.resultAmount.getInt(ctx);
|
||||||
resultCount += HammerLootModifier.calculateFortuneBonus(this.level.registryAccess(), this.inventory.getStackInSlot(HAMMER_SLOT), ctx.getRandom(), resultCount == 0);
|
if (!input.is(EItemTags.HAMMER_FORTUNE_BLACKLIST)) {
|
||||||
|
resultCount += HammerLootModifier.calculateFortuneBonus(this.level.registryAccess(), this.inventory.getStackInSlot(HAMMER_SLOT), ctx.getRandom(), resultCount == 0);
|
||||||
|
}
|
||||||
var output = this.inventory.getStackInSlot(OUTPUT_SLOT);
|
var output = this.inventory.getStackInSlot(OUTPUT_SLOT);
|
||||||
if (output.isEmpty()) {
|
if (output.isEmpty()) {
|
||||||
this.inventory.setStackInSlot(OUTPUT_SLOT, recipe.result.copyWithCount(resultCount));
|
this.inventory.setStackInSlot(OUTPUT_SLOT, recipe.result.copyWithCount(resultCount));
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,10 @@ class ModTags {
|
||||||
tags.tag(EItemTags.STONE_BARRELS).add(DefaultMaterials.STONE_BARREL.getItem(), DefaultMaterials.CRYSTALLIZED_BARREL.getItem());
|
tags.tag(EItemTags.STONE_BARRELS).add(DefaultMaterials.STONE_BARREL.getItem(), DefaultMaterials.CRYSTALLIZED_BARREL.getItem());
|
||||||
tags.tag(EItemTags.BARRELS).addTags(EItemTags.WOODEN_BARRELS, EItemTags.STONE_BARRELS);
|
tags.tag(EItemTags.BARRELS).addTags(EItemTags.WOODEN_BARRELS, EItemTags.STONE_BARRELS);
|
||||||
|
|
||||||
|
// empty by default; pack makers can add items they don't want affected by Fortune-enchanted hammers
|
||||||
|
tags.tag(EItemTags.HAMMER_FORTUNE_BLACKLIST);
|
||||||
|
tags.tag(EItemTags.COMPRESSED_HAMMER_FORTUNE_BLACKLIST);
|
||||||
|
|
||||||
tags.tag(EItemTags.RANDOM_SHERD_DROPS).addTag(ItemTags.DECORATED_POT_SHERDS);
|
tags.tag(EItemTags.RANDOM_SHERD_DROPS).addTag(ItemTags.DECORATED_POT_SHERDS);
|
||||||
|
|
||||||
tags.tag(EItemTags.RANDOM_TRIM_DROPS).add(
|
tags.tag(EItemTags.RANDOM_TRIM_DROPS).add(
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,13 @@ import net.neoforged.neoforge.common.loot.LootModifier;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
||||||
import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe;
|
import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe;
|
||||||
|
import thedarkcolour.exdeorum.tag.EItemTags;
|
||||||
|
|
||||||
public class CompressedHammerLootModifier extends HammerLootModifier {
|
public class CompressedHammerLootModifier extends HammerLootModifier {
|
||||||
public static final MapCodec<CompressedHammerLootModifier> CODEC = RecordCodecBuilder.mapCodec(inst -> LootModifier.codecStart(inst).apply(inst, CompressedHammerLootModifier::new));
|
public static final MapCodec<CompressedHammerLootModifier> CODEC = RecordCodecBuilder.mapCodec(inst -> LootModifier.codecStart(inst).apply(inst, CompressedHammerLootModifier::new));
|
||||||
|
|
||||||
public CompressedHammerLootModifier(LootItemCondition[] conditionsIn) {
|
public CompressedHammerLootModifier(LootItemCondition[] conditionsIn) {
|
||||||
super(conditionsIn);
|
super(conditionsIn, EItemTags.COMPRESSED_HAMMER_FORTUNE_BLACKLIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
@ -36,42 +37,57 @@ import net.neoforged.neoforge.common.loot.LootModifier;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
import thedarkcolour.exdeorum.recipe.RecipeUtil;
|
||||||
import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe;
|
import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe;
|
||||||
|
import thedarkcolour.exdeorum.tag.EItemTags;
|
||||||
|
|
||||||
public class HammerLootModifier extends LootModifier {
|
public class HammerLootModifier extends LootModifier {
|
||||||
public static final MapCodec<HammerLootModifier> CODEC = RecordCodecBuilder.mapCodec(inst -> LootModifier.codecStart(inst).apply(inst, HammerLootModifier::new));
|
public static final MapCodec<HammerLootModifier> CODEC = RecordCodecBuilder.mapCodec(inst -> LootModifier.codecStart(inst).apply(inst, HammerLootModifier::new));
|
||||||
|
|
||||||
|
private final TagKey<Item> fortuneBlacklistTag;
|
||||||
|
|
||||||
public HammerLootModifier(LootItemCondition[] conditionsIn) {
|
public HammerLootModifier(LootItemCondition[] conditionsIn) {
|
||||||
super(conditionsIn);
|
super(conditionsIn);
|
||||||
|
|
||||||
|
this.fortuneBlacklistTag = EItemTags.HAMMER_FORTUNE_BLACKLIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HammerLootModifier(LootItemCondition[] conditionsIn, TagKey<Item> fortuneBlacklistTag) {
|
||||||
|
super(conditionsIn);
|
||||||
|
|
||||||
|
this.fortuneBlacklistTag = fortuneBlacklistTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
protected ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
||||||
var state = context.getParamOrNull(LootContextParams.BLOCK_STATE);
|
var state = context.getParamOrNull(LootContextParams.BLOCK_STATE);
|
||||||
|
|
||||||
if (state != null) {
|
if (state == null) {
|
||||||
var itemForm = state.getBlock().asItem();
|
return generatedLoot;
|
||||||
if (itemForm != Items.AIR) {
|
|
||||||
var recipe = getRecipe(itemForm);
|
|
||||||
|
|
||||||
if (recipe != null) {
|
|
||||||
ObjectArrayList<ItemStack> newLoot = new ObjectArrayList<>();
|
|
||||||
var resultAmount = recipe.resultAmount.getInt(context);
|
|
||||||
|
|
||||||
// fortune handling; more likely to boost drops if there are none to begin with
|
|
||||||
if (context.hasParam(LootContextParams.TOOL)) {
|
|
||||||
var hammer = context.getParam(LootContextParams.TOOL);
|
|
||||||
resultAmount += calculateFortuneBonus(context.getLevel().registryAccess(), hammer, context.getRandom(), resultAmount == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resultAmount > 0) {
|
|
||||||
newLoot.add(recipe.result.copyWithCount(resultAmount));
|
|
||||||
}
|
|
||||||
return newLoot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return generatedLoot;
|
var itemForm = state.getBlock().asItem();
|
||||||
|
if (itemForm == Items.AIR) {
|
||||||
|
return generatedLoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
var recipe = getRecipe(itemForm);
|
||||||
|
if (recipe == null) {
|
||||||
|
return generatedLoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectArrayList<ItemStack> newLoot = new ObjectArrayList<>();
|
||||||
|
var resultAmount = recipe.resultAmount.getInt(context);
|
||||||
|
|
||||||
|
if (!itemForm.builtInRegistryHolder().is(this.fortuneBlacklistTag) && context.hasParam(LootContextParams.TOOL)) {
|
||||||
|
var hammer = context.getParam(LootContextParams.TOOL);
|
||||||
|
// fortune handling; more likely to boost drops if there are none to begin with
|
||||||
|
resultAmount += calculateFortuneBonus(context.getLevel().registryAccess(), hammer, context.getRandom(), resultAmount == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultAmount > 0) {
|
||||||
|
newLoot.add(recipe.result.copyWithCount(resultAmount));
|
||||||
|
}
|
||||||
|
|
||||||
|
return newLoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ public class EItemTags {
|
||||||
public static final TagKey<Item> ORE_CHUNKS = tag("ore_chunks");
|
public static final TagKey<Item> ORE_CHUNKS = tag("ore_chunks");
|
||||||
public static final TagKey<Item> END_CAKE_MATERIAL = tag("end_cake_materials");
|
public static final TagKey<Item> END_CAKE_MATERIAL = tag("end_cake_materials");
|
||||||
|
|
||||||
|
public static final TagKey<Item> HAMMER_FORTUNE_BLACKLIST = tag("hammer_fortune_blacklist");
|
||||||
|
public static final TagKey<Item> COMPRESSED_HAMMER_FORTUNE_BLACKLIST = tag("compressed_hammer_fortune_blacklist");
|
||||||
|
|
||||||
public static final TagKey<Item> RANDOM_SHERD_DROPS = tag("random_shard_drops");
|
public static final TagKey<Item> RANDOM_SHERD_DROPS = tag("random_shard_drops");
|
||||||
public static final TagKey<Item> RANDOM_TRIM_DROPS = tag("random_trim_drops");
|
public static final TagKey<Item> RANDOM_TRIM_DROPS = tag("random_trim_drops");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user