-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate loot modifier to composable modifiers
- Loading branch information
1 parent
a584ec2
commit 64bfa3d
Showing
9 changed files
with
166 additions
and
24 deletions.
There are no files selected for viewing
13 changes: 8 additions & 5 deletions
13
src/generated/resources/data/tconstruct/tinkering/modifiers/fortune.json
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
{ | ||
"type": "tconstruct:loot", | ||
"type": "tconstruct:composable", | ||
"level_display": "tconstruct:default", | ||
"enchantment": { | ||
"name": "minecraft:fortune", | ||
"level": 1 | ||
} | ||
"modules": [ | ||
{ | ||
"type": "tconstruct:harvest_enchantment", | ||
"name": "minecraft:fortune", | ||
"level": 1 | ||
} | ||
] | ||
} |
9 changes: 7 additions & 2 deletions
9
src/generated/resources/data/tconstruct/tinkering/modifiers/looting.json
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"type": "tconstruct:loot", | ||
"type": "tconstruct:composable", | ||
"level_display": "tconstruct:default", | ||
"looting": 1 | ||
"modules": [ | ||
{ | ||
"type": "tconstruct:looting", | ||
"level": 1 | ||
} | ||
] | ||
} |
18 changes: 12 additions & 6 deletions
18
src/generated/resources/data/tconstruct/tinkering/modifiers/luck.json
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
{ | ||
"type": "tconstruct:loot", | ||
"type": "tconstruct:composable", | ||
"level_display": { | ||
"type": "tconstruct:unique", | ||
"unique_until": 3 | ||
}, | ||
"enchantment": { | ||
"name": "minecraft:fortune", | ||
"level": 1 | ||
}, | ||
"looting": 1 | ||
"modules": [ | ||
{ | ||
"type": "tconstruct:harvest_enchantment", | ||
"name": "minecraft:fortune", | ||
"level": 1 | ||
}, | ||
{ | ||
"type": "tconstruct:looting", | ||
"level": 1 | ||
} | ||
] | ||
} |
13 changes: 8 additions & 5 deletions
13
src/generated/resources/data/tconstruct/tinkering/modifiers/silky.json
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
{ | ||
"type": "tconstruct:loot", | ||
"type": "tconstruct:composable", | ||
"level_display": "tconstruct:no_levels", | ||
"enchantment": { | ||
"name": "minecraft:silk_touch", | ||
"level": 1 | ||
} | ||
"modules": [ | ||
{ | ||
"type": "tconstruct:harvest_enchantment", | ||
"name": "minecraft:silk_touch", | ||
"level": 1 | ||
} | ||
] | ||
} |
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
74 changes: 74 additions & 0 deletions
74
...main/java/slimeknights/tconstruct/library/modifiers/modules/HarvestEnchantmentModule.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,74 @@ | ||
package slimeknights.tconstruct.library.modifiers.modules; | ||
|
||
import com.google.gson.JsonObject; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader; | ||
import slimeknights.mantle.util.JsonHelper; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.modifiers.ModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.TinkerHooks; | ||
import slimeknights.tconstruct.library.modifiers.hook.HarvestEnchantmentsModifierHook; | ||
import slimeknights.tconstruct.library.tools.context.ToolHarvestContext; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
import slimeknights.tconstruct.library.utils.JsonUtils; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* Module that adds an enchantment applied during harvesting. Used for silk touch and fortune. | ||
* Currently, does not support incremental. | ||
*/ | ||
public record HarvestEnchantmentModule(Enchantment enchantment, int level) implements ModifierModule, HarvestEnchantmentsModifierHook { | ||
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.TOOL_HARVEST_ENCHANTMENTS, TinkerHooks.LEGGINGS_HARVEST_ENCHANTMENTS); | ||
|
||
public HarvestEnchantmentModule(Enchantment enchantment) { | ||
this(enchantment, 1); | ||
} | ||
|
||
@Override | ||
public void applyHarvestEnchantments(IToolStackView tool, ModifierEntry modifier, ToolHarvestContext context, BiConsumer<Enchantment,Integer> consumer) { | ||
consumer.accept(enchantment, level * modifier.getLevel()); | ||
} | ||
|
||
@Override | ||
public List<ModifierHook<?>> getDefaultHooks() { | ||
return DEFAULT_HOOKS; | ||
} | ||
|
||
@Override | ||
public IGenericLoader<? extends ModifierModule> getLoader() { | ||
return LOADER; | ||
} | ||
|
||
public static IGenericLoader<HarvestEnchantmentModule> LOADER = new IGenericLoader<>() { | ||
@Override | ||
public HarvestEnchantmentModule deserialize(JsonObject json) { | ||
Enchantment enchantment = JsonHelper.getAsEntry(ForgeRegistries.ENCHANTMENTS, json, "name"); | ||
int level = JsonUtils.getIntMin(json, "level", 1); | ||
return new HarvestEnchantmentModule(enchantment, level); | ||
} | ||
|
||
@Override | ||
public void serialize(HarvestEnchantmentModule object, JsonObject json) { | ||
json.addProperty("name", Objects.requireNonNull(object.enchantment.getRegistryName()).toString()); | ||
json.addProperty("level", object.level); | ||
} | ||
|
||
@Override | ||
public HarvestEnchantmentModule fromNetwork(FriendlyByteBuf buffer) { | ||
Enchantment enchantment = buffer.readRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS); | ||
int level = buffer.readVarInt(); | ||
return new HarvestEnchantmentModule(enchantment, level); | ||
} | ||
|
||
@Override | ||
public void toNetwork(HarvestEnchantmentModule object, FriendlyByteBuf buffer) { | ||
buffer.writeRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS, object.enchantment); | ||
buffer.writeVarInt(object.level); | ||
} | ||
}; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/slimeknights/tconstruct/library/modifiers/modules/LootingModule.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,39 @@ | ||
package slimeknights.tconstruct.library.modifiers.modules; | ||
|
||
import net.minecraft.world.damagesource.DamageSource; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import slimeknights.mantle.data.GenericIntSerializer; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.modifiers.ModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.TinkerHooks; | ||
import slimeknights.tconstruct.library.modifiers.hook.LootingModifierHook; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
/** | ||
* Module for increasing the looting level, used for tools, on pants, and from bows | ||
* Currently, does not support incremental. | ||
*/ | ||
public record LootingModule(int level) implements LootingModifierHook, ModifierModule { | ||
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.TOOL_LOOTING, TinkerHooks.LEGGINGS_LOOTING, TinkerHooks.PROJECTILE_LOOTING); | ||
public static IGenericLoader<LootingModule> LOADER = new GenericIntSerializer<>("level", LootingModule::new, LootingModule::level); | ||
|
||
@Override | ||
public int getLootingValue(IToolStackView tool, ModifierEntry modifier, LivingEntity holder, Entity target, @Nullable DamageSource damageSource, int looting) { | ||
return level * modifier.getLevel(); | ||
} | ||
|
||
@Override | ||
public List<ModifierHook<?>> getDefaultHooks() { | ||
return DEFAULT_HOOKS; | ||
} | ||
|
||
@Override | ||
public IGenericLoader<? extends ModifierModule> getLoader() { | ||
return LOADER; | ||
} | ||
} |
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
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