From f433ee885808c8537d16818c8e277320ec0fa4d6 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Fri, 22 Nov 2019 01:18:50 -0600 Subject: [PATCH] Tracker 'thrower' of mana bursts and use that for terra sword --- .../common/entity/EntityManaBurst.java | 11 ++++---- .../tool/terrasteel/ItemTerraSword.java | 28 +++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/main/java/vazkii/botania/common/entity/EntityManaBurst.java b/src/main/java/vazkii/botania/common/entity/EntityManaBurst.java index 9466a3852..c46dcccdc 100644 --- a/src/main/java/vazkii/botania/common/entity/EntityManaBurst.java +++ b/src/main/java/vazkii/botania/common/entity/EntityManaBurst.java @@ -149,16 +149,15 @@ public class EntityManaBurst extends ThrowableEntity implements IManaBurst { } public EntityManaBurst(PlayerEntity player, Hand hand) { - this(player.world); + super(TYPE, player, player.world); setBurstSourceCoords(new BlockPos(0, -1, 0)); - setLocationAndAngles(player.posX, player.posY + player.getEyeHeight(), player.posZ, player.rotationYaw + 180, -player.rotationPitch); + setRotation(player.rotationYaw + 180, -player.rotationPitch); - posX -= (hand == Hand.OFF_HAND ? -1 : 1) * MathHelper.cos((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F; - posY -= 0.10000000149011612D; - posZ -= (hand == Hand.OFF_HAND ? -1 : 1) * MathHelper.sin((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F; + double dX = (hand == Hand.OFF_HAND ? -1 : 1) * MathHelper.cos((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F; + double dZ = (hand == Hand.OFF_HAND ? -1 : 1) * MathHelper.sin((rotationYaw + 180) / 180.0F * (float) Math.PI) * 0.16F; - setPosition(posX, posY, posZ); + setPosition(posX - dX, posY, posZ - dZ); float f = 0.4F; double mx = MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f / 2D; double mz = -(MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f) / 2D; diff --git a/src/main/java/vazkii/botania/common/item/equipment/tool/terrasteel/ItemTerraSword.java b/src/main/java/vazkii/botania/common/item/equipment/tool/terrasteel/ItemTerraSword.java index 3dc7603a6..632508750 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/tool/terrasteel/ItemTerraSword.java +++ b/src/main/java/vazkii/botania/common/item/equipment/tool/terrasteel/ItemTerraSword.java @@ -40,9 +40,6 @@ import java.util.UUID; public class ItemTerraSword extends ItemManasteelSword implements ILensEffect { - // todo 1.14 use throwableentity's owner system instead of tracking it ourselves - private static final String TAG_ATTACKER_UUID = "attackerUuid"; - private static final int MANA_PER_DAMAGE = 100; public ItemTerraSword(Properties props) { @@ -59,8 +56,8 @@ public class ItemTerraSword extends ItemManasteelSword implements ILensEffect { } private void attackEntity(AttackEntityEvent evt) { - if (!evt.getEntityPlayer().world.isRemote) { - trySpawnBurst(evt.getEntityPlayer()); + if (!evt.getPlayer().world.isRemote) { + trySpawnBurst(evt.getPlayer()); } } @@ -94,9 +91,7 @@ public class ItemTerraSword extends ItemManasteelSword implements ILensEffect { burst.setBurstMotion(burst.getMotion().getX() * motionModifier, burst.getMotion().getY() * motionModifier, burst.getMotion().getZ() * motionModifier); - ItemStack lens = stack.copy(); - ItemNBTHelper.setUuid(lens, TAG_ATTACKER_UUID, player.getUniqueID()); - burst.setSourceLens(lens); + burst.setSourceLens(stack.copy()); return burst; } @@ -113,11 +108,11 @@ public class ItemTerraSword extends ItemManasteelSword implements ILensEffect { ThrowableEntity entity = (ThrowableEntity) burst; AxisAlignedBB axis = new AxisAlignedBB(entity.posX, entity.posY, entity.posZ, entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ).grow(1); List entities = entity.world.getEntitiesWithinAABB(LivingEntity.class, axis); - UUID attacker = ItemNBTHelper.getUuid(burst.getSourceLens(), TAG_ATTACKER_UUID); + LivingEntity thrower = entity.getThrower(); for(LivingEntity living : entities) { - if(living instanceof PlayerEntity && (living.getUniqueID().equals(attacker) - || ServerLifecycleHooks.getCurrentServer() != null && !ServerLifecycleHooks.getCurrentServer().isPVPEnabled())) + if(living == thrower + || ServerLifecycleHooks.getCurrentServer() != null && !ServerLifecycleHooks.getCurrentServer().isPVPEnabled()) continue; if(living.hurtTime == 0) { @@ -127,10 +122,13 @@ public class ItemTerraSword extends ItemManasteelSword implements ILensEffect { burst.setMana(mana - cost); float damage = 4F + BotaniaAPI.TERRASTEEL_ITEM_TIER.getAttackDamage(); if(!burst.isFake() && !entity.world.isRemote) { - PlayerEntity player = attacker != null ? living.world.getPlayerByUuid(attacker) : null; - living.attackEntityFrom(player == null - ? DamageSource.MAGIC - : DamageSource.causePlayerDamage(player), damage); + DamageSource source = DamageSource.MAGIC; + if(thrower instanceof PlayerEntity) { + source = DamageSource.causePlayerDamage((PlayerEntity) thrower); + } else if(thrower != null) { + source = DamageSource.causeMobDamage(thrower); + } + living.attackEntityFrom(source, damage); entity.remove(); break; }