generated from neoforged/MDK
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrote a global look modifier that I wound up not using -- I'll uncomm…
…ent it if its necessary, but I can't do particles or tool damage with it..
- Loading branch information
1 parent
0acbeca
commit dfc9a25
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...in/java/com/direwolf20/justdirethings/common/items/tools/utils/AutoSmeltLootModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.direwolf20.justdirethings.common.items.tools.utils; | ||
|
||
import com.direwolf20.justdirethings.setup.Registration; | ||
import com.google.common.base.Suppliers; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import net.minecraft.world.SimpleContainer; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.crafting.RecipeType; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.neoforged.neoforge.common.loot.IGlobalLootModifier; | ||
import net.neoforged.neoforge.common.loot.LootModifier; | ||
import net.neoforged.neoforge.items.ItemHandlerHelper; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* An alternate way to smelt drops - I wrote all this, but went back to my old approach. Will re-implement if told its necessary | ||
*/ | ||
public class AutoSmeltLootModifier extends LootModifier { | ||
public static final Supplier<Codec<AutoSmeltLootModifier>> CODEC = Suppliers.memoize(() -> RecordCodecBuilder.create(inst -> codecStart(inst).apply(inst, AutoSmeltLootModifier::new))); | ||
|
||
|
||
public AutoSmeltLootModifier(LootItemCondition[] conditionsIn) { | ||
super(conditionsIn); | ||
} | ||
|
||
@Override | ||
protected ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) { | ||
ItemStack tool = context.getParamOrNull(LootContextParams.TOOL); | ||
if (tool != null && tool.getItem() instanceof ToggleableTool toggleableTool) { | ||
if (toggleableTool.canUseAbility(tool, Ability.SMELTER)) { | ||
ObjectArrayList<ItemStack> ret = new ObjectArrayList<ItemStack>(); | ||
generatedLoot.forEach((stack) -> ret.add(smelt(stack, context))); | ||
return ret; | ||
} | ||
} | ||
return generatedLoot; | ||
} | ||
|
||
private static ItemStack smelt(ItemStack stack, LootContext context) { | ||
return context.getLevel().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SimpleContainer(stack), context.getLevel()) | ||
.map(smeltingRecipe -> smeltingRecipe.value().getResultItem(context.getLevel().registryAccess())) | ||
.filter(itemStack -> !itemStack.isEmpty()) | ||
.map(itemStack -> ItemHandlerHelper.copyStackWithSize(itemStack, stack.getCount() * itemStack.getCount())) | ||
.orElse(stack); | ||
} | ||
|
||
@Override | ||
public Codec<? extends IGlobalLootModifier> codec() { | ||
return Registration.AUTO_SMELT_LOOT_MODIFIER.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/com/direwolf20/justdirethings/datagen/JustDireLootProviders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.direwolf20.justdirethings.datagen; | ||
|
||
import com.direwolf20.justdirethings.JustDireThings; | ||
import com.direwolf20.justdirethings.common.items.tools.utils.AutoSmeltLootModifier; | ||
import net.minecraft.data.PackOutput; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.neoforged.neoforge.common.data.GlobalLootModifierProvider; | ||
|
||
/** | ||
* An alternate way to smelt drops - I wrote all this, but went back to my old approach. Will re-implement if told its necessary | ||
*/ | ||
public class JustDireLootProviders extends GlobalLootModifierProvider { | ||
|
||
public JustDireLootProviders(PackOutput output) { | ||
super(output, JustDireThings.MODID); | ||
} | ||
|
||
@Override | ||
protected void start() { | ||
this.add("auto_smelt", new AutoSmeltLootModifier(new LootItemCondition[]{})); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/data/forge/loot_modifiers/global_loot_modifiers.old
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"replace": false, | ||
"entries": [ | ||
"justdirethings:auto_smelt" | ||
] | ||
} |