From 214833790fa33e1e458bd43ac5c5819c49e8734a Mon Sep 17 00:00:00 2001 From: KeyLime17 Date: Thu, 22 Aug 2024 16:24:07 -0400 Subject: [PATCH 1/6] Began rework on some stuff, however onLivingHurt event doesnt apply the additional damage --- .../cinder_loe/CinderEventHandler.java | 111 ++++++++++++++++-- .../cinder_loe/client/render/RenderNex.java | 3 +- .../LOTREnchantmentWeakProtectionRanged.java | 51 ++++++++ .../mixins/MixinLOTREnchantment.java | 41 +++++++ .../overrides/MixinLOTRHiredNPCInfo.java | 95 +++++++++++++++ .../overrides/MixinLOTRReplacedMethods.java | 25 ++++ .../assets/cinder_loe/lang/en_US.lang | 5 + src/main/resources/mixins.cinder_loe.json | 3 + 8 files changed, 326 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java create mode 100644 src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java create mode 100644 src/main/java/com/zivilon/cinder_loe/mixins/overrides/MixinLOTRHiredNPCInfo.java create mode 100644 src/main/java/com/zivilon/cinder_loe/mixins/overrides/MixinLOTRReplacedMethods.java diff --git a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java index ef588f6..5443109 100644 --- a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java +++ b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java @@ -7,14 +7,20 @@ import cpw.mods.fml.common.IFuelHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.registry.GameRegistry; import lotr.common.LOTRMod; +import lotr.common.enchant.LOTREnchantment; +import lotr.common.enchant.LOTREnchantmentHelper; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingHurtEvent; @@ -24,22 +30,43 @@ import java.util.Random; public class CinderEventHandler implements IFuelHandler { private static final Random random = new Random(); public CinderEventHandler() { - FMLCommonHandler.instance().bus().register((Object)this); - MinecraftForge.EVENT_BUS.register((Object)this); - MinecraftForge.TERRAIN_GEN_BUS.register((Object)this); - GameRegistry.registerFuelHandler((IFuelHandler)this); + FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.TERRAIN_GEN_BUS.register(this); + GameRegistry.registerFuelHandler(this); } @SubscribeEvent public void onLivingHurt(LivingHurtEvent event) { EntityLivingBase entity = event.entityLiving; - EntityLivingBase attacker = event.source.getEntity() instanceof EntityLivingBase ? (EntityLivingBase)event.source.getEntity() : null; + EntityLivingBase attacker = event.source.getEntity() instanceof EntityLivingBase ? (EntityLivingBase) event.source.getEntity() : null; World world = entity.worldObj; + // Negative Arrow Protection Handler + if (event.source.isProjectile() && entity instanceof EntityPlayerMP) { + EntityPlayerMP player = (EntityPlayerMP) entity; + for (int i = 0; i < 4; i++) { + ItemStack armor = entity.getEquipmentInSlot(i + 1); + + if (armor != null) { + LOTREnchantment enchantment = LOTREnchantment.getEnchantmentByName("protectRangedWeak1"); + if (LOTREnchantmentHelper.hasEnchant(armor, enchantment)) { + float level = enchantment.getValueModifier(); + if (level > 0) { + float additionalDamage = level * 0.2f; // 20% more damage per level + event.ammount += additionalDamage; + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Your armor has received a negative modifier!")); + } + } + } + } + } + + // Broken Halo Event handler if (attacker != null && event.source.getSourceOfDamage() == attacker) { ItemStack helmet = entity.getEquipmentInSlot(4); if (helmet != null && helmet.getItem() instanceof BrokenHalo) { - if (random.nextDouble() <= 0.25 ) { + if (random.nextDouble() <= 0.25) { // Summon Corrupt Civilian NPC CorruptMan spawnedEntity = new CorruptMan(world); spawnedEntity.copyLocationAndAnglesFrom(attacker); @@ -59,8 +86,78 @@ public class CinderEventHandler implements IFuelHandler { } } } + // Smithing Rework event handler + if (entity != null && entity instanceof EntityPlayerMP) { + EntityPlayerMP player = (EntityPlayerMP) entity; + for (int i = 0; i < 4; ++i) { + ItemStack armor = entity.getEquipmentInSlot(i + 1); + if (armor != null && armor.isItemStackDamageable()) { + float durabilityPercent = (float) (armor.getMaxDamage() - armor.getItemDamage()) / armor.getMaxDamage(); + if (durabilityPercent <= 0.6) { + if (random.nextDouble() <= 1.02) { + addNegativeModifier(armor); + sendNegativeModifierMessage(player); + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + } + if (durabilityPercent <= 0.50) { + if (random.nextDouble() <= 1.05) { + addNegativeModifier(armor); + sendNegativeModifierMessage(player); + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + } + if (durabilityPercent <= 0.4) { + if (random.nextDouble() <= 1.1) { + addNegativeModifier(armor); + sendNegativeModifierMessage(player); + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + } + } + } + } + } + } + } + } + private void sendNegativeModifierMessage(EntityPlayerMP player) { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Your armor has received a negative modifier!")); + } + + private void playNegativeModifierSound(World world, double x, double y, double z) { + world.playSoundEffect(x, y, z, "mob.irongolem.hit", 1.0F, 2.0F); + } + private void addNegativeModifier(ItemStack armor) { + NBTTagCompound tag = armor.getTagCompound(); + if (tag == null) { + tag = new NBTTagCompound(); + armor.setTagCompound(tag); + } + + if (!tag.hasKey("LOTREnch")) { + tag.setTag("LOTREnch", new NBTTagList()); + } + + NBTTagList enchList = tag.getTagList("LOTREnch", 8); // 8 is the type for strings + + String[] negativeArmorModifiers = {"protectWeak1", "protectWeak2"}; + String newArmorModifier = negativeArmorModifiers[random.nextInt(negativeArmorModifiers.length)]; + + boolean hasModifier = false; + for (int i = 0; i < enchList.tagCount(); i++) { + String ench = enchList.getStringTagAt(i); + if (ench.equals(newArmorModifier)) { + hasModifier = true; + break; + } + } + + if (!hasModifier) { + enchList.appendTag(new NBTTagString(newArmorModifier)); + } + + tag.setTag("LOTREnch", enchList); } + private ItemStack getRandomWeapon() { Item[] weapons = new Item[]{LOTRMod.blacksmithHammer, LOTRMod.daggerIron, LOTRMod.dunlendingTrident, LOTRMod.battleaxeBronze, CinderLoE.cleaver}; return new ItemStack(weapons[random.nextInt(weapons.length)]); diff --git a/src/main/java/com/zivilon/cinder_loe/client/render/RenderNex.java b/src/main/java/com/zivilon/cinder_loe/client/render/RenderNex.java index 286829b..c660d0b 100644 --- a/src/main/java/com/zivilon/cinder_loe/client/render/RenderNex.java +++ b/src/main/java/com/zivilon/cinder_loe/client/render/RenderNex.java @@ -1,7 +1,8 @@ -package lotr.client.render.entity; +package com.zivilon.cinder_loe.client.render; import com.zivilon.cinder_loe.client.model.ModelNex; import com.zivilon.cinder_loe.entity.Nex; +import lotr.client.render.entity.LOTRRandomSkins; import lotr.common.entity.LOTRRandomSkinEntity; import lotr.common.entity.npc.LOTREntityBalrog; import net.minecraft.client.model.ModelBase; diff --git a/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java b/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java new file mode 100644 index 0000000..44dfd5b --- /dev/null +++ b/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java @@ -0,0 +1,51 @@ +package com.zivilon.cinder_loe.enchants; + +import lotr.common.enchant.LOTREnchantmentProtectionRanged; +import lotr.common.enchant.LOTREnchantmentProtectionSpecial; +import lotr.common.item.LOTRMaterial; +import net.minecraft.item.Item; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.StatCollector; + +public class LOTREnchantmentWeakProtectionRanged extends LOTREnchantmentProtectionSpecial { + + public LOTREnchantmentWeakProtectionRanged(String s, int level) { + super(s, level); + } + @Override + protected boolean protectsAgainst(DamageSource source) { + // Check if the damage source is a projectile + return source.isProjectile(); + } + + @Override + public String getDescription(ItemStack itemstack) { + return StatCollector.translateToLocalFormatted((String)"lotr.enchant.protectRanged.desc", (Object[])new Object[]{this.formatAdditiveInt(this.calcIntProtection())}); + } + + @Override + public boolean canApply(ItemStack itemstack, boolean considering) { + if (super.canApply(itemstack, considering)) { + Item item = itemstack.getItem(); + return !(item instanceof ItemArmor) || ((ItemArmor)item).getArmorMaterial() != LOTRMaterial.GALVORN.toArmorMaterial(); + } + return false; + } + + // Redundant because it doesnt work, instead we will be using CinderEventHandler + @Override + protected int calcIntProtection() { + // Implement the logic to calculate protection level + return -(this.protectLevel); + } + + @Override + public boolean isBeneficial() { + // This enchantment is detrimental, so return false + return false; + } +} + + diff --git a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java new file mode 100644 index 0000000..1640e42 --- /dev/null +++ b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java @@ -0,0 +1,41 @@ +package com.zivilon.cinder_loe.mixins; + +import com.zivilon.cinder_loe.enchants.LOTREnchantmentWeakProtectionRanged; +import lotr.common.enchant.LOTREnchantment; +import lotr.common.enchant.LOTREnchantmentDamage; +import lotr.common.enchant.LOTREnchantmentProtectionRanged; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.lang.reflect.Field; +import java.util.Map; + +@Mixin(LOTREnchantment.class) +public class MixinLOTREnchantment { + @Inject(method = "", at = @At("TAIL")) + private static void onStaticInit(CallbackInfo ci) { + // Add your new enchantments here + try { + LOTREnchantment protectRangedWeak1 = new LOTREnchantmentWeakProtectionRanged("protectRangedWeak1", 10).setEnchantWeight(0); + LOTREnchantment weak4 = new LOTREnchantmentDamage("weak4", -3.0f).setEnchantWeight(0); + + LOTREnchantment.allEnchantments.add(protectRangedWeak1); + LOTREnchantment.allEnchantments.add(weak4); + + Field enchantsByNameField = LOTREnchantment.class.getDeclaredField("enchantsByName"); + enchantsByNameField.setAccessible(true); + @SuppressWarnings("unchecked") + Map enchantsByName = (Map) enchantsByNameField.get(null); + + enchantsByName.put(protectRangedWeak1.enchantName, protectRangedWeak1); + enchantsByName.put(weak4.enchantName, weak4); + + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } + +} + diff --git a/src/main/java/com/zivilon/cinder_loe/mixins/overrides/MixinLOTRHiredNPCInfo.java b/src/main/java/com/zivilon/cinder_loe/mixins/overrides/MixinLOTRHiredNPCInfo.java new file mode 100644 index 0000000..94ab98f --- /dev/null +++ b/src/main/java/com/zivilon/cinder_loe/mixins/overrides/MixinLOTRHiredNPCInfo.java @@ -0,0 +1,95 @@ +package com.zivilon.cinder_loe.mixins.overrides; + +import lotr.common.entity.npc.LOTREntityNPC; +import lotr.common.entity.npc.LOTRHiredNPCInfo; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.IAttributeInstance; +import net.minecraft.entity.item.EntityFireworkRocket; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.IChatComponent; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.UUID; + +@Mixin(LOTRHiredNPCInfo.class) +public class MixinLOTRHiredNPCInfo { + @Shadow + private LOTREntityNPC theEntity; + @Shadow + private UUID hiringPlayerUUID; + @Shadow + public int xpLevel = 1; + + @Overwrite(remap = false) + private void onLevelUp() { + EntityPlayer hirer; + if (this.theEntity.getMaxHealth() >= 60) { + this.addLevelUpHealthGain((EntityLivingBase) this.theEntity); + } + Entity mount = this.theEntity.ridingEntity; + if (mount instanceof EntityLivingBase && !(mount instanceof LOTREntityNPC)) { + this.addLevelUpHealthGain((EntityLivingBase)mount); + } + if ((hirer = this.getHiringPlayer()) != null) { + hirer.addChatMessage((IChatComponent)new ChatComponentTranslation("lotr.hiredNPC.levelUp", new Object[]{this.theEntity.getCommandSenderName(), this.xpLevel})); + } + this.spawnLevelUpFireworks(); + } + + @Overwrite(remap = false) + private void addLevelUpHealthGain(EntityLivingBase gainingEntity) { + float healthBoost = 1.0f; + IAttributeInstance attrHealth = gainingEntity.getEntityAttribute(SharedMonsterAttributes.maxHealth); + attrHealth.setBaseValue(attrHealth.getBaseValue() + (double)healthBoost); + gainingEntity.heal(healthBoost); + } + + @Overwrite(remap = false) + public EntityPlayer getHiringPlayer() { + if (this.hiringPlayerUUID == null) { + return null; + } + return this.theEntity.worldObj.func_152378_a(this.hiringPlayerUUID); + } + + private void spawnLevelUpFireworks() { + boolean bigLvlUp = this.xpLevel % 5 == 0; + World world = this.theEntity.worldObj; + ItemStack itemstack = new ItemStack(Items.fireworks); + NBTTagCompound itemData = new NBTTagCompound(); + NBTTagCompound fireworkData = new NBTTagCompound(); + NBTTagList explosionsList = new NBTTagList(); + int explosions = 1; + for (int l = 0; l < explosions; ++l) { + NBTTagCompound explosionData = new NBTTagCompound(); + explosionData.setBoolean("Flicker", true); + explosionData.setBoolean("Trail", bigLvlUp); + int[] colors = new int[]{0xFF5500, this.theEntity.getFaction().getFactionColor()}; + explosionData.setIntArray("Colors", colors); + boolean effectType = bigLvlUp; + explosionData.setByte("Type", (byte)(effectType ? 1 : 0)); + explosionsList.appendTag((NBTBase)explosionData); + } + fireworkData.setTag("Explosions", (NBTBase)explosionsList); + itemData.setTag("Fireworks", (NBTBase)fireworkData); + itemstack.setTagCompound(itemData); + EntityFireworkRocket firework = new EntityFireworkRocket(world, this.theEntity.posX, this.theEntity.boundingBox.minY + (double)this.theEntity.height, this.theEntity.posZ, itemstack); + NBTTagCompound fireworkNBT = new NBTTagCompound(); + firework.writeEntityToNBT(fireworkNBT); + fireworkNBT.setInteger("LifeTime", bigLvlUp ? 20 : 15); + firework.readEntityFromNBT(fireworkNBT); + world.spawnEntityInWorld((Entity)firework); + } + +} diff --git a/src/main/java/com/zivilon/cinder_loe/mixins/overrides/MixinLOTRReplacedMethods.java b/src/main/java/com/zivilon/cinder_loe/mixins/overrides/MixinLOTRReplacedMethods.java new file mode 100644 index 0000000..772d827 --- /dev/null +++ b/src/main/java/com/zivilon/cinder_loe/mixins/overrides/MixinLOTRReplacedMethods.java @@ -0,0 +1,25 @@ +package com.zivilon.cinder_loe.mixins.overrides; + +import lotr.common.coremod.LOTRReplacedMethods; +import lotr.common.enchant.LOTREnchantmentHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(LOTRReplacedMethods.Enchants.class) +public class MixinLOTRReplacedMethods { + + /** + * @author Keylime + * @reason because Mixins complains + */ + @Overwrite(remap = false) + public static int getSpecialArmorProtection(int base, ItemStack[] armor, DamageSource source) { + int i = base; + i += LOTREnchantmentHelper.calcSpecialArmorSetProtection(armor, source); + //i = MathHelper.clamp_int(i, -25, 25); + return i; + } +} diff --git a/src/main/resources/assets/cinder_loe/lang/en_US.lang b/src/main/resources/assets/cinder_loe/lang/en_US.lang index 2f8da6d..f87a009 100644 --- a/src/main/resources/assets/cinder_loe/lang/en_US.lang +++ b/src/main/resources/assets/cinder_loe/lang/en_US.lang @@ -213,3 +213,8 @@ lotr.unit.Bree_Horse=Bree-land Outrider entity.cinder_loe.LOTREntitySauron.name=Sauron entity.cinder_loe.UtumnoSlaveTrader.bound.name=Slave Mule entity.cinder_loe.UtumnoSlaveTrader.name=Freed Utumno Trader + +lotr.enchant.protectWeak1=Dented +lotr.enchant.protectWeak2=Defective +lotr.enchant.protectRangedWeak1=Pierced +lotr.enchant.weak4=Bent \ No newline at end of file diff --git a/src/main/resources/mixins.cinder_loe.json b/src/main/resources/mixins.cinder_loe.json index c33d57e..c142dce 100644 --- a/src/main/resources/mixins.cinder_loe.json +++ b/src/main/resources/mixins.cinder_loe.json @@ -7,6 +7,9 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "MixinItemRenderer", + "overrides.MixinLOTRReplacedMethods", + "overrides.MixinLOTRHiredNPCInfo", + "MixinLOTREnchantment", "MixinLOTRArmorModels", "MixinLOTRClientProxy", "MixinLOTRContainerAnvil", From 18eafbc3a38d2fd24d28053912c1de1af432985d Mon Sep 17 00:00:00 2001 From: KeyLime17 Date: Sat, 24 Aug 2024 17:07:19 -0400 Subject: [PATCH 2/6] replaced onLivingHurt with onLivingAttack, unforseen issues --- .../cinder_loe/CinderEventHandler.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java index 5443109..5760d64 100644 --- a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java +++ b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java @@ -9,6 +9,7 @@ import cpw.mods.fml.common.registry.GameRegistry; import lotr.common.LOTRMod; import lotr.common.enchant.LOTREnchantment; import lotr.common.enchant.LOTREnchantmentHelper; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.player.EntityPlayerMP; @@ -23,6 +24,7 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import java.util.Random; @@ -35,31 +37,40 @@ public class CinderEventHandler implements IFuelHandler { MinecraftForge.TERRAIN_GEN_BUS.register(this); GameRegistry.registerFuelHandler(this); } + @SubscribeEvent - public void onLivingHurt(LivingHurtEvent event) { - EntityLivingBase entity = event.entityLiving; - EntityLivingBase attacker = event.source.getEntity() instanceof EntityLivingBase ? (EntityLivingBase) event.source.getEntity() : null; + public void onLivingAttack(LivingAttackEvent event) { + EntityLivingBase entity = event.entityLiving;; + Entity sourceEntity = event.source.getEntity(); World world = entity.worldObj; - // Negative Arrow Protection Handler + // Negative Arrow Protection Handle if (event.source.isProjectile() && entity instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entity; + player.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "DEBUG: Original Damage: " + (event.ammount))); for (int i = 0; i < 4; i++) { ItemStack armor = entity.getEquipmentInSlot(i + 1); - if (armor != null) { LOTREnchantment enchantment = LOTREnchantment.getEnchantmentByName("protectRangedWeak1"); if (LOTREnchantmentHelper.hasEnchant(armor, enchantment)) { float level = enchantment.getValueModifier(); if (level > 0) { - float additionalDamage = level * 0.2f; // 20% more damage per level - event.ammount += additionalDamage; - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Your armor has received a negative modifier!")); + float additionalDamage = level * 0.2f; //20% more damage per level + event.setCanceled(true); + entity.attackEntityFrom(event.source, event.ammount + additionalDamage); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: damage received, total damage: " + (event.ammount + additionalDamage))); } } } } } + } + + @SubscribeEvent + public void onLivingHurt(LivingHurtEvent event) { + EntityLivingBase entity = event.entityLiving; + EntityLivingBase attacker = event.source.getEntity() instanceof EntityLivingBase ? (EntityLivingBase) event.source.getEntity() : null; + World world = entity.worldObj; // Broken Halo Event handler if (attacker != null && event.source.getSourceOfDamage() == attacker) { From 7bd9ac2b5f69f30145bf05ef41d665809325ef14 Mon Sep 17 00:00:00 2001 From: KeyLime17 Date: Sat, 24 Aug 2024 17:20:10 -0400 Subject: [PATCH 3/6] I have reached Infinity damage! --- .../com/zivilon/cinder_loe/CinderEventHandler.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java index 5760d64..445a0ff 100644 --- a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java +++ b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java @@ -53,13 +53,10 @@ public class CinderEventHandler implements IFuelHandler { if (armor != null) { LOTREnchantment enchantment = LOTREnchantment.getEnchantmentByName("protectRangedWeak1"); if (LOTREnchantmentHelper.hasEnchant(armor, enchantment)) { - float level = enchantment.getValueModifier(); - if (level > 0) { - float additionalDamage = level * 0.2f; //20% more damage per level - event.setCanceled(true); - entity.attackEntityFrom(event.source, event.ammount + additionalDamage); - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: damage received, total damage: " + (event.ammount + additionalDamage))); - } + float additionalDamage = 1.6f; //60% more damage + // event.setCanceled(true); //Disabled to see if this was the source of spam, it wasnt + entity.attackEntityFrom(event.source, event.ammount * additionalDamage); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: damage received, total damage: " + (event.ammount + additionalDamage))); } } } From f95db236bfcafc7a3a2db6a340ca5a8895e5eb1f Mon Sep 17 00:00:00 2001 From: KeyLime17 Date: Sat, 24 Aug 2024 18:08:21 -0400 Subject: [PATCH 4/6] Infinite damage bug 'fixed', back to onLivingHurt, a negative modifier is for some reason giving positive protection still. --- .../cinder_loe/CinderEventHandler.java | 32 +++++++++---------- .../LOTREnchantmentWeakProtectionRanged.java | 21 ++++++------ .../mixins/MixinLOTREnchantment.java | 2 +- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java index 445a0ff..91ee381 100644 --- a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java +++ b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java @@ -39,35 +39,35 @@ public class CinderEventHandler implements IFuelHandler { } @SubscribeEvent - public void onLivingAttack(LivingAttackEvent event) { - EntityLivingBase entity = event.entityLiving;; - Entity sourceEntity = event.source.getEntity(); + public void onLivingHurt(LivingHurtEvent event) { + EntityLivingBase entity = event.entityLiving; + EntityLivingBase attacker = event.source.getEntity() instanceof EntityLivingBase ? (EntityLivingBase) event.source.getEntity() : null; World world = entity.worldObj; - // Negative Arrow Protection Handle + // Negative Arrow Protection Handler if (event.source.isProjectile() && entity instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entity; - player.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "DEBUG: Original Damage: " + (event.ammount))); + float totalAdditionalDamage = 0.0f; + for (int i = 0; i < 4; i++) { ItemStack armor = entity.getEquipmentInSlot(i + 1); + if (armor != null) { LOTREnchantment enchantment = LOTREnchantment.getEnchantmentByName("protectRangedWeak1"); if (LOTREnchantmentHelper.hasEnchant(armor, enchantment)) { - float additionalDamage = 1.6f; //60% more damage - // event.setCanceled(true); //Disabled to see if this was the source of spam, it wasnt - entity.attackEntityFrom(event.source, event.ammount * additionalDamage); - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: damage received, total damage: " + (event.ammount + additionalDamage))); + float level = enchantment.getValueModifier(); + if (level > 0) { + totalAdditionalDamage += 1.6f; // 20% more damage per level + } } } } + // Apply the total additional damage to the event amount + if (totalAdditionalDamage > 0) { + event.ammount += totalAdditionalDamage; + player.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "DEBUG: total damage received: " + event.ammount)); + } } - } - - @SubscribeEvent - public void onLivingHurt(LivingHurtEvent event) { - EntityLivingBase entity = event.entityLiving; - EntityLivingBase attacker = event.source.getEntity() instanceof EntityLivingBase ? (EntityLivingBase) event.source.getEntity() : null; - World world = entity.worldObj; // Broken Halo Event handler if (attacker != null && event.source.getSourceOfDamage() == attacker) { diff --git a/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java b/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java index 44dfd5b..9532eb7 100644 --- a/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java +++ b/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java @@ -14,11 +14,6 @@ public class LOTREnchantmentWeakProtectionRanged extends LOTREnchantmentProtecti public LOTREnchantmentWeakProtectionRanged(String s, int level) { super(s, level); } - @Override - protected boolean protectsAgainst(DamageSource source) { - // Check if the damage source is a projectile - return source.isProjectile(); - } @Override public String getDescription(ItemStack itemstack) { @@ -34,18 +29,22 @@ public class LOTREnchantmentWeakProtectionRanged extends LOTREnchantmentProtecti return false; } - // Redundant because it doesnt work, instead we will be using CinderEventHandler - @Override - protected int calcIntProtection() { - // Implement the logic to calculate protection level - return -(this.protectLevel); - } @Override public boolean isBeneficial() { // This enchantment is detrimental, so return false return false; } + + @Override + protected boolean protectsAgainst(DamageSource damageSource) { + return damageSource.isProjectile(); + } + + @Override + protected int calcIntProtection() { + return 0; + } } diff --git a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java index 1640e42..4c6714e 100644 --- a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java +++ b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java @@ -18,7 +18,7 @@ public class MixinLOTREnchantment { private static void onStaticInit(CallbackInfo ci) { // Add your new enchantments here try { - LOTREnchantment protectRangedWeak1 = new LOTREnchantmentWeakProtectionRanged("protectRangedWeak1", 10).setEnchantWeight(0); + LOTREnchantment protectRangedWeak1 = new LOTREnchantmentWeakProtectionRanged("protectRangedWeak1", 0).setEnchantWeight(0); LOTREnchantment weak4 = new LOTREnchantmentDamage("weak4", -3.0f).setEnchantWeight(0); LOTREnchantment.allEnchantments.add(protectRangedWeak1); From 1d43e42dfaa27f9920d1c98bd59598455bb53754 Mon Sep 17 00:00:00 2001 From: KeyLime17 Date: Wed, 28 Aug 2024 20:53:56 -0400 Subject: [PATCH 5/6] Smithing rework on swords and bows still incomplete --- .../cinder_loe/CinderEventHandler.java | 303 ++++++++++++++---- .../LOTREnchantmentWeakProtectionRanged.java | 4 +- .../mixins/MixinLOTREnchantment.java | 9 +- .../java/com/zivilon/cinder_loe/recipes.java | 4 +- .../cinder_loe/util/DurableItemCrafter.java | 3 + .../assets/cinder_loe/lang/en_US.lang | 6 +- 6 files changed, 267 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java index 91ee381..14b82e6 100644 --- a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java +++ b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java @@ -4,17 +4,20 @@ import com.zivilon.cinder_loe.entity.corrupt.CorruptMan; import com.zivilon.cinder_loe.items.BrokenHalo; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.IFuelHandler; +import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.registry.GameRegistry; import lotr.common.LOTRMod; import lotr.common.enchant.LOTREnchantment; import lotr.common.enchant.LOTREnchantmentHelper; +import lotr.common.item.*; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; +import net.minecraft.item.ItemBow; import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; @@ -26,6 +29,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.event.entity.player.ArrowLooseEvent; import java.util.Random; @@ -37,35 +41,96 @@ public class CinderEventHandler implements IFuelHandler { MinecraftForge.TERRAIN_GEN_BUS.register(this); GameRegistry.registerFuelHandler(this); } + @SubscribeEvent + public void onArrowLoose (ArrowLooseEvent event) { + Entity attacker = event.entityLiving; + if (attacker instanceof EntityPlayerMP player) { + ItemStack bow = player.getHeldItem(); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Arrow Loose Event")); + if (bow != null && bow.isItemStackDamageable() && (bow.getItem() instanceof LOTRItemBow || bow.getItem() instanceof ItemBow)) { + float[] durabilityThresholds = {0.6f, 0.5f, 0.4f}; + double[] probabilities = {1.02, 1.05, 1.1}; + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Semi Complete")); + float durabilityPercent = (float) (bow.getMaxDamage() - bow.getItemDamage() / bow.getMaxDamage()); + for (int j = 0; j < durabilityThresholds.length; j++) { + if (durabilityPercent <= durabilityThresholds[j] && random.nextDouble() <= probabilities[j]) { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Complete")); + addNegativeModifier(bow, player, "bow"); + break; // Exit loop once a modifier is added + } + } + } + } + } @SubscribeEvent + public void onLivingAttack(LivingAttackEvent event) { + Entity attacker = event.source.getEntity(); + + if (attacker instanceof EntityPlayerMP player) { + ItemStack weapon = player.getHeldItem(); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Attack Event")); + // smithing rework for melee + if (weapon !=null && (weapon.getItem() instanceof LOTRItemSpear || weapon.getItem() instanceof LOTRItemSword || weapon.getItem() instanceof LOTRItemDagger || weapon.getItem() instanceof LOTRItemBattleaxe || weapon.getItem() instanceof LOTRItemHammer || weapon.getItem() instanceof ItemSword)) { + float[] durabilityThresholds = {0.6f, 0.5f, 0.4f}; + double[] probabilities = {1.02, 1.05, 1.1}; + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Semi Attack Event Complete")); + if (weapon.isItemStackDamageable()) { + float durabilityPercent = (float) (weapon.getMaxDamage() - weapon.getItemDamage() / weapon.getMaxDamage()); + for (int j = 0; j < durabilityThresholds.length; j++) { + if (durabilityPercent <= durabilityThresholds[j] && random.nextDouble() <= probabilities[j]) { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Attack Event Complete")); + addNegativeModifier(weapon, player, "weapon"); + break; // Exit loop once a modifier is added + } + } + } + } + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) public void onLivingHurt(LivingHurtEvent event) { EntityLivingBase entity = event.entityLiving; EntityLivingBase attacker = event.source.getEntity() instanceof EntityLivingBase ? (EntityLivingBase) event.source.getEntity() : null; World world = entity.worldObj; // Negative Arrow Protection Handler - if (event.source.isProjectile() && entity instanceof EntityPlayerMP) { - EntityPlayerMP player = (EntityPlayerMP) entity; - float totalAdditionalDamage = 0.0f; + if (!event.entityLiving.worldObj.isRemote && event.source.isProjectile() && event.entityLiving instanceof EntityPlayerMP player) { + // player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Initial Damage: " + event.ammount)); - for (int i = 0; i < 4; i++) { - ItemStack armor = entity.getEquipmentInSlot(i + 1); + float totalAdditionalDamage = 0.0f; // Initialize total additional damage + for (int i = 0; i < 4; i++) { + ItemStack armor = player.getEquipmentInSlot(i + 1); if (armor != null) { - LOTREnchantment enchantment = LOTREnchantment.getEnchantmentByName("protectRangedWeak1"); - if (LOTREnchantmentHelper.hasEnchant(armor, enchantment)) { - float level = enchantment.getValueModifier(); - if (level > 0) { - totalAdditionalDamage += 1.6f; // 20% more damage per level - } + LOTREnchantment protectRangedWeak1 = LOTREnchantment.getEnchantmentByName("protectRangedWeak1"); + LOTREnchantment protectRangedWeak2 = LOTREnchantment.getEnchantmentByName("protectRangedWeak2"); + + if (LOTREnchantmentHelper.hasEnchant(armor, protectRangedWeak1)) { + float additionalDamage = 0.2f; // 20% more damage per piece + totalAdditionalDamage += additionalDamage; // Accumulate damage increase + } + if (LOTREnchantmentHelper.hasEnchant(armor, protectRangedWeak2)) { + float additionalDamage = 0.4f; // 40% more damage per piece + totalAdditionalDamage += additionalDamage; // Accumulate damage increase } } } - // Apply the total additional damage to the event amount + + // Apply total additional damage if (totalAdditionalDamage > 0) { - event.ammount += totalAdditionalDamage; - player.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "DEBUG: total damage received: " + event.ammount)); + float newDamage = event.ammount * (1 + totalAdditionalDamage); // Calculate new damage + float newHealth = player.getHealth() - (newDamage - event.ammount); // Calculate health after applying extra damage + + if (newHealth > 0) { + player.setHealth(newHealth); + event.setCanceled(true); + } else { + event.ammount = player.getHealth(); // Ensure player dies if health reaches 0 or below + } + + // player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Total Additional Damage: " + newDamage)); } } @@ -86,7 +151,7 @@ public class CinderEventHandler implements IFuelHandler { spawnedEntity.setHealth(10); spawnedEntity.addPotionEffect(new PotionEffect(Potion.regeneration.id, 9999, 0)); - spawnedEntity.onSpawnWithEgg((IEntityLivingData) null); + spawnedEntity.onSpawnWithEgg(null); world.spawnEntityInWorld(spawnedEntity); world.playAuxSFXAtEntity(null, 1016, (int) spawnedEntity.posX, (int) spawnedEntity.posY, (int) spawnedEntity.posZ, 0); world.playSoundAtEntity(entity, "mob.zombie.unfect", 1F, 1F); @@ -94,32 +159,41 @@ public class CinderEventHandler implements IFuelHandler { } } } + // Smithing Rework event handler - if (entity != null && entity instanceof EntityPlayerMP) { - EntityPlayerMP player = (EntityPlayerMP) entity; + if (attacker instanceof EntityPlayerMP player) { + ItemStack weapon = player.getHeldItem(); + // smithing rework for melee + if (weapon !=null && (weapon.getItem() instanceof LOTRItemSpear || weapon.getItem() instanceof LOTRItemSword || weapon.getItem() instanceof LOTRItemDagger || weapon.getItem() instanceof LOTRItemBattleaxe || weapon.getItem() instanceof LOTRItemHammer || weapon.getItem() instanceof ItemSword)) { + float[] durabilityThresholds = {0.6f, 0.5f, 0.4f}; + double[] probabilities = {1.02, 1.05, 1.1}; + + if (weapon.isItemStackDamageable()) { + float durabilityPercent = (float) (weapon.getMaxDamage() - weapon.getItemDamage() / weapon.getMaxDamage()); + for (int j = 0; j < durabilityThresholds.length; j++) { + if (durabilityPercent <= durabilityThresholds[j] && random.nextDouble() <= probabilities[j]) { + addNegativeModifier(weapon, player, "weapon"); + break; // Exit loop once a modifier is added + } + } + } + } + } + if (entity instanceof EntityPlayerMP player) { + + // Durability thresholds and corresponding probabilities for adding a negative modifier + float[] durabilityThresholds = {0.6f, 0.5f, 0.4f}; + double[] probabilities = {1.02, 1.05, 1.1}; + for (int i = 0; i < 4; ++i) { - ItemStack armor = entity.getEquipmentInSlot(i + 1); + ItemStack armor = player.getEquipmentInSlot(i + 1); if (armor != null && armor.isItemStackDamageable()) { float durabilityPercent = (float) (armor.getMaxDamage() - armor.getItemDamage()) / armor.getMaxDamage(); - if (durabilityPercent <= 0.6) { - if (random.nextDouble() <= 1.02) { - addNegativeModifier(armor); - sendNegativeModifierMessage(player); - playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - } - if (durabilityPercent <= 0.50) { - if (random.nextDouble() <= 1.05) { - addNegativeModifier(armor); - sendNegativeModifierMessage(player); - playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - } - if (durabilityPercent <= 0.4) { - if (random.nextDouble() <= 1.1) { - addNegativeModifier(armor); - sendNegativeModifierMessage(player); - playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - } - } + // Check each threshold and apply negative modifier if conditions are met + for (int j = 0; j < durabilityThresholds.length; j++) { + if (durabilityPercent <= durabilityThresholds[j] && random.nextDouble() <= probabilities[j]) { + addNegativeModifier(armor, player, "armor"); + break; // Exit loop once a modifier is added } } } @@ -129,15 +203,14 @@ public class CinderEventHandler implements IFuelHandler { private void sendNegativeModifierMessage(EntityPlayerMP player) { player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Your armor has received a negative modifier!")); } - private void playNegativeModifierSound(World world, double x, double y, double z) { world.playSoundEffect(x, y, z, "mob.irongolem.hit", 1.0F, 2.0F); } - private void addNegativeModifier(ItemStack armor) { - NBTTagCompound tag = armor.getTagCompound(); + private void addNegativeModifier(ItemStack item, EntityPlayerMP player, String type) { + NBTTagCompound tag = item.getTagCompound(); if (tag == null) { tag = new NBTTagCompound(); - armor.setTagCompound(tag); + item.setTagCompound(tag); } if (!tag.hasKey("LOTREnch")) { @@ -145,27 +218,147 @@ public class CinderEventHandler implements IFuelHandler { } NBTTagList enchList = tag.getTagList("LOTREnch", 8); // 8 is the type for strings + boolean protectWeakUpgraded = false; + boolean protectRangedWeakUpgraded = false; + boolean upgraded = false; - String[] negativeArmorModifiers = {"protectWeak1", "protectWeak2"}; - String newArmorModifier = negativeArmorModifiers[random.nextInt(negativeArmorModifiers.length)]; + boolean meleeSwift = false; + boolean meleeReach = false; - boolean hasModifier = false; - for (int i = 0; i < enchList.tagCount(); i++) { - String ench = enchList.getStringTagAt(i); - if (ench.equals(newArmorModifier)) { - hasModifier = true; - break; + if (type.equals("armor")) { + // First, iterate and upgrade if necessary + for (int i = 0; i < enchList.tagCount(); i++) { + String ench = enchList.getStringTagAt(i); + switch (ench) { + case "protectWeak1" -> { + enchList.removeTag(i); + enchList.appendTag(new NBTTagString("protectWeak2")); + protectWeakUpgraded = true; + i--; // Adjust index after removal + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); + } + case "protectRangedWeak1" -> { + enchList.removeTag(i); + enchList.appendTag(new NBTTagString("protectRangedWeak2")); + protectRangedWeakUpgraded = true; + i--; // Adjust index after removal + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); + } + case "protectWeak2" -> protectWeakUpgraded = true; + case "protectRangedWeak2" -> protectRangedWeakUpgraded = true; + } + } + // After upgrading, check if we need to add a new modifier + if (!protectWeakUpgraded || !protectRangedWeakUpgraded) { + // Separate conditions for adding new modifiers + if (!protectWeakUpgraded && !protectRangedWeakUpgraded) { + // Randomly add either protectWeak1 or protectRangedWeak1 + String[] possibleModifiers = {"protectWeak1", "protectRangedWeak1"}; + String newModifier = possibleModifiers[random.nextInt(possibleModifiers.length)]; + enchList.appendTag(new NBTTagString(newModifier)); + } else if (!protectWeakUpgraded) { + // Only protectWeak1 is added + enchList.appendTag(new NBTTagString("protectWeak1")); + } else if (!protectRangedWeakUpgraded) { + // Only protectRangedWeak1 is added + enchList.appendTag(new NBTTagString("protectRangedWeak1")); + } + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); } - } - if (!hasModifier) { - enchList.appendTag(new NBTTagString(newArmorModifier)); - } + tag.setTag("LOTREnch", enchList); + } else if (type.equals("bow")) { + for (int i = 0; i < enchList.tagCount(); i++) { + String ench = enchList.getStringTagAt(i); + switch (ench) { + case "rangedWeak1" -> { + enchList.removeTag(i); + enchList.appendTag(new NBTTagString("rangedWeak2")); + upgraded = true; + i--; // Adjust index after removal + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); + } + case "rangedWeak2" -> { + enchList.removeTag(i); + enchList.appendTag(new NBTTagString("rangedWeak3")); + upgraded = true; + i--; // Adjust index after removal + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); + } + case "rangedWeak3" -> upgraded = true; + } + } + if (!upgraded) { + // Randomly add either rangedWeak1... etc + String[] possibleModifiers = {"rangedWeak1", "rangedWeak2", "rangedWeak3"}; + String newModifier = possibleModifiers[random.nextInt(possibleModifiers.length)]; + enchList.appendTag(new NBTTagString(newModifier)); + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); + } + } else if (type.equals("weapon")) { + // First, iterate and upgrade if necessary + for (int i = 0; i < enchList.tagCount(); i++) { + String ench = enchList.getStringTagAt(i); + switch (ench) { + case "weak1" -> { + enchList.removeTag(i); + enchList.appendTag(new NBTTagString("weak2")); + upgraded = true; + i--; // Adjust index after removal + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); + } + case "weak3" -> { + enchList.removeTag(i); + enchList.appendTag(new NBTTagString("weak4")); + upgraded = true; + i--; // Adjust index after removal + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); + } + case "weak4" -> upgraded = true; + case "meleeSlow1" -> meleeSwift = true; + case "meleeUnreach1" -> meleeReach = true; + } + } + // After upgrading, check if we need to add a new modifier + if (!upgraded || !meleeSwift || !meleeReach) { + // Separate conditions for adding new modifiers + if (!upgraded && !meleeSwift && !meleeReach) { + // Randomly add one of the possible modifiers + String[] possibleModifiers = {"weak1", "weak2", "weak3", "weak4", "meleeSlow1", "meleeUnreach1"}; + String newModifier = possibleModifiers[random.nextInt(possibleModifiers.length)]; + enchList.appendTag(new NBTTagString(newModifier)); + } else if (!upgraded) { + // Only weak modifier is added + String[] weakModifiers = {"weak1", "weak2", "weak3", "weak4"}; + String newModifier = weakModifiers[random.nextInt(weakModifiers.length)]; + enchList.appendTag(new NBTTagString(newModifier)); + } else if (!meleeSwift) { + // Only meleeSlow1 is added + enchList.appendTag(new NBTTagString("meleeSlow1")); + } else if (!meleeReach) { + // Only meleeUnreach1 is added + enchList.appendTag(new NBTTagString("meleeUnreach1")); + } + + playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); + sendNegativeModifierMessage(player); + } - tag.setTag("LOTREnch", enchList); + + tag.setTag("LOTREnch", enchList); + } } + private ItemStack getRandomWeapon() { Item[] weapons = new Item[]{LOTRMod.blacksmithHammer, LOTRMod.daggerIron, LOTRMod.dunlendingTrident, LOTRMod.battleaxeBronze, CinderLoE.cleaver}; return new ItemStack(weapons[random.nextInt(weapons.length)]); diff --git a/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java b/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java index 9532eb7..d4fac14 100644 --- a/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java +++ b/src/main/java/com/zivilon/cinder_loe/enchants/LOTREnchantmentWeakProtectionRanged.java @@ -38,12 +38,12 @@ public class LOTREnchantmentWeakProtectionRanged extends LOTREnchantmentProtecti @Override protected boolean protectsAgainst(DamageSource damageSource) { - return damageSource.isProjectile(); + return false; } @Override protected int calcIntProtection() { - return 0; + return this.protectLevel; } } diff --git a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java index 4c6714e..b6bb4b7 100644 --- a/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java +++ b/src/main/java/com/zivilon/cinder_loe/mixins/MixinLOTREnchantment.java @@ -4,6 +4,7 @@ import com.zivilon.cinder_loe.enchants.LOTREnchantmentWeakProtectionRanged; import lotr.common.enchant.LOTREnchantment; import lotr.common.enchant.LOTREnchantmentDamage; import lotr.common.enchant.LOTREnchantmentProtectionRanged; +import lotr.common.enchant.LOTREnchantmentRangedDamage; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -18,10 +19,14 @@ public class MixinLOTREnchantment { private static void onStaticInit(CallbackInfo ci) { // Add your new enchantments here try { - LOTREnchantment protectRangedWeak1 = new LOTREnchantmentWeakProtectionRanged("protectRangedWeak1", 0).setEnchantWeight(0); + LOTREnchantment protectRangedWeak1 = new LOTREnchantmentWeakProtectionRanged("protectRangedWeak1", -1).setEnchantWeight(0); + LOTREnchantment protectRangedWeak2 = new LOTREnchantmentWeakProtectionRanged("protectRangedWeak2", -2).setEnchantWeight(0); + LOTREnchantment rangedWeak3 = new LOTREnchantmentRangedDamage("rangedWeak3", 0.25f); LOTREnchantment weak4 = new LOTREnchantmentDamage("weak4", -3.0f).setEnchantWeight(0); LOTREnchantment.allEnchantments.add(protectRangedWeak1); + LOTREnchantment.allEnchantments.add(protectRangedWeak2); + rangedWeak3.allEnchantments.add(rangedWeak3); LOTREnchantment.allEnchantments.add(weak4); Field enchantsByNameField = LOTREnchantment.class.getDeclaredField("enchantsByName"); @@ -30,6 +35,8 @@ public class MixinLOTREnchantment { Map enchantsByName = (Map) enchantsByNameField.get(null); enchantsByName.put(protectRangedWeak1.enchantName, protectRangedWeak1); + enchantsByName.put(protectRangedWeak2.enchantName, protectRangedWeak2); + enchantsByName.put(rangedWeak3.enchantName, rangedWeak3); enchantsByName.put(weak4.enchantName, weak4); } catch (NoSuchFieldException | IllegalAccessException e) { diff --git a/src/main/java/com/zivilon/cinder_loe/recipes.java b/src/main/java/com/zivilon/cinder_loe/recipes.java index 3dc590c..43e465d 100644 --- a/src/main/java/com/zivilon/cinder_loe/recipes.java +++ b/src/main/java/com/zivilon/cinder_loe/recipes.java @@ -143,9 +143,9 @@ public class recipes { OreDictionary.registerOre("meat", LOTRMod.zebraCooked); GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(CinderLoE.fruitsalad), Items.bowl, "fruit1", "fruit2", "fruit3")); - GameRegistry.addRecipe(new CinderShapelessOreRecipe(new ItemStack(CinderLoE.pasta, 4), LOTRMod.rollingPin, CinderLoE.dough, CinderLoE.dough)); + GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(CinderLoE.pasta, 4), LOTRMod.rollingPin, CinderLoE.dough, CinderLoE.dough)); GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(CinderLoE.halva), Items.sugar, CinderLoE.dough, CinderLoE.spice, LOTRMod.almond)); - //takes durability from rolling pin + GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(CinderLoE.chocolatebar, 2), LOTRMod.mugChocolate)); GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(CinderLoE.pelmen), Items.wheat, "meat", LOTRMod.salt)); diff --git a/src/main/java/com/zivilon/cinder_loe/util/DurableItemCrafter.java b/src/main/java/com/zivilon/cinder_loe/util/DurableItemCrafter.java index 242a81a..6392934 100644 --- a/src/main/java/com/zivilon/cinder_loe/util/DurableItemCrafter.java +++ b/src/main/java/com/zivilon/cinder_loe/util/DurableItemCrafter.java @@ -9,6 +9,9 @@ import com.zivilon.cinder_loe.CinderLoE; public class DurableItemCrafter { public static List customItems = new ArrayList<>(); + static { + customItems.add(LOTRMod.rollingPin); + } public static List exceptionItems = new ArrayList<>(); static { customItems.add(LOTRMod.chisel); diff --git a/src/main/resources/assets/cinder_loe/lang/en_US.lang b/src/main/resources/assets/cinder_loe/lang/en_US.lang index f87a009..2414e61 100644 --- a/src/main/resources/assets/cinder_loe/lang/en_US.lang +++ b/src/main/resources/assets/cinder_loe/lang/en_US.lang @@ -216,5 +216,7 @@ entity.cinder_loe.UtumnoSlaveTrader.name=Freed Utumno Trader lotr.enchant.protectWeak1=Dented lotr.enchant.protectWeak2=Defective -lotr.enchant.protectRangedWeak1=Pierced -lotr.enchant.weak4=Bent \ No newline at end of file +lotr.enchant.protectRangedWeak1=Punctured +lotr.enchant.protectRangedWeak2=Pierced +lotr.enchant.weak4=Bent +lotr.enchant.rangedWeak3=Cracked From 5c190c43826d25384e499f3c2589f2d5eb893590 Mon Sep 17 00:00:00 2001 From: KeyLime17 Date: Thu, 29 Aug 2024 17:29:05 -0400 Subject: [PATCH 6/6] Smithing rework finished- kits incomplete --- .../cinder_loe/CinderEventHandler.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java index 14b82e6..ee1674c 100644 --- a/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java +++ b/src/main/java/com/zivilon/cinder_loe/CinderEventHandler.java @@ -42,19 +42,19 @@ public class CinderEventHandler implements IFuelHandler { GameRegistry.registerFuelHandler(this); } @SubscribeEvent - public void onArrowLoose (ArrowLooseEvent event) { + public void onArrowLoose(ArrowLooseEvent event) { Entity attacker = event.entityLiving; if (attacker instanceof EntityPlayerMP player) { ItemStack bow = player.getHeldItem(); - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Arrow Loose Event")); if (bow != null && bow.isItemStackDamageable() && (bow.getItem() instanceof LOTRItemBow || bow.getItem() instanceof ItemBow)) { float[] durabilityThresholds = {0.6f, 0.5f, 0.4f}; - double[] probabilities = {1.02, 1.05, 1.1}; - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Semi Complete")); - float durabilityPercent = (float) (bow.getMaxDamage() - bow.getItemDamage() / bow.getMaxDamage()); + double[] probabilities = {0.02, 0.05, 0.1}; // Corrected probabilities + + // Corrected durabilityPercent calculation + float durabilityPercent = (float) (bow.getMaxDamage() - bow.getItemDamage()) / bow.getMaxDamage(); + for (int j = 0; j < durabilityThresholds.length; j++) { if (durabilityPercent <= durabilityThresholds[j] && random.nextDouble() <= probabilities[j]) { - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Complete")); addNegativeModifier(bow, player, "bow"); break; // Exit loop once a modifier is added } @@ -69,17 +69,16 @@ public class CinderEventHandler implements IFuelHandler { if (attacker instanceof EntityPlayerMP player) { ItemStack weapon = player.getHeldItem(); - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Attack Event")); // smithing rework for melee - if (weapon !=null && (weapon.getItem() instanceof LOTRItemSpear || weapon.getItem() instanceof LOTRItemSword || weapon.getItem() instanceof LOTRItemDagger || weapon.getItem() instanceof LOTRItemBattleaxe || weapon.getItem() instanceof LOTRItemHammer || weapon.getItem() instanceof ItemSword)) { + if (weapon != null && (weapon.getItem() instanceof LOTRItemSpear || weapon.getItem() instanceof LOTRItemSword || weapon.getItem() instanceof LOTRItemDagger || weapon.getItem() instanceof LOTRItemBattleaxe || weapon.getItem() instanceof LOTRItemHammer || weapon.getItem() instanceof ItemSword)) { float[] durabilityThresholds = {0.6f, 0.5f, 0.4f}; - double[] probabilities = {1.02, 1.05, 1.1}; - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Semi Attack Event Complete")); + double[] probabilities = {0.02, 0.05, 0.1}; // Corrected probabilities if (weapon.isItemStackDamageable()) { - float durabilityPercent = (float) (weapon.getMaxDamage() - weapon.getItemDamage() / weapon.getMaxDamage()); + // Corrected durabilityPercent calculation + float durabilityPercent = (float) (weapon.getMaxDamage() - weapon.getItemDamage()) / weapon.getMaxDamage(); + for (int j = 0; j < durabilityThresholds.length; j++) { if (durabilityPercent <= durabilityThresholds[j] && random.nextDouble() <= probabilities[j]) { - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Attack Event Complete")); addNegativeModifier(weapon, player, "weapon"); break; // Exit loop once a modifier is added } @@ -166,7 +165,7 @@ public class CinderEventHandler implements IFuelHandler { // smithing rework for melee if (weapon !=null && (weapon.getItem() instanceof LOTRItemSpear || weapon.getItem() instanceof LOTRItemSword || weapon.getItem() instanceof LOTRItemDagger || weapon.getItem() instanceof LOTRItemBattleaxe || weapon.getItem() instanceof LOTRItemHammer || weapon.getItem() instanceof ItemSword)) { float[] durabilityThresholds = {0.6f, 0.5f, 0.4f}; - double[] probabilities = {1.02, 1.05, 1.1}; + double[] probabilities = {0.02, 0.05, 0.1}; if (weapon.isItemStackDamageable()) { float durabilityPercent = (float) (weapon.getMaxDamage() - weapon.getItemDamage() / weapon.getMaxDamage()); @@ -183,7 +182,7 @@ public class CinderEventHandler implements IFuelHandler { // Durability thresholds and corresponding probabilities for adding a negative modifier float[] durabilityThresholds = {0.6f, 0.5f, 0.4f}; - double[] probabilities = {1.02, 1.05, 1.1}; + double[] probabilities = {0.02, 0.05, 0.1}; for (int i = 0; i < 4; ++i) { ItemStack armor = player.getEquipmentInSlot(i + 1); @@ -200,8 +199,12 @@ public class CinderEventHandler implements IFuelHandler { } } } - private void sendNegativeModifierMessage(EntityPlayerMP player) { - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Your armor has received a negative modifier!")); + private void sendNegativeModifierMessage(EntityPlayerMP player, String type) { + player.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "Your " + + EnumChatFormatting.GOLD + type + + EnumChatFormatting.RED + " has received a negative modifier!" + )); } private void playNegativeModifierSound(World world, double x, double y, double z) { world.playSoundEffect(x, y, z, "mob.irongolem.hit", 1.0F, 2.0F); @@ -236,7 +239,7 @@ public class CinderEventHandler implements IFuelHandler { protectWeakUpgraded = true; i--; // Adjust index after removal playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Armor"); } case "protectRangedWeak1" -> { enchList.removeTag(i); @@ -244,7 +247,7 @@ public class CinderEventHandler implements IFuelHandler { protectRangedWeakUpgraded = true; i--; // Adjust index after removal playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Armor"); } case "protectWeak2" -> protectWeakUpgraded = true; case "protectRangedWeak2" -> protectRangedWeakUpgraded = true; @@ -266,7 +269,7 @@ public class CinderEventHandler implements IFuelHandler { enchList.appendTag(new NBTTagString("protectRangedWeak1")); } playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Armor"); } tag.setTag("LOTREnch", enchList); @@ -280,7 +283,7 @@ public class CinderEventHandler implements IFuelHandler { upgraded = true; i--; // Adjust index after removal playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Bow"); } case "rangedWeak2" -> { enchList.removeTag(i); @@ -288,7 +291,7 @@ public class CinderEventHandler implements IFuelHandler { upgraded = true; i--; // Adjust index after removal playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Bow"); } case "rangedWeak3" -> upgraded = true; } @@ -299,7 +302,7 @@ public class CinderEventHandler implements IFuelHandler { String newModifier = possibleModifiers[random.nextInt(possibleModifiers.length)]; enchList.appendTag(new NBTTagString(newModifier)); playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Weapon"); } } else if (type.equals("weapon")) { // First, iterate and upgrade if necessary @@ -312,7 +315,7 @@ public class CinderEventHandler implements IFuelHandler { upgraded = true; i--; // Adjust index after removal playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Weapon"); } case "weak3" -> { enchList.removeTag(i); @@ -320,7 +323,7 @@ public class CinderEventHandler implements IFuelHandler { upgraded = true; i--; // Adjust index after removal playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Weapon"); } case "weak4" -> upgraded = true; case "meleeSlow1" -> meleeSwift = true; @@ -349,7 +352,7 @@ public class CinderEventHandler implements IFuelHandler { } playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ); - sendNegativeModifierMessage(player); + sendNegativeModifierMessage(player, "Weapon"); }