2
0
Fork 0

Packet doesnt work in Event Handler for blocking

frozen
KeyLime17 1 year ago
parent 9df86edb36
commit 31a94c46f0

@ -19,6 +19,7 @@ import net.minecraft.item.*;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString; import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.play.server.S04PacketEntityEquipment;
import net.minecraft.network.play.server.S19PacketEntityStatus; import net.minecraft.network.play.server.S19PacketEntityStatus;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
@ -89,11 +90,17 @@ public class CinderEventHandler implements IFuelHandler {
} }
@SubscribeEvent @SubscribeEvent
public void onLivingHurt(LivingHurtEvent event) { public void onLivingHurt(LivingHurtEvent event) {
if (event.entityLiving == null || event.source.getEntity() == null) {
return;
}
EntityLivingBase entity = event.entityLiving; 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; World world = entity.worldObj;
DamageSource source = event.source; DamageSource source = event.source;
if (event.entity instanceof EntityPlayer && !source.isUnblockable() || event.entity instanceof EntityPlayer && !source.isExplosion()) {
if (event.entity instanceof EntityPlayer && !source.isUnblockable()) {
EntityPlayerMP player = (EntityPlayerMP) event.entity; EntityPlayerMP player = (EntityPlayerMP) event.entity;
ItemStack sword = player.getHeldItem(); ItemStack sword = player.getHeldItem();
@ -120,14 +127,14 @@ public class CinderEventHandler implements IFuelHandler {
sword.damageItem((int) (event.ammount *1.5), player); // Axes deal 150% the Durability damage sword.damageItem((int) (event.ammount *1.5), player); // Axes deal 150% the Durability damage
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S19PacketEntityStatus(player, (byte) 29)); ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S19PacketEntityStatus(player, (byte) 29));
world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F); world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F);
additionalDamage = 0.75f; additionalDamage = 0.75f; // Only 25% Passes through
} else if (weapon.getItem() instanceof LOTRItemHammer) { } else if (weapon.getItem() instanceof LOTRItemHammer) {
sword.damageItem((int) event.ammount, player); // Hammers bypass the block better, but only deal 100% of the durability damage sword.damageItem((int) event.ammount, player); // Hammers bypass the block better, but only deal 100% of the durability damage
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S19PacketEntityStatus(player, (byte) 29)); ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S19PacketEntityStatus(player, (byte) 29));
world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F); world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F);
additionalDamage = 0.5f; // 20% more damage per piece additionalDamage = 0.5f; // Only 50% Passes through
} else { } else {
additionalDamage = 0.0f; additionalDamage = 0.0f; // 0% Damage Passes through
sword.damageItem((int) (event.ammount/2), player); //Swords only deal 50% of durability damage sword.damageItem((int) (event.ammount/2), player); //Swords only deal 50% of durability damage
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S19PacketEntityStatus(player, (byte) 29)); ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S19PacketEntityStatus(player, (byte) 29));
world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F); world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F);

@ -5,7 +5,9 @@ import lotr.common.entity.npc.LOTRHiredNPCInfo;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.IAttribute;
import net.minecraft.entity.ai.attributes.IAttributeInstance; import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.ai.attributes.RangedAttribute;
import net.minecraft.entity.item.EntityFireworkRocket; import net.minecraft.entity.item.EntityFireworkRocket;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items; import net.minecraft.init.Items;
@ -19,6 +21,7 @@ import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import java.util.UUID; import java.util.UUID;
@ -30,11 +33,18 @@ public class MixinLOTRHiredNPCInfo {
private UUID hiringPlayerUUID; private UUID hiringPlayerUUID;
@Shadow @Shadow
public int xpLevel = 1; public int xpLevel = 1;
@Unique
public int levelUpCounter = 0;
/**
* @author
* @reason
*/
@Overwrite(remap = false) @Overwrite(remap = false)
public void onLevelUp() { public void onLevelUp() {
EntityPlayer hirer; EntityPlayer hirer;
this.addLevelUpHealthGain((EntityLivingBase) this.theEntity); rotateLevelUpStat();
Entity mount = this.theEntity.ridingEntity; Entity mount = this.theEntity.ridingEntity;
if (mount instanceof EntityLivingBase && !(mount instanceof LOTREntityNPC)) { if (mount instanceof EntityLivingBase && !(mount instanceof LOTREntityNPC)) {
this.addLevelUpHealthGain((EntityLivingBase)mount); this.addLevelUpHealthGain((EntityLivingBase)mount);
@ -45,6 +55,35 @@ public class MixinLOTRHiredNPCInfo {
this.spawnLevelUpFireworks(); this.spawnLevelUpFireworks();
} }
public void rotateLevelUpStat() {
EntityLivingBase entity = (EntityLivingBase) this.theEntity;
switch (levelUpCounter) {
case 0:
// +1 HP
this.addLevelUpHealthGain(entity);
break;
case 1:
// +0.25 Damage
this.increaseDamageGain(entity);
break;
case 2:
// +0.005 movement Speed
this.increaseMovementGain(entity);
break;
case 3:
// +0.1 knockback resistance
this.increaseKnockbackGain(entity);
break;
}
levelUpCounter = (levelUpCounter +1) % 4;
}
/**
* @author
* @reason
*/
@Overwrite(remap = false) @Overwrite(remap = false)
public void addLevelUpHealthGain(EntityLivingBase gainingEntity) { public void addLevelUpHealthGain(EntityLivingBase gainingEntity) {
float healthBoost = 1.0f; float healthBoost = 1.0f;
@ -53,6 +92,28 @@ public class MixinLOTRHiredNPCInfo {
gainingEntity.heal(healthBoost); gainingEntity.heal(healthBoost);
} }
public void increaseDamageGain(EntityLivingBase gainingEntity) {
float damageBoost = 0.25f;
IAttributeInstance attribute = gainingEntity.getEntityAttribute(LOTREntityNPC.npcAttackDamage);
attribute.setBaseValue(attribute.getBaseValue() + (double)damageBoost);
}
public void increaseMovementGain(EntityLivingBase gainingEntity) {
float movementBoost = 0.005f;
IAttributeInstance attribute = gainingEntity.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
attribute.setBaseValue(attribute.getBaseValue() + (double)movementBoost);
}
public void increaseKnockbackGain(EntityLivingBase gainingEntity) {
float kbResBoost = 0.1f;
IAttributeInstance attribute = gainingEntity.getEntityAttribute(SharedMonsterAttributes.knockbackResistance);
attribute.setBaseValue(attribute.getBaseValue() + (double)kbResBoost);
}
/**
* @author
* @reason
*/
@Overwrite(remap = false) @Overwrite(remap = false)
public EntityPlayer getHiringPlayer() { public EntityPlayer getHiringPlayer() {
if (this.hiringPlayerUUID == null) { if (this.hiringPlayerUUID == null) {

Loading…
Cancel
Save