2
0
Fork 0

Smithing rework on swords and bows still incomplete

frozen
KeyLime17 1 year ago
parent f95db236bf
commit 1d43e42dfa

@ -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;
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 (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 (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);
}
}
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 = player.getEquipmentInSlot(i + 1);
if (armor != null && armor.isItemStackDamageable()) {
float durabilityPercent = (float) (armor.getMaxDamage() - armor.getItemDamage()) / armor.getMaxDamage();
// 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,25 +218,145 @@ 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;
boolean meleeSwift = false;
boolean meleeReach = false;
String[] negativeArmorModifiers = {"protectWeak1", "protectWeak2"};
String newArmorModifier = negativeArmorModifiers[random.nextInt(negativeArmorModifiers.length)];
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);
}
boolean hasModifier = false;
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);
if (ench.equals(newArmorModifier)) {
hasModifier = true;
break;
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"));
}
if (!hasModifier) {
enchList.appendTag(new NBTTagString(newArmorModifier));
playNegativeModifierSound(player.worldObj, player.posX, player.posY, player.posZ);
sendNegativeModifierMessage(player);
}
tag.setTag("LOTREnch", enchList);
}
}
private ItemStack getRandomWeapon() {

@ -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;
}
}

@ -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<String, LOTREnchantment> enchantsByName = (Map<String, LOTREnchantment>) 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) {

@ -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));

@ -9,6 +9,9 @@ import com.zivilon.cinder_loe.CinderLoE;
public class DurableItemCrafter {
public static List<Item> customItems = new ArrayList<>();
static {
customItems.add(LOTRMod.rollingPin);
}
public static List<Item> exceptionItems = new ArrayList<>();
static {
customItems.add(LOTRMod.chisel);

@ -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.protectRangedWeak1=Punctured
lotr.enchant.protectRangedWeak2=Pierced
lotr.enchant.weak4=Bent
lotr.enchant.rangedWeak3=Cracked

Loading…
Cancel
Save