Skip to content

Commit

Permalink
fixed resonarium armor enchanting
Browse files Browse the repository at this point in the history
  • Loading branch information
NewJumper committed Jan 10, 2025
1 parent 031fcf3 commit 5da0976
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 87 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.debug=false
minecraft_version=1.21.1
minecraft_version_range=[1.21.1,1.21.2)
neo_version=21.1.93
neo_version_range=[21.1.0,)
neo_version_range=[21.1.4,)
loader_version_range=[4,)
neogradle.subsystems.parchment.minecraftVersion=1.21.1
neogradle.subsystems.parchment.mappingsVersion=2024.11.17
Expand Down
86 changes: 0 additions & 86 deletions src/main/java/com/kyanite/deeperdarker/DeeperDarkerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.kyanite.deeperdarker.content.blocks.CrystallizedAmberBlock;
import com.kyanite.deeperdarker.content.blocks.entity.CrystallizedAmberBlockEntity;
import com.kyanite.deeperdarker.content.blocks.vegetation.IceLilyBlock;
import com.kyanite.deeperdarker.content.items.ResonariumArmorItem;
import com.kyanite.deeperdarker.content.items.SculkTransmitterItem;
import com.kyanite.deeperdarker.content.items.SoulElytraItem;
import com.kyanite.deeperdarker.network.SoulElytraBoostPacket;
Expand All @@ -17,7 +16,6 @@
import com.kyanite.deeperdarker.util.DDArmorMaterials;
import com.kyanite.deeperdarker.util.DDTags;
import com.kyanite.deeperdarker.world.otherside.OthersideDimension;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.client.model.BoatModel;
import net.minecraft.client.model.ChestBoatModel;
import net.minecraft.client.renderer.DimensionSpecialEffects;
Expand All @@ -30,7 +28,6 @@
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
Expand All @@ -41,12 +38,10 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.util.RandomSource;
import net.minecraft.util.StringUtil;
import net.minecraft.world.Difficulty;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
Expand All @@ -55,9 +50,7 @@
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
Expand All @@ -70,7 +63,6 @@
import net.neoforged.neoforge.client.event.InputEvent;
import net.neoforged.neoforge.client.event.RegisterDimensionSpecialEffectsEvent;
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
import net.neoforged.neoforge.event.AnvilUpdateEvent;
import net.neoforged.neoforge.event.brewing.RegisterBrewingRecipesEvent;
import net.neoforged.neoforge.event.entity.living.ArmorHurtEvent;
import net.neoforged.neoforge.event.entity.living.LivingDamageEvent;
Expand Down Expand Up @@ -187,84 +179,6 @@ public static void equipmentChangeEvent(final LivingEquipmentChangeEvent event)
if(event.getEntity() instanceof ServerPlayer player) PacketDistributor.sendToPlayer(player, new SoulElytraClientPacket(true));
}

@SubscribeEvent
public static void anvilEvent(final AnvilUpdateEvent event) {
ItemStack input = event.getLeft();
ItemStack addition = event.getRight();

if(!(input.getItem() instanceof ResonariumArmorItem)) return;
if(addition.is(DDItems.RESONARIUM)) {
ItemStack output = input.copy();
int diff = Math.min(output.getDamageValue(), output.getMaxDamage() / 4);
int cost = 0;
for(int i = 0; diff > 0 && i < addition.getCount(); i++) {
int damage = output.getDamageValue() - diff;
output.setDamageValue(damage);
diff = Math.min(damage, output.getMaxDamage() / 4);
cost++;
}

event.setOutput(output);
event.setCost(nameCost(event.getName(), input, cost, output));
return;
}
if(!addition.is(Items.ENCHANTED_BOOK)) return;
boolean client = event.getPlayer().level().isClientSide;

ItemEnchantments inputEnchants = EnchantmentHelper.getEnchantmentsForCrafting(input);
ItemEnchantments bookEnchants = EnchantmentHelper.getEnchantmentsForCrafting(addition);
ItemEnchantments.Mutable finalEnchants = new ItemEnchantments.Mutable(inputEnchants);
int cost = 0;

boolean noChange = true;
for(Object2IntMap.Entry<Holder<Enchantment>> entry : bookEnchants.entrySet()) {
Holder<Enchantment> enchantment = entry.getKey();
Enchantment enchant = enchantment.value();
int level = entry.getIntValue();
int existingLevel = inputEnchants.getLevel(enchantment);
level = level == existingLevel ? level + 1 : Math.max(level, existingLevel);
level = Math.min(level, enchant.getMaxLevel());

if(enchant.canEnchant(input) && !enchantment.is(DDTags.Misc.RESONARIUM_EXCLUDES)) {
finalEnchants.set(enchantment, level);
cost += enchant.getAnvilCost() * level;
noChange = false;
}
}

if(noChange) {
event.setCanceled(true);
return;
}

int inputRepair = input.getOrDefault(DataComponents.REPAIR_COST, 0);
int additionRepair = addition.getOrDefault(DataComponents.REPAIR_COST, 0);
int newRepairCost = AnvilMenu.calculateIncreasedRepairCost(Math.max(inputRepair, additionRepair));
cost = Math.clamp(cost + inputRepair + additionRepair, 0, Integer.MAX_VALUE);

ItemStack output = input.copy();
output.set(DataComponents.REPAIR_COST, newRepairCost);
EnchantmentHelper.setEnchantments(output, finalEnchants.toImmutable());

cost = nameCost(event.getName(), input, cost, output);

event.setOutput(output);
event.setCost(cost / 2);
}

private static int nameCost(String name, ItemStack input, int cost, ItemStack output) {
if(name != null && !StringUtil.isBlank(name)) {
if(!name.equals(input.getHoverName().getString())) {
cost++;
output.set(DataComponents.CUSTOM_NAME, Component.literal(name));
}
} else if(input.has(DataComponents.CUSTOM_NAME)) {
cost++;
output.remove(DataComponents.CUSTOM_NAME);
}
return cost;
}

@EventBusSubscriber(modid = DeeperDarker.MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientEvents {
@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package com.kyanite.deeperdarker.content.items;

import com.kyanite.deeperdarker.util.DDTags;
import net.minecraft.core.Holder;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import org.jetbrains.annotations.NotNull;

public class ResonariumArmorItem extends ArmorItem {
public ResonariumArmorItem(Holder<ArmorMaterial> material, Type type, Properties properties) {
super(material, type, properties);
}

@Override
public boolean supportsEnchantment(@NotNull ItemStack stack, @NotNull Holder<Enchantment> enchantment) {
return !enchantment.is(DDTags.Misc.RESONARIUM_EXCLUDES);
}

@Override
public boolean isEnchantable(@NotNull ItemStack stack) {
return false;
Expand Down

0 comments on commit 5da0976

Please sign in to comment.