-
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.
- Loading branch information
1 parent
388adf7
commit 38fd06f
Showing
13 changed files
with
169 additions
and
84 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"type": "tconstruct:loot", | ||
"enchantment": { | ||
"name": "minecraft:fortune", | ||
"level": 1 | ||
}, | ||
"single_level": false | ||
} |
5 changes: 5 additions & 0 deletions
5
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "tconstruct:loot", | ||
"looting": 1, | ||
"single_level": false | ||
} |
8 changes: 8 additions & 0 deletions
8
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"type": "tconstruct:loot", | ||
"enchantment": { | ||
"name": "minecraft:silk_touch", | ||
"level": 1 | ||
}, | ||
"single_level": true | ||
} |
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
126 changes: 126 additions & 0 deletions
126
src/main/java/slimeknights/tconstruct/library/modifiers/dynamic/LootModifier.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,126 @@ | ||
package slimeknights.tconstruct.library.modifiers.dynamic; | ||
|
||
import com.google.gson.JsonObject; | ||
import lombok.RequiredArgsConstructor; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.util.GsonHelper; | ||
import net.minecraft.world.damagesource.DamageSource; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader; | ||
import slimeknights.tconstruct.library.modifiers.Modifier; | ||
import slimeknights.tconstruct.library.modifiers.hooks.IArmorLootModifier; | ||
import slimeknights.tconstruct.library.tools.context.ToolHarvestContext; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
import slimeknights.tconstruct.library.utils.JsonUtils; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Objects; | ||
import java.util.function.BiConsumer; | ||
|
||
/** Modifier to boost loot, from mobs or blocks */ | ||
@RequiredArgsConstructor | ||
public class LootModifier extends Modifier implements IArmorLootModifier { | ||
@Nullable | ||
private final Enchantment enchantment; | ||
private final int enchantmentLevel; | ||
private final int lootingLevel; | ||
private final boolean singleLevel; | ||
|
||
public LootModifier(Enchantment enchantment, int level, boolean singleLevel) { | ||
this(enchantment, level, 0, singleLevel); | ||
} | ||
|
||
public LootModifier(int lootingLevel, boolean singleLevel) { | ||
this(null, 0, lootingLevel, singleLevel); | ||
} | ||
|
||
@Override | ||
public Component getDisplayName(int level) { | ||
if (singleLevel && level == 1) { | ||
return getDisplayName(); | ||
} | ||
return super.getDisplayName(level); | ||
} | ||
|
||
@Override | ||
public int getLootingValue(IToolStackView tool, int level, LivingEntity holder, Entity target, @org.jetbrains.annotations.Nullable DamageSource damageSource, int looting) { | ||
return looting + (this.lootingLevel * level); | ||
} | ||
|
||
@Override | ||
public void applyHarvestEnchantments(IToolStackView tool, int level, ToolHarvestContext context, BiConsumer<Enchantment,Integer> consumer) { | ||
if (enchantment != null && enchantmentLevel > 0) { | ||
consumer.accept(enchantment, enchantmentLevel * level); | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T> T getModule(Class<T> type) { | ||
return tryModuleMatch(type, IArmorLootModifier.class, this); | ||
} | ||
|
||
@Override | ||
public IGenericLoader<? extends Modifier> getLoader() { | ||
return LOADER; | ||
} | ||
|
||
/** Loader for this modifier */ | ||
public static final IGenericLoader<LootModifier> LOADER = new IGenericLoader<>() { | ||
@Override | ||
public LootModifier deserialize(JsonObject json) { | ||
Enchantment enchantment = null; | ||
int enchantmentLevel = 0; | ||
if (json.has("enchantment")) { | ||
JsonObject enchantmentJson = GsonHelper.getAsJsonObject(json, "enchantment"); | ||
enchantment = JsonUtils.getAsEntry(ForgeRegistries.ENCHANTMENTS, enchantmentJson, "name"); | ||
enchantmentLevel = GsonHelper.getAsInt(enchantmentJson, "level"); | ||
} | ||
int looting = GsonHelper.getAsInt(json, "looting", 0); | ||
boolean singleLevel = GsonHelper.getAsBoolean(json, "single_level", false); | ||
return new LootModifier(enchantment, enchantmentLevel, looting, singleLevel); | ||
} | ||
|
||
@Override | ||
public void serialize(LootModifier object, JsonObject json) { | ||
if (object.enchantmentLevel > 0 && object.enchantment != null) { | ||
JsonObject enchantment = new JsonObject(); | ||
enchantment.addProperty("name", Objects.requireNonNull(object.enchantment.getRegistryName()).toString()); | ||
enchantment.addProperty("level", object.enchantmentLevel); | ||
json.add("enchantment", enchantment); | ||
} | ||
if (object.lootingLevel > 0) { | ||
json.addProperty("looting", object.lootingLevel); | ||
} | ||
json.addProperty("single_level", object.singleLevel); | ||
} | ||
|
||
@Override | ||
public LootModifier fromNetwork(FriendlyByteBuf buffer) { | ||
int enchantmentLevel = buffer.readVarInt(); | ||
Enchantment enchantment = null; | ||
if (enchantmentLevel > 0) { | ||
enchantment = buffer.readRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS); | ||
} | ||
int lootingLevel = buffer.readVarInt(); | ||
boolean singleLevel = buffer.readBoolean(); | ||
return new LootModifier(enchantment, enchantmentLevel, lootingLevel, singleLevel); | ||
} | ||
|
||
@Override | ||
public void toNetwork(LootModifier object, FriendlyByteBuf buffer) { | ||
if (object.enchantmentLevel > 0 && object.enchantment != null) { | ||
buffer.writeVarInt(object.enchantmentLevel); | ||
buffer.writeRegistryIdUnsafe(ForgeRegistries.ENCHANTMENTS, object.enchantment); | ||
} else { | ||
buffer.writeVarInt(0); | ||
} | ||
buffer.writeVarInt(object.lootingLevel); | ||
buffer.writeBoolean(object.singleLevel); | ||
} | ||
}; | ||
} |
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
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
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
24 changes: 0 additions & 24 deletions
24
src/main/java/slimeknights/tconstruct/tools/modifiers/ability/tool/SilkyModifier.java
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/main/java/slimeknights/tconstruct/tools/modifiers/upgrades/harvest/FortuneModifier.java
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/main/java/slimeknights/tconstruct/tools/modifiers/upgrades/melee/LootingModifier.java
This file was deleted.
Oops, something went wrong.