Began rework on some stuff, however onLivingHurt event doesnt apply the additional damage
parent
85ab078658
commit
214833790f
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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 = "<clinit>", 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<String, LOTREnchantment> enchantsByName = (Map<String, LOTREnchantment>) enchantsByNameField.get(null);
|
||||||
|
|
||||||
|
enchantsByName.put(protectRangedWeak1.enchantName, protectRangedWeak1);
|
||||||
|
enchantsByName.put(weak4.enchantName, weak4);
|
||||||
|
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue