diff --git a/modules/API/src/main/java/de/Keyle/MyPet/api/entity/MyPetMinecraftEntity.java b/modules/API/src/main/java/de/Keyle/MyPet/api/entity/MyPetMinecraftEntity.java index 436ce4957e..fe00d3e7e8 100644 --- a/modules/API/src/main/java/de/Keyle/MyPet/api/entity/MyPetMinecraftEntity.java +++ b/modules/API/src/main/java/de/Keyle/MyPet/api/entity/MyPetMinecraftEntity.java @@ -20,15 +20,16 @@ package de.Keyle.MyPet.api.entity; -import de.Keyle.MyPet.api.entity.ai.AIGoalSelector; -import de.Keyle.MyPet.api.entity.ai.navigation.AbstractNavigation; -import de.Keyle.MyPet.api.entity.ai.target.TargetPriority; -import de.Keyle.MyPet.api.player.MyPetPlayer; +import java.util.UUID; + import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; -import java.util.UUID; +import de.Keyle.MyPet.api.entity.ai.AIGoalSelector; +import de.Keyle.MyPet.api.entity.ai.navigation.AbstractNavigation; +import de.Keyle.MyPet.api.entity.ai.target.TargetPriority; +import de.Keyle.MyPet.api.player.MyPetPlayer; public interface MyPetMinecraftEntity { boolean isMyPet(); @@ -57,12 +58,8 @@ public interface MyPetMinecraftEntity { void updateVisuals(); - LivingEntity getTarget(); - TargetPriority getTargetPriority(); - void setTarget(LivingEntity entity, TargetPriority priority); - void forgetTarget(); boolean hasTarget(); @@ -78,4 +75,8 @@ public interface MyPetMinecraftEntity { boolean isSitting(); UUID getUniqueID(); + + LivingEntity getMyPetTarget(); + + void setMyPetTarget(LivingEntity entity, TargetPriority priority); } \ No newline at end of file diff --git a/modules/API/src/main/java/de/Keyle/MyPet/api/util/inventory/CustomInventory.java b/modules/API/src/main/java/de/Keyle/MyPet/api/util/inventory/CustomInventory.java index ae4a5800ef..8367448e49 100644 --- a/modules/API/src/main/java/de/Keyle/MyPet/api/util/inventory/CustomInventory.java +++ b/modules/API/src/main/java/de/Keyle/MyPet/api/util/inventory/CustomInventory.java @@ -27,8 +27,6 @@ import org.bukkit.inventory.ItemStack; public interface CustomInventory { - int getSize(); - void setSize(int size); String getName(); diff --git a/modules/MyPet/pom.xml b/modules/MyPet/pom.xml index aea224a91f..74cba96a27 100644 --- a/modules/MyPet/pom.xml +++ b/modules/MyPet/pom.xml @@ -24,7 +24,7 @@ de.keyle mypet - 3.12-dev4 + 3.12-dev5 jar MyPet https://www.spigotmc.org/resources/mypet.12725/ diff --git a/modules/Plugin/src/main/java/de/Keyle/MyPet/listeners/MyPetEntityListener.java b/modules/Plugin/src/main/java/de/Keyle/MyPet/listeners/MyPetEntityListener.java index 8c56c83156..e836ab1876 100644 --- a/modules/Plugin/src/main/java/de/Keyle/MyPet/listeners/MyPetEntityListener.java +++ b/modules/Plugin/src/main/java/de/Keyle/MyPet/listeners/MyPetEntityListener.java @@ -507,7 +507,7 @@ public void onMyPet(final EntityDeathEvent event) { if (deadBehaviorSkill.getBehavior() == BehaviorMode.Duel && killerBehaviorSkill.getBehavior() == BehaviorMode.Duel) { MyPetMinecraftEntity myPetEntity = ((MyPetBukkitEntity) deadEntity).getHandle(); - if (e.getDamager().equals(myPetEntity.getTarget())) { + if (e.getDamager().equals(myPetEntity.getMyPetTarget())) { myPet.setRespawnTime(10); killerMyPet.setHealth(Double.MAX_VALUE); } diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/CraftMyPet.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/CraftMyPet.java index dd5679f3ee..b85b1c49c3 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/CraftMyPet.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/CraftMyPet.java @@ -123,7 +123,7 @@ public void forgetTarget() { } public void setTarget(LivingEntity target, TargetPriority priority) { - getHandle().setTarget(target, priority); + getHandle().setMyPetTarget(target, priority); } @Override diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/EntityMyPet.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/EntityMyPet.java index 6a497931d2..6def656fa4 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/EntityMyPet.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/EntityMyPet.java @@ -198,8 +198,9 @@ public boolean hasTarget() { public TargetPriority getTargetPriority() { return targetPriority; } - - public LivingEntity getTarget() { + + @Override + public LivingEntity getMyPetTarget() { if (target != null) { if (target.isAlive()) { return (LivingEntity) target.getBukkitEntity(); @@ -208,8 +209,9 @@ public LivingEntity getTarget() { } return null; } - - public void setTarget(LivingEntity entity, TargetPriority priority) { + + @Override + public void setMyPetTarget(LivingEntity entity, TargetPriority priority) { if (entity == null || entity.isDead() || entity instanceof ArmorStand || !(entity instanceof CraftLivingEntity)) { forgetTarget(); return; diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/attack/MeleeAttack.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/attack/MeleeAttack.java index a1ea362eeb..5fa9792086 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/attack/MeleeAttack.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/attack/MeleeAttack.java @@ -58,7 +58,7 @@ public boolean shouldStart() { if (!this.petEntity.hasTarget()) { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (targetEntity instanceof EntityArmorStand) { return false; @@ -92,7 +92,7 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!this.petEntity.hasTarget() || !this.petEntity.canMove()) { return true; - } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getTarget()) { + } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getMyPetTarget()) { return true; } if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.e(targetEntity.locX, targetEntity.getBoundingBox().b, targetEntity.locZ) >= 20) { diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/attack/RangedAttack.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/attack/RangedAttack.java index c441b894e5..35b2eb4d03 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/attack/RangedAttack.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/attack/RangedAttack.java @@ -63,7 +63,7 @@ public boolean shouldStart() { return false; } - EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getMyPetTarget()).getHandle(); if (target instanceof EntityArmorStand) { return false; @@ -102,7 +102,7 @@ public boolean shouldFinish() { if (!entityMyPet.hasTarget() || myPet.getRangedDamage() <= 0 || !entityMyPet.canMove()) { return true; } - if (this.target.getBukkitEntity() != entityMyPet.getTarget()) { + if (this.target.getBukkitEntity() != entityMyPet.getMyPetTarget()) { return true; } double meleeDamage = myPet.getDamage(); diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/EatGrass.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/EatGrass.java index 89cbae525e..ef2a849399 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/EatGrass.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/EatGrass.java @@ -51,7 +51,7 @@ public boolean shouldStart() { return false; } else if (entityMySheep.getRandom().nextInt(1000) != 0) { return false; - } else if (this.entityMySheep.getTarget() != null && !this.entityMySheep.getTarget().isDead()) { + } else if (this.entityMySheep.getMyPetTarget() != null && !this.entityMySheep.getMyPetTarget().isDead()) { return false; } int blockLocX = MathHelper.floor(this.entityMySheep.locX); diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/FollowOwner.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/FollowOwner.java index d664e8ef6b..9c47474fae 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/FollowOwner.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/FollowOwner.java @@ -59,7 +59,7 @@ public boolean shouldStart() { } if (!this.petEntity.canMove()) { return false; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } else if (this.petEntity.getOwner() == null) { return false; @@ -81,7 +81,7 @@ public boolean shouldFinish() { return true; } else if (!this.petEntity.canMove()) { return true; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return true; } return false; diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/LookAtPlayer.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/LookAtPlayer.java index ea7e436310..87e01b4848 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/LookAtPlayer.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/LookAtPlayer.java @@ -50,7 +50,7 @@ public boolean shouldStart() { if (this.petEntity.getRandom().nextFloat() >= this.lookAtPlayerChance) { return false; } - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/RandomLookaround.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/RandomLookaround.java index 7a6da393f6..1250160de9 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/RandomLookaround.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/RandomLookaround.java @@ -37,7 +37,7 @@ public RandomLookaround(EntityMyPet petEntity) { @Override public boolean shouldStart() { - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/Sprint.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/Sprint.java index e00b695723..9d2ccf1658 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/Sprint.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/movement/Sprint.java @@ -58,7 +58,7 @@ public boolean shouldStart() { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!targetEntity.isAlive()) { return false; diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorAggressiveTarget.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorAggressiveTarget.java index ba226bace6..017cde8a0b 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorAggressiveTarget.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorAggressiveTarget.java @@ -107,11 +107,11 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!petEntity.canMove()) { return true; - } else if (petEntity.getTarget() == null) { + } else if (petEntity.getMyPetTarget() == null) { return true; } - EntityLiving target = ((CraftLivingEntity) petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -133,7 +133,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); } @Override diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorDuelTarget.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorDuelTarget.java index cef6a52c66..88e543c827 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorDuelTarget.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorDuelTarget.java @@ -99,7 +99,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); Behavior behaviorSkill = myPet.getSkills().get(Behavior.class); if (behaviorSkill.getBehavior() != BehaviorMode.Duel) { @@ -118,7 +118,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget(this.target.getBukkitEntity(), TargetPriority.Duel); + petEntity.setMyPetTarget(this.target.getBukkitEntity(), TargetPriority.Duel); setDuelOpponent(this.target); if (target.getTargetSelector().hasGoal("DuelTarget")) { BehaviorDuelTarget duelGoal = (BehaviorDuelTarget) target.getTargetSelector().getGoal("DuelTarget"); diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorFarmTarget.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorFarmTarget.java index 9263b0a06a..bab5b156b4 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorFarmTarget.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/BehaviorFarmTarget.java @@ -87,7 +87,7 @@ public boolean shouldFinish() { if (!this.petEntity.hasTarget()) { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -109,7 +109,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); } @Override diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/ControlTarget.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/ControlTarget.java index 021918a57c..2b220f00b7 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/ControlTarget.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/ControlTarget.java @@ -129,7 +129,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -143,7 +143,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); } @Override diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/HurtByTarget.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/HurtByTarget.java index 359892ceba..60bee00a07 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/HurtByTarget.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/HurtByTarget.java @@ -98,7 +98,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -112,7 +112,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); } @Override diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/OwnerHurtByTarget.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/OwnerHurtByTarget.java index c5e30a8c08..f404c62e0a 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/OwnerHurtByTarget.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/ai/target/OwnerHurtByTarget.java @@ -125,7 +125,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -139,7 +139,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); + petEntity.setMyPetTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); } @Override diff --git a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/types/EntityMyRabbit.java b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/types/EntityMyRabbit.java index 21eb63e219..1f5f51c655 100644 --- a/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/types/EntityMyRabbit.java +++ b/modules/v1_12_R1/src/main/java/de/Keyle/MyPet/compat/v1_12_R1/entity/types/EntityMyRabbit.java @@ -98,7 +98,7 @@ public void onLivingUpdate() { if (this.onGround && getNavigation().l() != null && jumpDelay-- <= 0) { getControllerJump().a(); jumpDelay = (this.random.nextInt(10) + 10); - if (getTarget() != null) { + if (getMyPetTarget() != null) { jumpDelay /= 3; } this.world.broadcastEntityEffect(this, (byte) 1); diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/CraftMyPet.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/CraftMyPet.java index e35988e647..fdb186bd56 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/CraftMyPet.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/CraftMyPet.java @@ -165,7 +165,7 @@ public void forgetTarget() { @Override public void setTarget(LivingEntity target, TargetPriority priority) { - getHandle().setTarget(target, priority); + getHandle().setMyPetTarget(target, priority); } @Override diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/EntityMyPet.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/EntityMyPet.java index 5790a8752e..96fcf24553 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/EntityMyPet.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/EntityMyPet.java @@ -228,7 +228,7 @@ public TargetPriority getTargetPriority() { } @Override - public LivingEntity getTarget() { + public LivingEntity getMyPetTarget() { if (target != null) { if (target.isAlive()) { return (LivingEntity) target.getBukkitEntity(); @@ -239,7 +239,7 @@ public LivingEntity getTarget() { } @Override - public void setTarget(LivingEntity entity, TargetPriority priority) { + public void setMyPetTarget(LivingEntity entity, TargetPriority priority) { if (entity == null || entity.isDead() || entity instanceof ArmorStand || !(entity instanceof CraftLivingEntity)) { forgetTarget(); return; diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/attack/MeleeAttack.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/attack/MeleeAttack.java index 490a580be2..bb7628cd9c 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/attack/MeleeAttack.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/attack/MeleeAttack.java @@ -59,7 +59,7 @@ public boolean shouldStart() { if (!this.petEntity.hasTarget()) { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (targetEntity instanceof EntityArmorStand) { return false; @@ -93,7 +93,7 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!this.petEntity.hasTarget() || !this.petEntity.canMove()) { return true; - } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getTarget()) { + } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getMyPetTarget()) { return true; } if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.g(targetEntity.locX(), targetEntity.getBoundingBox().minY, targetEntity.locZ()) >= 20) { diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/attack/RangedAttack.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/attack/RangedAttack.java index cee906cbc4..52439b54f9 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/attack/RangedAttack.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/attack/RangedAttack.java @@ -63,7 +63,7 @@ public boolean shouldStart() { return false; } - EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getMyPetTarget()).getHandle(); if (target instanceof EntityArmorStand) { return false; @@ -102,7 +102,7 @@ public boolean shouldFinish() { if (!entityMyPet.hasTarget() || myPet.getRangedDamage() <= 0 || !entityMyPet.canMove()) { return true; } - if (this.target.getBukkitEntity() != entityMyPet.getTarget()) { + if (this.target.getBukkitEntity() != entityMyPet.getMyPetTarget()) { return true; } double meleeDamage = myPet.getDamage(); diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/EatGrass.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/EatGrass.java index a203ed0dc9..4a86b9f8c8 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/EatGrass.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/EatGrass.java @@ -52,7 +52,7 @@ public boolean shouldStart() { return false; } else if (entityMySheep.getRandom().nextInt(1000) != 0) { return false; - } else if (this.entityMySheep.getTarget() != null && !this.entityMySheep.getTarget().isDead()) { + } else if (this.entityMySheep.getMyPetTarget() != null && !this.entityMySheep.getMyPetTarget().isDead()) { return false; } int blockLocX = MathHelper.floor(this.entityMySheep.locX()); diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/FollowOwner.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/FollowOwner.java index 239efcdc35..6f8c610dc6 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/FollowOwner.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/FollowOwner.java @@ -60,7 +60,7 @@ public boolean shouldStart() { } if (!this.petEntity.canMove()) { return false; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } else if (this.petEntity.getOwner() == null) { return false; @@ -82,7 +82,7 @@ public boolean shouldFinish() { return true; } else if (!this.petEntity.canMove()) { return true; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return true; } return false; diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/LookAtPlayer.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/LookAtPlayer.java index 8fc353acb6..2c6d3e590d 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/LookAtPlayer.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/LookAtPlayer.java @@ -51,7 +51,7 @@ public boolean shouldStart() { if (this.petEntity.getRandom().nextFloat() >= this.lookAtPlayerChance) { return false; } - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/RandomLookaround.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/RandomLookaround.java index ce42e7cb2f..3c5af13de4 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/RandomLookaround.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/RandomLookaround.java @@ -38,7 +38,7 @@ public RandomLookaround(EntityMyPet petEntity) { @Override public boolean shouldStart() { - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/Sprint.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/Sprint.java index 4c1b7c9c1e..827aee058d 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/Sprint.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/movement/Sprint.java @@ -59,7 +59,7 @@ public boolean shouldStart() { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!targetEntity.isAlive()) { return false; diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorAggressiveTarget.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorAggressiveTarget.java index 66c97faa60..b5e68f685b 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorAggressiveTarget.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorAggressiveTarget.java @@ -108,11 +108,11 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!petEntity.canMove()) { return true; - } else if (petEntity.getTarget() == null) { + } else if (petEntity.getMyPetTarget() == null) { return true; } - EntityLiving target = ((CraftLivingEntity) petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -134,7 +134,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); } @Override diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorDuelTarget.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorDuelTarget.java index a354f21753..a6ca578774 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorDuelTarget.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorDuelTarget.java @@ -100,7 +100,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); Behavior behaviorSkill = myPet.getSkills().get(Behavior.class); if (behaviorSkill.getBehavior() != BehaviorMode.Duel) { @@ -119,7 +119,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget(this.target.getBukkitEntity(), TargetPriority.Duel); + petEntity.setMyPetTarget(this.target.getBukkitEntity(), TargetPriority.Duel); setDuelOpponent(this.target); if (target.getTargetSelector().hasGoal("DuelTarget")) { BehaviorDuelTarget duelGoal = (BehaviorDuelTarget) target.getTargetSelector().getGoal("DuelTarget"); diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorFarmTarget.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorFarmTarget.java index f994fc287b..af86e12062 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorFarmTarget.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/BehaviorFarmTarget.java @@ -88,7 +88,7 @@ public boolean shouldFinish() { if (!this.petEntity.hasTarget()) { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -110,7 +110,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); } @Override diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/ControlTarget.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/ControlTarget.java index 1d86df1031..0c37d005cc 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/ControlTarget.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/ControlTarget.java @@ -130,7 +130,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -144,7 +144,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); } @Override diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/HurtByTarget.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/HurtByTarget.java index fa04c3049f..5192311147 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/HurtByTarget.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/HurtByTarget.java @@ -99,7 +99,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -113,7 +113,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); } @Override diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/OwnerHurtByTarget.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/OwnerHurtByTarget.java index ba258dfc84..0fe84deafa 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/OwnerHurtByTarget.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/ai/target/OwnerHurtByTarget.java @@ -126,7 +126,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -140,7 +140,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); + petEntity.setMyPetTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); } @Override diff --git a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/types/EntityMyRabbit.java b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/types/EntityMyRabbit.java index c6ae649def..4963d26ab3 100644 --- a/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/types/EntityMyRabbit.java +++ b/modules/v1_16_R1/src/main/java/de/Keyle/MyPet/compat/v1_16_R1/entity/types/EntityMyRabbit.java @@ -101,7 +101,7 @@ public void onLivingUpdate() { if (this.onGround && getNavigation().k() != null && jumpDelay-- <= 0) { getControllerJump().jump(); jumpDelay = (this.random.nextInt(10) + 10); - if (getTarget() != null) { + if (getMyPetTarget() != null) { jumpDelay /= 3; } this.world.broadcastEntityEffect(this, (byte) 1); diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/CraftMyPet.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/CraftMyPet.java index 8ff6b97072..b00b5ec047 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/CraftMyPet.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/CraftMyPet.java @@ -200,7 +200,7 @@ public void forgetTarget() { @Override public void setTarget(LivingEntity target, TargetPriority priority) { - getHandle().setTarget(target, priority); + getHandle().setMyPetTarget(target, priority); } @Override diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/EntityMyPet.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/EntityMyPet.java index f9e08afb6d..c60e7f15a1 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/EntityMyPet.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/EntityMyPet.java @@ -20,13 +20,45 @@ package de.Keyle.MyPet.compat.v1_16_R3.entity; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_16_R3.attribute.CraftAttributeMap; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; + import com.google.common.base.Preconditions; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.compat.ParticleCompat; import de.Keyle.MyPet.api.entity.EntitySize; -import de.Keyle.MyPet.api.entity.*; +import de.Keyle.MyPet.api.entity.JumpHelper; +import de.Keyle.MyPet.api.entity.MyPet; +import de.Keyle.MyPet.api.entity.MyPetBaby; +import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; +import de.Keyle.MyPet.api.entity.MyPetType; import de.Keyle.MyPet.api.entity.ai.AIGoalSelector; import de.Keyle.MyPet.api.entity.ai.navigation.AbstractNavigation; import de.Keyle.MyPet.api.entity.ai.target.TargetPriority; @@ -43,40 +75,57 @@ import de.Keyle.MyPet.compat.v1_16_R3.PlatformHelper; import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.attack.MeleeAttack; import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.attack.RangedAttack; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.movement.Control; import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.movement.Float; -import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.movement.*; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.movement.FollowOwner; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.movement.LookAtPlayer; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.movement.RandomLookaround; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.movement.Sit; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.movement.Sprint; import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.navigation.VanillaNavigation; -import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.target.*; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.target.BehaviorAggressiveTarget; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.target.BehaviorDuelTarget; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.target.BehaviorFarmTarget; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.target.ControlTarget; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.target.HurtByTarget; +import de.Keyle.MyPet.compat.v1_16_R3.entity.ai.target.OwnerHurtByTarget; import de.Keyle.MyPet.compat.v1_16_R3.entity.types.EntityMyHorse; import de.Keyle.MyPet.skill.skills.ControlImpl; import de.Keyle.MyPet.skill.skills.RideImpl; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R3.attribute.CraftAttributeMap; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scheduler.BukkitRunnable; - -import java.lang.reflect.Field; -import java.math.BigDecimal; -import java.util.List; +import net.minecraft.server.v1_16_R3.AttributeMapBase; +import net.minecraft.server.v1_16_R3.AttributeProvider; +import net.minecraft.server.v1_16_R3.AxisAlignedBB; +import net.minecraft.server.v1_16_R3.BlockPosition; +import net.minecraft.server.v1_16_R3.DamageSource; +import net.minecraft.server.v1_16_R3.DataWatcherObject; +import net.minecraft.server.v1_16_R3.Entity; +import net.minecraft.server.v1_16_R3.EntityHuman; +import net.minecraft.server.v1_16_R3.EntityInsentient; +import net.minecraft.server.v1_16_R3.EntityLiving; +import net.minecraft.server.v1_16_R3.EntityPlayer; +import net.minecraft.server.v1_16_R3.EntityPose; +import net.minecraft.server.v1_16_R3.EntityTypes; +import net.minecraft.server.v1_16_R3.EnumHand; +import net.minecraft.server.v1_16_R3.EnumInteractionResult; +import net.minecraft.server.v1_16_R3.EnumMoveType; +import net.minecraft.server.v1_16_R3.GenericAttributes; +import net.minecraft.server.v1_16_R3.IBlockData; +import net.minecraft.server.v1_16_R3.IChatBaseComponent; +import net.minecraft.server.v1_16_R3.IJumpable; +import net.minecraft.server.v1_16_R3.IRegistry; +import net.minecraft.server.v1_16_R3.ItemStack; +import net.minecraft.server.v1_16_R3.Items; +import net.minecraft.server.v1_16_R3.MathHelper; +import net.minecraft.server.v1_16_R3.MinecraftKey; +import net.minecraft.server.v1_16_R3.NBTTagCompound; +import net.minecraft.server.v1_16_R3.PacketPlayOutAttachEntity; +import net.minecraft.server.v1_16_R3.PacketPlayOutNamedSoundEffect; +import net.minecraft.server.v1_16_R3.PotionUtil; +import net.minecraft.server.v1_16_R3.SoundCategory; +import net.minecraft.server.v1_16_R3.SoundEffect; +import net.minecraft.server.v1_16_R3.TagsFluid; +import net.minecraft.server.v1_16_R3.Vec3D; +import net.minecraft.server.v1_16_R3.World; public abstract class EntityMyPet extends EntityInsentient implements MyPetMinecraftEntity { @@ -228,7 +277,7 @@ public TargetPriority getTargetPriority() { } @Override - public LivingEntity getTarget() { + public LivingEntity getMyPetTarget() { if (target != null) { if (target.isAlive()) { return (LivingEntity) target.getBukkitEntity(); @@ -239,7 +288,7 @@ public LivingEntity getTarget() { } @Override - public void setTarget(LivingEntity entity, TargetPriority priority) { + public void setMyPetTarget(LivingEntity entity, TargetPriority priority) { if (entity == null || entity.isDead() || entity instanceof ArmorStand || !(entity instanceof CraftLivingEntity)) { forgetTarget(); return; diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/EntityRegistry.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/EntityRegistry.java index 04892176fe..c652587cab 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/EntityRegistry.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/EntityRegistry.java @@ -20,8 +20,19 @@ package de.Keyle.MyPet.compat.v1_16_R3.entity; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.ChatColor; +import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; +import org.bukkit.event.entity.CreatureSpawnEvent; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.MyPet; @@ -30,16 +41,15 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.api.util.ReflectionUtil; import lombok.SneakyThrows; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.ChatColor; -import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; -import org.bukkit.event.entity.CreatureSpawnEvent; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; +import net.minecraft.server.v1_16_R3.EntityLiving; +import net.minecraft.server.v1_16_R3.EntitySize; +import net.minecraft.server.v1_16_R3.EntityTypes; +import net.minecraft.server.v1_16_R3.EnumCreatureType; +import net.minecraft.server.v1_16_R3.IRegistry; +import net.minecraft.server.v1_16_R3.MinecraftKey; +import net.minecraft.server.v1_16_R3.RegistryBlocks; +import net.minecraft.server.v1_16_R3.RegistryMaterials; +import net.minecraft.server.v1_16_R3.World; @Compat("v1_16_R3") public class EntityRegistry extends de.Keyle.MyPet.api.entity.EntityRegistry { diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/attack/MeleeAttack.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/attack/MeleeAttack.java index 892bb96d0b..8d8950d61b 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/attack/MeleeAttack.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/attack/MeleeAttack.java @@ -59,7 +59,7 @@ public boolean shouldStart() { if (!this.petEntity.hasTarget()) { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (targetEntity instanceof EntityArmorStand) { return false; @@ -93,7 +93,7 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!this.petEntity.hasTarget() || !this.petEntity.canMove()) { return true; - } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getTarget()) { + } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getMyPetTarget()) { return true; } if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.h(targetEntity.locX(), targetEntity.getBoundingBox().minY, targetEntity.locZ()) >= 20) { diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/attack/RangedAttack.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/attack/RangedAttack.java index 059553dfac..2366cca82f 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/attack/RangedAttack.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/attack/RangedAttack.java @@ -63,7 +63,7 @@ public boolean shouldStart() { return false; } - EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getMyPetTarget()).getHandle(); if (target instanceof EntityArmorStand) { return false; @@ -102,7 +102,7 @@ public boolean shouldFinish() { if (!entityMyPet.hasTarget() || myPet.getRangedDamage() <= 0 || !entityMyPet.canMove()) { return true; } - if (this.target.getBukkitEntity() != entityMyPet.getTarget()) { + if (this.target.getBukkitEntity() != entityMyPet.getMyPetTarget()) { return true; } double meleeDamage = myPet.getDamage(); diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/EatGrass.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/EatGrass.java index 6bc90d5069..0b03f7c049 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/EatGrass.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/EatGrass.java @@ -52,7 +52,7 @@ public boolean shouldStart() { return false; } else if (entityMySheep.getRandom().nextInt(1000) != 0) { return false; - } else if (this.entityMySheep.getTarget() != null && !this.entityMySheep.getTarget().isDead()) { + } else if (this.entityMySheep.getMyPetTarget() != null && !this.entityMySheep.getMyPetTarget().isDead()) { return false; } int blockLocX = MathHelper.floor(this.entityMySheep.locX()); diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/FollowOwner.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/FollowOwner.java index 5d823ab420..7089ec8fc4 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/FollowOwner.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/FollowOwner.java @@ -60,7 +60,7 @@ public boolean shouldStart() { } if (!this.petEntity.canMove()) { return false; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } else if (this.petEntity.getOwner() == null) { return false; @@ -79,7 +79,7 @@ public boolean shouldFinish() { return true; } else if (!this.petEntity.canMove()) { return true; - } else return this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead(); + } else return this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead(); } @Override diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/LookAtPlayer.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/LookAtPlayer.java index a40055f550..f64f1db0ac 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/LookAtPlayer.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/LookAtPlayer.java @@ -51,7 +51,7 @@ public boolean shouldStart() { if (this.petEntity.getRandom().nextFloat() >= this.lookAtPlayerChance) { return false; } - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/RandomLookaround.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/RandomLookaround.java index 62e4c205c7..bc0ebb5636 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/RandomLookaround.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/RandomLookaround.java @@ -38,7 +38,7 @@ public RandomLookaround(EntityMyPet petEntity) { @Override public boolean shouldStart() { - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/Sprint.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/Sprint.java index b4df44a528..ca10482be8 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/Sprint.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/movement/Sprint.java @@ -59,7 +59,7 @@ public boolean shouldStart() { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!targetEntity.isAlive()) { return false; diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorAggressiveTarget.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorAggressiveTarget.java index 071426fb68..67bb7da590 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorAggressiveTarget.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorAggressiveTarget.java @@ -108,11 +108,11 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!petEntity.canMove()) { return true; - } else if (petEntity.getTarget() == null) { + } else if (petEntity.getMyPetTarget() == null) { return true; } - EntityLiving target = ((CraftLivingEntity) petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -131,7 +131,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); } @Override diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorDuelTarget.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorDuelTarget.java index 1af0d44d10..f478c0089c 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorDuelTarget.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorDuelTarget.java @@ -100,7 +100,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); Behavior behaviorSkill = myPet.getSkills().get(Behavior.class); if (behaviorSkill.getBehavior() != BehaviorMode.Duel) { @@ -116,7 +116,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget(this.target.getBukkitEntity(), TargetPriority.Duel); + petEntity.setMyPetTarget(this.target.getBukkitEntity(), TargetPriority.Duel); setDuelOpponent(this.target); if (target.getTargetSelector().hasGoal("DuelTarget")) { BehaviorDuelTarget duelGoal = (BehaviorDuelTarget) target.getTargetSelector().getGoal("DuelTarget"); diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorFarmTarget.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorFarmTarget.java index a05f0cc8c7..8230e4a1fa 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorFarmTarget.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/BehaviorFarmTarget.java @@ -88,7 +88,7 @@ public boolean shouldFinish() { if (!this.petEntity.hasTarget()) { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -107,7 +107,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); } @Override diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/ControlTarget.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/ControlTarget.java index 2e12e3e778..88c8c21825 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/ControlTarget.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/ControlTarget.java @@ -20,6 +20,11 @@ package de.Keyle.MyPet.compat.v1_16_R3.entity.ai.target; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.ai.AIGoal; @@ -33,10 +38,6 @@ import net.minecraft.server.v1_16_R3.EntityLiving; import net.minecraft.server.v1_16_R3.EntityPlayer; import net.minecraft.server.v1_16_R3.EntityTameableAnimal; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; @Compat("v1_16_R3") public class ControlTarget implements AIGoal { @@ -130,7 +131,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -141,7 +142,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); } @Override diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/HurtByTarget.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/HurtByTarget.java index 5603928f06..b8cbc622cb 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/HurtByTarget.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/HurtByTarget.java @@ -99,7 +99,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -110,7 +110,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); } @Override diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/OwnerHurtByTarget.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/OwnerHurtByTarget.java index a780570022..c2370912c8 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/OwnerHurtByTarget.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/ai/target/OwnerHurtByTarget.java @@ -124,7 +124,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -135,7 +135,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); + petEntity.setMyPetTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); } @Override diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/types/EntityMyRabbit.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/types/EntityMyRabbit.java index f35a00a4ac..442c291a1a 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/types/EntityMyRabbit.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/entity/types/EntityMyRabbit.java @@ -101,7 +101,7 @@ public void onLivingUpdate() { if (this.onGround && getNavigation().k() != null && jumpDelay-- <= 0) { getControllerJump().jump(); jumpDelay = (this.random.nextInt(10) + 10); - if (getTarget() != null) { + if (getMyPetTarget() != null) { jumpDelay /= 3; } this.world.broadcastEntityEffect(this, (byte) 1); diff --git a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/skill/skills/ranged/nms/MyPetArrow.java b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/skill/skills/ranged/nms/MyPetArrow.java index 5db0054963..6985ecace0 100644 --- a/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/skill/skills/ranged/nms/MyPetArrow.java +++ b/modules/v1_16_R3/src/main/java/de/Keyle/MyPet/compat/v1_16_R3/skill/skills/ranged/nms/MyPetArrow.java @@ -24,7 +24,12 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_16_R3.skill.skills.ranged.bukkit.CraftMyPetArrow; -import net.minecraft.server.v1_16_R3.*; +import net.minecraft.server.v1_16_R3.DamageSource; +import net.minecraft.server.v1_16_R3.EntityTippedArrow; +import net.minecraft.server.v1_16_R3.ItemStack; +import net.minecraft.server.v1_16_R3.Items; +import net.minecraft.server.v1_16_R3.NBTTagCompound; +import net.minecraft.server.v1_16_R3.World; @Compat("v1_16_R3") public class MyPetArrow extends EntityTippedArrow implements EntityMyPetProjectile { diff --git a/modules/v1_17_R1/pom.xml b/modules/v1_17_R1/pom.xml index f42b8156a7..f7123d83f7 100644 --- a/modules/v1_17_R1/pom.xml +++ b/modules/v1_17_R1/pom.xml @@ -16,18 +16,12 @@ MyPet-v1_17_R1 - - org.spigotmc - spigot-api - 1.17.1-R0.1-SNAPSHOT - provided - true - org.spigotmc spigot 1.17.1-R0.1-SNAPSHOT provided + remapped-mojang true @@ -73,6 +67,39 @@ true + + net.md-5 + specialsource-maven-plugin + 1.2.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf + + + + diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/CompatManager.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/CompatManager.java index 2d9d2f9443..de402f7b38 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/CompatManager.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/CompatManager.java @@ -20,6 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1; +import java.lang.reflect.Method; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityToggleGlideEvent; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.util.Compat; @@ -27,20 +35,13 @@ import de.Keyle.MyPet.compat.v1_17_R1.services.EggIconService; import de.Keyle.MyPet.compat.v1_17_R1.services.EntityConverterService; import de.Keyle.MyPet.compat.v1_17_R1.services.RepositoryMyPetConverterService; -import net.minecraft.world.EnumHand; -import net.minecraft.world.entity.EntityLiving; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityToggleGlideEvent; - -import java.lang.reflect.Method; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.LivingEntity; @Compat("v1_17_R1") public class CompatManager extends de.Keyle.MyPet.api.util.CompatManager implements Listener { - public static Method ENTITY_LIVING_broadcastItemBreak = ReflectionUtil.getMethod(EntityLiving.class, "d", EnumHand.class); + public static Method ENTITY_LIVING_broadcastItemBreak = ReflectionUtil.getMethod(LivingEntity.class, "d", InteractionHand.class); @Override public void init() { diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/PlatformHelper.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/PlatformHelper.java index 1b0679d02e..83828c58dc 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/PlatformHelper.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/PlatformHelper.java @@ -39,7 +39,6 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Villager; -import org.bukkit.entity.WanderingTrader; import org.bukkit.entity.Zombie; import com.mojang.brigadier.StringReader; @@ -54,57 +53,54 @@ import de.Keyle.MyPet.api.util.inventory.material.ItemDatabase; import de.Keyle.MyPet.compat.v1_17_R1.util.inventory.ItemStackNBTConverter; import de.keyle.knbt.TagCompound; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.IRegistry; -import net.minecraft.core.particles.Particle; -import net.minecraft.core.particles.ParticleParam; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.chat.ChatMessage; -import net.minecraft.network.chat.ChatMessageType; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutChat; -import net.minecraft.network.protocol.game.PacketPlayOutCollect; -import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.network.protocol.game.PacketPlayOutWorldParticles; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.server.level.ChunkProviderServer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.sounds.SoundCategory; -import net.minecraft.sounds.SoundEffects; -import net.minecraft.util.MathHelper; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EntityLightning; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.npc.EntityVillager; -import net.minecraft.world.entity.npc.EntityVillagerTrader; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemAxe; -import net.minecraft.world.item.ItemBow; -import net.minecraft.world.item.ItemCarrotStick; -import net.minecraft.world.item.ItemCompass; -import net.minecraft.world.item.ItemCrossbow; -import net.minecraft.world.item.ItemFishingRod; -import net.minecraft.world.item.ItemHoe; -import net.minecraft.world.item.ItemPickaxe; -import net.minecraft.world.item.ItemShield; -import net.minecraft.world.item.ItemSign; -import net.minecraft.world.item.ItemSpade; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import net.minecraft.network.protocol.game.ClientboundChatPacket; +import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket; +import net.minecraft.network.protocol.game.ClientboundSoundPacket; +import net.minecraft.network.protocol.game.ClientboundTakeItemEntityPacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerChunkCache; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.AxeItem; +import net.minecraft.world.item.BowItem; +import net.minecraft.world.item.CompassItem; +import net.minecraft.world.item.CrossbowItem; +import net.minecraft.world.item.FishingRodItem; +import net.minecraft.world.item.FoodOnAStickItem; +import net.minecraft.world.item.HoeItem; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.ItemSword; -import net.minecraft.world.item.ItemTrident; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.phys.AxisAlignedBB; +import net.minecraft.world.item.PickaxeItem; +import net.minecraft.world.item.ShieldItem; +import net.minecraft.world.item.ShovelItem; +import net.minecraft.world.item.SignItem; +import net.minecraft.world.item.SwordItem; +import net.minecraft.world.item.TridentItem; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.shapes.VoxelShape; @Compat("v1_17_R1") public class PlatformHelper extends de.Keyle.MyPet.api.PlatformHelper { - private static final Method ENTITY_LIVING_cD = ReflectionUtil.getMethod(EntityLiving.class, "cT"); - private static final Method CHAT_MESSAGE_k = ReflectionUtil.getMethod(ChatMessage.class, "k"); + private static final Method ENTITY_LIVING_cD = ReflectionUtil.getMethod(net.minecraft.world.entity.LivingEntity.class, "cT"); + private static final Method CHAT_MESSAGE_k = ReflectionUtil.getMethod(TranslatableComponent.class, "k"); /** * @param location the {@link Location} around which players must be to see the effect @@ -118,33 +114,33 @@ public class PlatformHelper extends de.Keyle.MyPet.api.PlatformHelper { */ @Override public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat data) { - Particle effect = IRegistry.ab.get(new MinecraftKey(effectName)); + ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName)); Validate.notNull(location, "Location cannot be null"); Validate.notNull(effect, "Effect cannot be null"); Validate.notNull(location.getWorld(), "World cannot be null"); - ParticleParam particle = null; + ParticleOptions particle = null; - if (effect.d() != null && data != null) { + if (effect.getDeserializer() != null && data != null) { try { - particle = effect.d().b(effect, new StringReader(" " + data.get().toString())); + particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString())); } catch (CommandSyntaxException e) { e.printStackTrace(); } - } else if (effect instanceof ParticleType) { - particle = (ParticleType) effect; + } else if (effect instanceof SimpleParticleType) { + particle = (SimpleParticleType) effect; } if (particle == null) { return; } - PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count); + ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count); radius = radius * radius; for (Player player : location.getWorld().getPlayers()) { if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) { - ((CraftPlayer) player).getHandle().b.sendPacket(packet); + ((CraftPlayer) player).getHandle().connection.send(packet); } } @@ -162,69 +158,69 @@ public void playParticleEffect(Location location, String effectName, float offse */ @Override public void playParticleEffect(Player player, Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat data) { - Particle effect = IRegistry.ab.get(new MinecraftKey(effectName)); + ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName)); Validate.notNull(location, "Location cannot be null"); Validate.notNull(effect, "Effect cannot be null"); Validate.notNull(location.getWorld(), "World cannot be null"); - ParticleParam particle = null; + ParticleOptions particle = null; - if (effect.d() != null && data != null) { + if (effect.getDeserializer() != null && data != null) { try { - particle = effect.d().b(effect, new StringReader(" " + data.get().toString())); + particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString())); } catch (CommandSyntaxException e) { e.printStackTrace(); } - } else if (effect instanceof ParticleType) { - particle = (ParticleType) effect; + } else if (effect instanceof SimpleParticleType) { + particle = (SimpleParticleType) effect; } if (particle == null) { return; } - PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count); + ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count); if (MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) { - ((CraftPlayer) player).getHandle().b.sendPacket(packet); + ((CraftPlayer) player).getHandle().connection.send(packet); } } @Override public boolean canSpawn(Location loc, MyPetMinecraftEntity entity) { - return canSpawn(loc, ((EntityLiving) entity).getBoundingBox()); + return canSpawn(loc, ((net.minecraft.world.entity.LivingEntity) entity).getBoundingBox()); } - public Boolean canSpawn(Location loc, AxisAlignedBB bb) { - net.minecraft.world.level.World mcWorld = ((CraftWorld) loc.getWorld()).getHandle(); - return getBlockBBsInBB(mcWorld, bb).isEmpty() && !mcWorld.containsLiquid(bb); + public Boolean canSpawn(Location loc, AABB bb) { + net.minecraft.world.level.Level mcWorld = ((CraftWorld) loc.getWorld()).getHandle(); + return getBlockBBsInBB(mcWorld, bb).isEmpty() && !mcWorld.containsAnyLiquid(bb); } - public List getBlockBBsInBB(net.minecraft.world.level.World world, AxisAlignedBB axisalignedbb) { + public List getBlockBBsInBB(net.minecraft.world.level.Level world, AABB axisalignedbb) { UnsafeList unsafeList = new UnsafeList(); - int minX = MathHelper.floor(axisalignedbb.a); - int maxX = (int) Math.ceil(axisalignedbb.d); - int minY = MathHelper.floor(axisalignedbb.b); - int maxY = (int) Math.ceil(axisalignedbb.e); - int minZ = MathHelper.floor(axisalignedbb.c); - int maxZ = (int) Math.ceil(axisalignedbb.f); + int minX = Mth.floor(axisalignedbb.minX); + int maxX = (int) Math.ceil(axisalignedbb.maxX); + int minY = Mth.floor(axisalignedbb.minY); + int maxY = (int) Math.ceil(axisalignedbb.maxY); + int minZ = Mth.floor(axisalignedbb.minZ); + int maxZ = (int) Math.ceil(axisalignedbb.maxZ); VoxelShape vec3d; boolean isEmpty; for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { - if (((ChunkProviderServer) world.getChunkProvider()).isLoaded(x >> 4, z >> 4)) { + if (((ServerChunkCache) world.getChunkSource()).hasChunk(x >> 4, z >> 4)) { for (int y = minY - 1; y <= maxY; y++) { - BlockPosition bp = new BlockPosition(x, y, z); - IBlockData blockData = world.getType(bp); + BlockPos bp = new BlockPos(x, y, z); + BlockState blockData = world.getBlockState(bp); if (blockData != null && blockData.getMaterial().isSolid()) { vec3d = blockData.getCollisionShape(world, bp); isEmpty = vec3d.isEmpty(); if (!isEmpty) { - for (AxisAlignedBB bb : vec3d.toList()) { - if (bb.a(bp).c(axisalignedbb)) { + for (AABB bb : vec3d.toAabbs()) { + if (bb.move(bp).intersects(axisalignedbb)) { unsafeList.add(bb); } } @@ -249,12 +245,12 @@ public String getPlayerLanguage(Player player) { @Override public TagCompound entityToTag(Entity bukkitEntity) { net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkitEntity).getHandle(); - NBTTagCompound vanillaNBT = new NBTTagCompound(); + CompoundTag vanillaNBT = new CompoundTag(); - if (entity instanceof EntityLiving) { - ((EntityLiving) entity).saveData(vanillaNBT); + if (entity instanceof net.minecraft.world.entity.LivingEntity) { + ((net.minecraft.world.entity.LivingEntity) entity).addAdditionalSaveData(vanillaNBT); } else { - Method b = ReflectionUtil.getMethod(entity.getClass(), "b", NBTTagCompound.class); + Method b = ReflectionUtil.getMethod(entity.getClass(), "b", CompoundTag.class); try { b.invoke(entity, vanillaNBT); } catch (IllegalAccessException | InvocationTargetException e) { @@ -268,14 +264,14 @@ public TagCompound entityToTag(Entity bukkitEntity) { @Override public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) { net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkitEntity).getHandle(); - NBTTagCompound vanillaNBT = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag); + CompoundTag vanillaNBT = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(tag); if (vanillaNBT != null) { if (bukkitEntity instanceof Villager) { - EntityVillager villager = (EntityVillager) entity; - villager.a(vanillaNBT); - } else if (bukkitEntity instanceof WanderingTrader) { - EntityVillagerTrader villager = (EntityVillagerTrader) entity; - villager.saveData(vanillaNBT); + net.minecraft.world.entity.npc.Villager villager = (net.minecraft.world.entity.npc.Villager) entity; + villager.readAdditionalSaveData(vanillaNBT); + } else if (bukkitEntity instanceof net.minecraft.world.entity.npc.WanderingTrader) { + net.minecraft.world.entity.npc.WanderingTrader villager = (net.minecraft.world.entity.npc.WanderingTrader) entity; + villager.addAdditionalSaveData(vanillaNBT); } } } @@ -293,15 +289,15 @@ public org.bukkit.inventory.ItemStack compundToItemStack(TagCompound compound) { @Override public void sendMessageRaw(Player player, String message) { if (player instanceof CraftPlayer) { - ((CraftPlayer) player).getHandle().b.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(message), ChatMessageType.a, player.getUniqueId())); + ((CraftPlayer) player).getHandle().connection.send(new ClientboundChatPacket(Component.Serializer.fromJson(message), ChatType.CHAT, player.getUniqueId())); } } @Override public void sendMessageActionBar(Player player, String message) { if (player instanceof CraftPlayer) { - IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + Util.escapeJsonString(message) + "\"}"); - ((CraftPlayer) player).getHandle().b.sendPacket(new PacketPlayOutChat(cbc, ChatMessageType.c, player.getUniqueId())); + Component cbc = Component.Serializer.fromJson("{\"text\": \"" + Util.escapeJsonString(message) + "\"}"); + ((CraftPlayer) player).getHandle().connection.send(new ClientboundChatPacket(cbc, ChatType.GAME_INFO, player.getUniqueId())); } } @@ -311,9 +307,9 @@ public void addZombieTargetGoal(Zombie zombie) { @Override public boolean comparePlayerWithEntity(MyPetPlayer player, Object obj) { - if (obj instanceof EntityHuman && player != null && player.getPlayer() != null) { - EntityHuman entityHuman = (EntityHuman) obj; - return player.getPlayer().getUniqueId().equals(entityHuman.getUniqueID()); + if (obj instanceof net.minecraft.world.entity.player.Player && player != null && player.getPlayer() != null) { + net.minecraft.world.entity.player.Player entityHuman = (net.minecraft.world.entity.player.Player) obj; + return player.getPlayer().getUniqueId().equals(entityHuman.getUUID()); } return false; } @@ -322,33 +318,33 @@ public boolean comparePlayerWithEntity(MyPetPlayer player, Object obj) { public boolean isEquipment(org.bukkit.inventory.ItemStack itemStack) { { ItemStack itemstack = CraftItemStack.asNMSCopy(itemStack); - int slot = EntityInsentient.getEquipmentSlotForItem(itemstack).getSlotFlag(); + int slot = Mob.getEquipmentSlotForItem(itemstack).getFilterFlag(); if (slot == 0) { - if (itemstack.getItem() instanceof ItemSword) { + if (itemstack.getItem() instanceof SwordItem) { return true; - } else if (itemstack.getItem() instanceof ItemAxe) { + } else if (itemstack.getItem() instanceof AxeItem) { return true; - } else if (itemstack.getItem() instanceof ItemSpade) { + } else if (itemstack.getItem() instanceof ShovelItem) { return true; - } else if (itemstack.getItem() instanceof ItemHoe) { + } else if (itemstack.getItem() instanceof HoeItem) { return true; - } else if (itemstack.getItem() instanceof ItemPickaxe) { + } else if (itemstack.getItem() instanceof PickaxeItem) { return true; - } else if (itemstack.getItem() instanceof ItemBow) { + } else if (itemstack.getItem() instanceof BowItem) { return true; - } else if (itemstack.getItem() instanceof ItemShield) { + } else if (itemstack.getItem() instanceof ShieldItem) { return true; - } else if (itemstack.getItem() instanceof ItemTrident) { + } else if (itemstack.getItem() instanceof TridentItem) { return true; - } else if (itemstack.getItem() instanceof ItemFishingRod) { + } else if (itemstack.getItem() instanceof FishingRodItem) { return true; - } else if (itemstack.getItem() instanceof ItemCompass) { + } else if (itemstack.getItem() instanceof CompassItem) { return true; - } else if (itemstack.getItem() instanceof ItemCarrotStick) { + } else if (itemstack.getItem() instanceof FoodOnAStickItem) { return true; - } else if (itemstack.getItem() instanceof ItemSign) { + } else if (itemstack.getItem() instanceof SignItem) { return true; - } else return itemstack.getItem() instanceof ItemCrossbow; + } else return itemstack.getItem() instanceof CrossbowItem; } return true; } @@ -357,18 +353,18 @@ public boolean isEquipment(org.bukkit.inventory.ItemStack itemStack) { @Override public String getVanillaName(org.bukkit.inventory.ItemStack bukkitItemStack) { ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItemStack); - return itemStack.getItem().getName(); + return itemStack.getItem().getDescriptionId(); } @Override public void doPickupAnimation(Entity entity, Entity target) { int count = 1; - if (target instanceof EntityItem) { - count = ((EntityItem) target).getItemStack().getCount(); + if (target instanceof ItemEntity) { + count = ((ItemEntity) target).getItem().getCount(); } for (Entity p : target.getNearbyEntities(10, 10, 10)) { if (p instanceof Player) { - ((CraftPlayer) p).getHandle().b.sendPacket(new PacketPlayOutCollect(target.getEntityId(), entity.getEntityId(), count)); + ((CraftPlayer) p).getHandle().connection.send(new ClientboundTakeItemEntityPacket(target.getEntityId(), entity.getEntityId(), count)); } } } @@ -396,35 +392,35 @@ public ItemStack asNmsItemStack(org.bukkit.inventory.ItemStack itemStack) { return CraftItemStack.asNMSCopy(itemStack); } - public net.minecraft.world.level.World getWorldNMS(World world) { + public Level getWorldNMS(World world) { return ((CraftWorld) world).getHandle(); } @Override public void strikeLightning(Location loc, float distance) { - WorldServer world = ((CraftWorld) loc.getWorld()).getHandle(); - EntityLightning lightning = new EntityLightning(EntityTypes.U, world); - lightning.setEffect(true); - lightning.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), 0.0F, 0.0F); + ServerLevel world = ((CraftWorld) loc.getWorld()).getHandle(); + LightningBolt lightning = new LightningBolt(EntityType.LIGHTNING_BOLT, world); + lightning.setVisualOnly(true); + lightning.moveTo(loc.getX(), loc.getY(), loc.getZ(), 0.0F, 0.0F); world.getCraftServer() .getServer() .getPlayerList() - .sendPacketNearby(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.getDimensionKey(), - new PacketPlayOutSpawnEntity(lightning)); + .broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), + new ClientboundAddEntityPacket(lightning)); world.getCraftServer() .getServer() .getPlayerList() - .sendPacketNearby(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.getDimensionKey(), - new PacketPlayOutNamedSoundEffect(SoundEffects.jL, SoundCategory.d, loc.getX(), loc.getY(), loc.getZ(), distance, 1F)); + .broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), + new ClientboundSoundPacket(SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, loc.getX(), loc.getY(), loc.getZ(), distance, 1F)); } @Override public String getLastDamageSource(LivingEntity e) { - EntityLiving el = ((CraftLivingEntity) e).getHandle(); - if (el.dW() == null) { + net.minecraft.world.entity.LivingEntity el = ((CraftLivingEntity) e).getHandle(); + if (el.getLastDamageSource() == null) { return null; } - return ((ChatMessage) el.dW().getLocalizedDeathMessage(el)).getKey(); + return ((TranslatableComponent) el.getLastDamageSource().getLocalizedDeathMessage(el)).getKey(); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/CraftMyPet.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/CraftMyPet.java index 6b36fe7802..bfde17e278 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/CraftMyPet.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/CraftMyPet.java @@ -97,7 +97,7 @@ public MyPetPlayer getOwner() { @Override public void removeEntity() { - getHandle().die(); + getHandle().discard(); } @Override @@ -201,7 +201,7 @@ public void forgetTarget() { @Override public void setTarget(LivingEntity target, TargetPriority priority) { - getHandle().setTarget(target, priority); + getHandle().setMyPetTarget(target, priority); } @Override @@ -218,45 +218,45 @@ public FakeEquipment(CraftLivingEntity entity) { @NotNull @Override public ItemStack getItemInMainHand() { - return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.b); + return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.EMPTY); } @NotNull @Override public ItemStack getItemInOffHand() { - return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.b); + return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.EMPTY); } @NotNull @Override public ItemStack getItemInHand() { - return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.b); + return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.EMPTY); } @Override public ItemStack getHelmet() { - return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.b); + return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.EMPTY); } @Override public ItemStack getChestplate() { - return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.b); + return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.EMPTY); } @Override public ItemStack getLeggings() { - return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.b); + return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.EMPTY); } @Override public ItemStack getBoots() { - return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.b); + return CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.EMPTY); } @NotNull @Override public ItemStack[] getArmorContents() { - ItemStack empty = CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.b); + ItemStack empty = CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.EMPTY); return new ItemStack[]{empty, empty, empty, empty}; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPet.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPet.java index e0937d0bf6..b0be80a782 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPet.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPet.java @@ -23,6 +23,7 @@ import java.lang.reflect.Field; import java.math.BigDecimal; import java.util.List; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -36,7 +37,6 @@ import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -92,50 +92,47 @@ import de.Keyle.MyPet.compat.v1_17_R1.entity.types.EntityMyHorse; import de.Keyle.MyPet.skill.skills.ControlImpl; import de.Keyle.MyPet.skill.skills.RideImpl; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.IRegistry; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity; -import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.sounds.SoundCategory; -import net.minecraft.sounds.SoundEffect; -import net.minecraft.tags.TagsFluid; -import net.minecraft.util.MathHelper; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket; +import net.minecraft.network.protocol.game.ClientboundSoundPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; +import net.minecraft.tags.FluidTags; +import net.minecraft.util.Mth; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityPose; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.EnumMoveType; -import net.minecraft.world.entity.IJumpable; -import net.minecraft.world.entity.ai.attributes.AttributeMapBase; -import net.minecraft.world.entity.ai.attributes.AttributeProvider; -import net.minecraft.world.entity.ai.attributes.GenericAttributes; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.PlayerRideableJumping; +import net.minecraft.world.entity.Pose; +import net.minecraft.world.entity.ai.attributes.AttributeMap; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.item.alchemy.PotionUtil; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.phys.AxisAlignedBB; -import net.minecraft.world.phys.Vec3D; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; -public abstract class EntityMyPet extends EntityInsentient implements MyPetMinecraftEntity { +public abstract class EntityMyPet extends Mob implements MyPetMinecraftEntity { - protected static final DataWatcherObject POTION_PARTICLE_WATCHER = EntityInsentient.aB; - + protected static final EntityDataAccessor POTION_PARTICLE_WATCHER = Mob.DATA_SHARED_FLAGS_ID; protected AIGoalSelector petPathfinderSelector, petTargetSelector; - protected EntityLiving target = null; + protected LivingEntity target = null; protected TargetPriority targetPriority = TargetPriority.None; protected double walkSpeed = 0.3F; protected boolean hasRider = false; @@ -155,11 +152,11 @@ public abstract class EntityMyPet extends EntityInsentient implements MyPetMinec protected float limitCounter = 0; protected DamageSource deathReason = null; protected CraftMyPet bukkitEntity = null; - protected AttributeMapBase attributeMap; + protected AttributeMap attributeMap; - private static final Field jump = ReflectionUtil.getField(EntityLiving.class, "jumping"); + private static final Field jump = ReflectionUtil.getField(LivingEntity.class, "jumping"); - public EntityMyPet(World world, MyPet myPet) { + public EntityMyPet(Level world, MyPet myPet) { super(((EntityRegistry) MyPetApi.getEntityRegistry()).getEntityType(myPet.getPetType()), world); try { @@ -167,16 +164,16 @@ public EntityMyPet(World world, MyPet myPet) { this.myPet = myPet; this.isMyPet = true; - this.updateSize(); + this.refreshDimensions(); this.petPathfinderSelector = new AIGoalSelector(0); this.petTargetSelector = new AIGoalSelector(Configuration.Entity.SKIP_TARGET_AI_TICKS); this.walkSpeed = MyPetApi.getMyPetInfo().getSpeed(myPet.getPetType()); this.petNavigation = new VanillaNavigation(this); this.sitPathfinder = new Sit(this); - this.getAttributeInstance(GenericAttributes.a).setValue(Integer.MAX_VALUE); + this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(Integer.MAX_VALUE); this.setHealth((float) myPet.getHealth()); this.updateNameTag(); - this.getAttributeInstance(GenericAttributes.d).setValue(walkSpeed); + this.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(walkSpeed); this.setPathfinder(); this.updateVisuals(); } catch (Exception e) { @@ -185,8 +182,8 @@ public EntityMyPet(World world, MyPet myPet) { } protected void replaceCraftAttributes() { - Field craftAttributesField = ReflectionUtil.getField(EntityLiving.class, "craftAttributes"); - CraftAttributeMap craftAttributes = new CraftAttributeMap(this.getAttributeMap()); + Field craftAttributesField = ReflectionUtil.getField(LivingEntity.class, "craftAttributes"); + CraftAttributeMap craftAttributes = new CraftAttributeMap(this.getAttributes()); ReflectionUtil.setFinalFieldValue(craftAttributesField, this, craftAttributes); } @@ -204,7 +201,7 @@ public void setPathfinder() { petPathfinderSelector.addGoal("Sit", sitPathfinder); petPathfinderSelector.addGoal("Sprint", new Sprint(this, 0.25F)); petPathfinderSelector.addGoal("RangedTarget", new RangedAttack(this, -0.1F, 12.0F)); - petPathfinderSelector.addGoal("MeleeAttack", new MeleeAttack(this, 0.1F, this.getWidth() + 1.3, 20)); + petPathfinderSelector.addGoal("MeleeAttack", new MeleeAttack(this, 0.1F, this.getBbWidth() + 1.3, 20)); petPathfinderSelector.addGoal("Control", new Control(this, 0.1F)); petPathfinderSelector.addGoal("FollowOwner", new FollowOwner(this, Configuration.Entity.MYPET_FOLLOW_START_DISTANCE, 2.0F, 16F)); petPathfinderSelector.addGoal("LookAtPlayer", new LookAtPlayer(this, 8.0F)); @@ -218,18 +215,18 @@ public void setPathfinder() { } @Override - public AttributeMapBase getAttributeMap() { + public AttributeMap getAttributes() { if (attributeMap == null) { EntityRegistry entityRegistry = (EntityRegistry) MyPetApi.getEntityRegistry(); MyPetType type = entityRegistry.getMyPetType(this.getClass()); - EntityTypes types = entityRegistry.entityTypes.get(type); - AttributeProvider attributeProvider = MyAttributeDefaults.getAttribute(types); - this.attributeMap = new AttributeMapBase(attributeProvider); + EntityType types = entityRegistry.entityTypes.get(type); + AttributeSupplier attributeProvider = MyAttributeDefaults.getAttribute(types); + this.attributeMap = new AttributeMap(attributeProvider); } return attributeMap; } - public static void setupAttributes(EntityMyPet pet, EntityTypes types) { + public static void setupAttributes(EntityMyPet pet, EntityType types) { pet.initAttributes(); } @@ -250,7 +247,8 @@ public boolean hasRider() { @Override public void setLocation(Location loc) { - this.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getPitch(), loc.getYaw()); + this.setPos(loc.getX(), loc.getY(), loc.getZ()); + this.setRot(loc.getPitch(), loc.getYaw()); } @Override @@ -280,10 +278,10 @@ public TargetPriority getTargetPriority() { } @Override - public LivingEntity getTarget() { + public org.bukkit.entity.LivingEntity getMyPetTarget() { if (target != null) { if (target.isAlive()) { - return (LivingEntity) target.getBukkitEntity(); + return (org.bukkit.entity.LivingEntity) target.getBukkitEntity(); } target = null; } @@ -291,7 +289,7 @@ public LivingEntity getTarget() { } @Override - public void setTarget(LivingEntity entity, TargetPriority priority) { + public void setMyPetTarget(org.bukkit.entity.LivingEntity entity, TargetPriority priority) { if (entity == null || entity.isDead() || entity instanceof ArmorStand || !(entity instanceof CraftLivingEntity)) { forgetTarget(); return; @@ -312,21 +310,21 @@ public void forgetTarget() { } @Override - public void setCustomName(IChatBaseComponent ignored) { + public void setCustomName(Component ignored) { updateNameTag(); } @Override public void updateNameTag() { try { - if (getCustomNameVisible()) { + if (isCustomNameVisible()) { String prefix = Configuration.Name.Tag.PREFIX; String suffix = Configuration.Name.Tag.SUFFIX; prefix = prefix.replace("", getOwner().getName()); prefix = prefix.replace("", "" + getMyPet().getExperience().getLevel()); suffix = suffix.replace("", getOwner().getName()); suffix = suffix.replace("", "" + getMyPet().getExperience().getLevel()); - this.setCustomNameVisible(getCustomNameVisible()); + this.setCustomNameVisible(isCustomNameVisible()); String name = myPet.getPetName(); if (!Permissions.has(getOwner(), "MyPet.command.name.color")) { name = ChatColor.stripColor(name); @@ -339,7 +337,7 @@ public void updateNameTag() { } @Override - public IChatBaseComponent getCustomName() { + public Component getCustomName() { try { return CraftChatMessage.fromStringOrNull(myPet.getPetName()); } catch (Exception e) { @@ -348,7 +346,7 @@ public IChatBaseComponent getCustomName() { } @Override - public boolean getCustomNameVisible() { + public boolean isCustomNameVisible() { return Configuration.Name.Tag.SHOW; } @@ -398,16 +396,16 @@ public boolean playIdleSound() { @Override public void showPotionParticles(Color color) { - getDataWatcher().set(POTION_PARTICLE_WATCHER, (byte) color.asRGB()); + getEntityData().set(POTION_PARTICLE_WATCHER, (byte) color.asRGB()); } @Override public void hidePotionParticles() { int potionEffects = 0; - if (!getEffects().isEmpty()) { - potionEffects = PotionUtil.a(getEffects()); + if (!getActiveEffects().isEmpty()) { + potionEffects = PotionUtils.getColor(getActiveEffects()); } - getDataWatcher().set(POTION_PARTICLE_WATCHER, (byte) potionEffects); + getEntityData().set(POTION_PARTICLE_WATCHER, (byte) potionEffects); } @Override @@ -422,16 +420,16 @@ public boolean attack(Entity entity) { boolean damageEntity = false; try { double damage = isMyPet() ? myPet.getDamage() : 0; - if (entity instanceof EntityPlayer) { + if (entity instanceof ServerPlayer) { Player victim = (Player) entity.getBukkitEntity(); if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), victim, true)) { if (myPet.hasTarget()) { - setGoalTarget(null); + setTarget(null); } return false; } } - damageEntity = entity.damageEntity(DamageSource.mobAttack(this), (float) damage); + damageEntity = entity.hurt(DamageSource.mobAttack(this), (float) damage); } catch (Exception e) { e.printStackTrace(); } @@ -475,14 +473,14 @@ public boolean isSitting() { } @Override - public boolean isPersistent() { + public boolean isPersistenceRequired() { return false; } @Override public CraftMyPet getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPet(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPet(this.level.getCraftServer(), this); } return this.bukkitEntity; } @@ -495,22 +493,22 @@ public CraftMyPet getBukkitEntity() { * true: there was a reaction on rightclick * false: no reaction on rightclick */ - public EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) { + public InteractionResult handlePlayerInteraction(final net.minecraft.world.entity.player.Player entityhuman, InteractionHand enumhand, final ItemStack itemStack) { new BukkitRunnable() { @Override public void run() { - EntityPlayer player = ((EntityPlayer) entityhuman); + ServerPlayer player = ((ServerPlayer) entityhuman); if (player.getBukkitEntity().isOnline()) { - player.initMenu(entityhuman.bU); + player.initMenu(entityhuman.containerMenu); } } }.runTaskLater(MyPetApi.getPlugin(), 5); - if (itemStack != null && itemStack.getItem() == Items.rP) { - ((EntityPlayer) entityhuman).b.sendPacket(new PacketPlayOutAttachEntity(this, null)); + if (itemStack != null && itemStack.getItem() == Items.LEAD) { + ((ServerPlayer) entityhuman).connection.send(new ClientboundSetEntityLinkPacket(this, null)); } - if (enumhand == EnumHand.b) { - return EnumInteractionResult.a; + if (enumhand == InteractionHand.OFF_HAND) { + return InteractionResult.SUCCESS; } Player owner = this.getOwner().getPlayer(); @@ -520,7 +518,7 @@ public void run() { if (myPet.getSkills().isActive(RideImpl.class) && canMove()) { if (Permissions.hasExtended(owner, "MyPet.extended.ride")) { ((CraftPlayer) owner).getHandle().startRiding(this); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else { getOwner().sendMessage(Translation.getString("Message.No.CanUse", myPet.getOwner()), 2000); } @@ -528,21 +526,21 @@ public void run() { } if (Configuration.Skilltree.Skill.CONTROL_ITEM.compare(itemStack)) { if (myPet.getSkills().isActive(ControlImpl.class)) { - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } if (itemStack != null) { - if (itemStack.getItem() == Items.rQ && itemStack.hasName()) { + if (itemStack.getItem() == Items.NAME_TAG && itemStack.hasCustomHoverName()) { if (Permissions.has(getOwner(), "MyPet.command.name") && Permissions.hasExtended(getOwner(), "MyPet.extended.nametag")) { - final String name = itemStack.getName().getString(); + final String name = itemStack.getHoverName().getString(); getMyPet().setPetName(name); EntityMyPet.super.setCustomName(CraftChatMessage.fromStringOrNull("-")); myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Name.New", myPet.getOwner()), name)); - if (!entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (!entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); } if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } new BukkitRunnable() { @Override @@ -550,17 +548,17 @@ public void run() { updateNameTag(); } }.runTaskLater(MyPetApi.getPlugin(), 1L); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } if (canEat(itemStack) && canUseItem()) { if (owner != null && !Permissions.hasExtended(owner, "MyPet.extended.feed")) { - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } if (this.petTargetSelector.hasGoal("DuelTarget")) { BehaviorDuelTarget duelTarget = (BehaviorDuelTarget) this.petTargetSelector.getGoal("DuelTarget"); if (duelTarget.getDuelOpponent() != null) { - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } boolean used = false; @@ -592,15 +590,15 @@ public void run() { } if (used) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, getHeadHeight(), 0), ParticleCompat.HEART.get(), 0.5F, 0.5F, 0.5F, 0.5F, 5, 20); + MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, getEyeHeight(), 0), ParticleCompat.HEART.get(), 0.5F, 0.5F, 0.5F, 0.5F, 5, 20); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } @@ -614,12 +612,12 @@ public void run() { command = command.replaceAll("%pet_uuid%", myPet.getUUID().toString()); command = command.replaceAll("%pet_world_group%", myPet.getWorldGroup()); command = command.replaceAll("%pet_skilltree_name%", myPet.getSkilltree() != null ? myPet.getSkilltree().getName() : ""); - return owner.performCommand(command) ? EnumInteractionResult.b : EnumInteractionResult.d; // TODO: 2021/06/28 PASS + return owner.performCommand(command) ? InteractionResult.CONSUME : InteractionResult.PASS; } } else { if (itemStack != null) { - if (itemStack.getItem() == Items.rQ) { - if (itemStack.hasName()) { + if (itemStack.getItem() == Items.NAME_TAG) { + if (itemStack.hasCustomHoverName()) { EntityMyPet.super.setCustomName(CraftChatMessage.fromStringOrNull("-")); new BukkitRunnable() { @Override @@ -627,19 +625,19 @@ public void run() { updateNameTag(); } }.runTaskLater(MyPetApi.getPlugin(), 1L); - return EnumInteractionResult.d; + return InteractionResult.PASS; } } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } public void onLivingUpdate() { if (hasRider) { if (!isVehicle()) { hasRider = false; - this.G = 0.5F; // climb height -> halfslab + this.walkDistO = 0.5F; // climb height -> halfslab Location playerLoc = getOwner().getPlayer().getLocation(); Location petLoc = getBukkitEntity().getLocation(); petLoc.setYaw(playerLoc.getYaw()); @@ -649,9 +647,9 @@ public void onLivingUpdate() { } else { if (isVehicle()) { for (Entity e : this.getPassengers()) { - if (e instanceof EntityPlayer && getOwner().equals(e)) { + if (e instanceof ServerPlayer && getOwner().equals(e)) { hasRider = true; - this.G = 1.0F; // climb height -> 1 block + this.walkDistO = 1.0F; // climb height -> 1 block petTargetSelector.finish(); petPathfinderSelector.finish(); } else { @@ -661,13 +659,13 @@ public void onLivingUpdate() { } } if (sitPathfinder.isSitting() && sitCounter-- <= 0) { - MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), ParticleCompat.BARRIER.get(), 0F, 0F, 0F, 5F, 1, 32); + MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getEyeHeight() + 1, 0), ParticleCompat.BARRIER.get(), 0F, 0F, 0F, 5F, 1, 32); sitCounter = 60; } Player p = myPet.getOwner().getPlayer(); if (p != null && p.isOnline() && !p.isDead()) { - if (p.isSneaking() != isSneaking()) { - this.setSneaking(!isSneaking()); + if (p.isSneaking() != isShiftKeyDown()) { + this.setShiftKeyDown(!isShiftKeyDown()); } if (Configuration.Misc.INVISIBLE_LIKE_OWNER) { if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) { @@ -701,10 +699,10 @@ public void setHealth(float f) { double deltaHealth = super.getHealth(); double maxHealth = myPet.getMaxHealth(); - boolean silent = this.getAttributeInstance(GenericAttributes.a).getValue() != maxHealth; - this.getAttributeInstance(GenericAttributes.a).setValue(maxHealth); + boolean silent = this.getAttribute(Attributes.MAX_HEALTH).getValue() != maxHealth; + this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(maxHealth); - super.setHealth(MathHelper.a(f, 0.0F, (float) maxHealth)); // Is that right? + super.setHealth(Mth.clamp(f, 0.0F, (float) maxHealth)); // Is that right? double health = getHealth(); if (deltaHealth > maxHealth) { @@ -757,7 +755,7 @@ public float getSoundSpeed() { pitchAddition += 0.5F; } } - return (this.Q.nextFloat() - this.Q.nextFloat()) * 0.2F + 1 + pitchAddition; + return (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1 + pitchAddition; } /** @@ -773,33 +771,33 @@ public float getSoundSpeed() { /** * Returns the sound that is played when the MyPet dies */ - protected abstract String getDeathSound(); + protected abstract String getMyPetDeathSound(); public void playPetStepSound() { } - public void playStepSound(BlockPosition blockposition, IBlockData blockdata) { + public void playMyPetStepSound(BlockPos blockposition, BlockState blockdata) { playPetStepSound(); } private void makeLivingSound() { if (getLivingSound() != null) { - SoundEffect se = IRegistry.T.get(new MinecraftKey(getLivingSound())); + SoundEvent se = Registry.SOUND_EVENT.get(new ResourceLocation(getLivingSound())); if (se != null) { - for (int j = 0; j < this.t.getPlayers().size(); ++j) { - EntityPlayer entityplayer = (EntityPlayer) this.t.getPlayers().get(j); + for (int j = 0; j < this.level.players().size(); ++j) { + ServerPlayer entityplayer = (ServerPlayer) this.level.players().get(j); float volume = 1f; if (MyPetApi.getPlayerManager().isMyPetPlayer(entityplayer.getBukkitEntity())) { volume = MyPetApi.getPlayerManager().getMyPetPlayer(entityplayer.getBukkitEntity()).getPetLivingSoundVolume(); } - double deltaX = locX() - entityplayer.locX(); - double deltaY = locY() - entityplayer.locY(); - double deltaZ = locZ() - entityplayer.locZ(); + double deltaX = getX() - entityplayer.getX(); + double deltaY = getY() - entityplayer.getY(); + double deltaZ = getZ() - entityplayer.getZ(); double maxDistance = volume > 1.0F ? (double) (16.0F * volume) : 16.0D; if (deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ < maxDistance * maxDistance) { - entityplayer.b.sendPacket(new PacketPlayOutNamedSoundEffect(se, SoundCategory.f, locX(), locY(), locZ(), volume, getSoundSpeed())); + entityplayer.connection.send(new ClientboundSoundPacket(se, SoundSource.HOSTILE, getX(), getY(), getZ(), volume, getSoundSpeed())); } } } else { @@ -822,68 +820,68 @@ private void ride(double motionSideways, double motionForward, double motionUpwa float speed; float swimmSpeed; - if (this.a(TagsFluid.b)) { - locY = this.locY(); + if (this.isEyeInFluid(FluidTags.WATER)) { + locY = this.getY(); speed = 0.8F; swimmSpeed = 0.02F; - this.a(swimmSpeed, new Vec3D(motionSideways, motionUpwards, motionForward)); - this.move(EnumMoveType.a, this.getMot()); - double motX = this.getMot().getX() * (double) speed; - double motY = this.getMot().getY() * 0.800000011920929D; - double motZ = this.getMot().getZ() * (double) speed; + this.moveRelative(swimmSpeed, new Vec3(motionSideways, motionUpwards, motionForward)); + this.move(MoverType.SELF, this.getDeltaMovement()); + double motX = this.getDeltaMovement().x() * (double) speed; + double motY = this.getDeltaMovement().y() * 0.800000011920929D; + double motZ = this.getDeltaMovement().z() * (double) speed; motY -= 0.02D; - if (this.A && this.f(this.getMot().getX(), this.getMot().getY() + 0.6000000238418579D - this.locY() + locY, this.getMot().getZ())) { + if (this.horizontalCollision && this.isFree(this.getDeltaMovement().x(), this.getDeltaMovement().y() + 0.6000000238418579D - this.getY() + locY, this.getDeltaMovement().z())) { motY = 0.30000001192092896D; } - this.setMot(motX, motY, motZ); - } else if (this.a(TagsFluid.c)) { - locY = this.locY(); - this.a(0.02F, new Vec3D(motionSideways, motionUpwards, motionForward)); - this.move(EnumMoveType.a, this.getMot()); - double motX = this.getMot().getX() * 0.5D; - double motY = this.getMot().getY() * 0.5D; - double motZ = this.getMot().getZ() * 0.5D; + this.setDeltaMovement(motX, motY, motZ); + } else if (this.isEyeInFluid(FluidTags.LAVA)) { + locY = this.getY(); + this.moveRelative(0.02F, new Vec3(motionSideways, motionUpwards, motionForward)); + this.move(MoverType.SELF, this.getDeltaMovement()); + double motX = this.getDeltaMovement().x() * 0.5D; + double motY = this.getDeltaMovement().y() * 0.5D; + double motZ = this.getDeltaMovement().z() * 0.5D; motY -= 0.02D; - if (this.A && this.f(this.getMot().getX(), this.getMot().getY() + 0.6000000238418579D - this.locY() + locY, this.getMot().getZ())) { + if (this.horizontalCollision && this.isFree(this.getDeltaMovement().x(), this.getDeltaMovement().y() + 0.6000000238418579D - this.getY() + locY, this.getDeltaMovement().z())) { motY = 0.30000001192092896D; } - this.setMot(motX, motY, motZ); + this.setDeltaMovement(motX, motY, motZ); } else { double minY; - minY = this.getBoundingBox().b; + minY = this.getBoundingBox().minY; float friction = 0.91F; - if (this.z) { - friction = this.t.getType(new BlockPosition(MathHelper.floor(this.locX()), MathHelper.floor(minY) - 1, MathHelper.floor(this.locZ()))).getBlock().getFrictionFactor() * 0.91F; + if (this.onGround) { + friction = this.level.getBlockState(new BlockPos(Mth.floor(this.getX()), Mth.floor(minY) - 1, Mth.floor(this.getZ()))).getBlock().getFriction() * 0.91F; } speed = speedModifier * (0.16277136F / (friction * friction * friction)); - this.a(speed, new Vec3D(motionSideways, motionUpwards, motionForward)); + this.moveRelative(speed, new Vec3(motionSideways, motionUpwards, motionForward)); friction = 0.91F; - if (this.z) { - friction = this.t.getType(new BlockPosition(MathHelper.floor(this.locX()), MathHelper.floor(minY) - 1, MathHelper.floor(this.locZ()))).getBlock().getFrictionFactor() * 0.91F; + if (this.onGround) { + friction = this.level.getBlockState(new BlockPos(Mth.floor(this.getX()), Mth.floor(minY) - 1, Mth.floor(this.getZ()))).getBlock().getFriction() * 0.91F; } - double motX = this.getMot().getX(); - double motY = this.getMot().getY(); - double motZ = this.getMot().getZ(); + double motX = this.getDeltaMovement().x(); + double motY = this.getDeltaMovement().y(); + double motZ = this.getDeltaMovement().z(); - if (this.isClimbing()) { + if (this.onClimbable()) { swimmSpeed = 0.16F; - motX = MathHelper.a(motX, -swimmSpeed, swimmSpeed); - motZ = MathHelper.a(motZ, -swimmSpeed, swimmSpeed); - this.J = 0.0F; + motX = Mth.clamp(motX, -swimmSpeed, swimmSpeed); + motZ = Mth.clamp(motZ, -swimmSpeed, swimmSpeed); + this.flyDist = 0.0F; if (motY < -0.16D) { motY = -0.16D; } } - Vec3D mot = new Vec3D(motX, motY, motZ); + Vec3 mot = new Vec3(motX, motY, motZ); - this.move(EnumMoveType.a, mot); - if (this.A && this.isClimbing()) { + this.move(MoverType.SELF, mot); + if (this.horizontalCollision && this.onClimbable()) { motY = 0.2D; } @@ -893,16 +891,16 @@ private void ride(double motionSideways, double motionForward, double motionUpwa motX *= friction; motZ *= friction; - this.setMot(motX, motY, motZ); + this.setDeltaMovement(motX, motY, motZ); } // is bird - this.a(this, false); + this.startRiding(this, false); } @Override public void makeSound(String sound, float volume, float pitch) { if (sound != null) { - SoundEffect se = IRegistry.T.get(new MinecraftKey(sound)); + SoundEvent se = Registry.SOUND_EVENT.get(new ResourceLocation(sound)); if (se != null) { this.playSound(se, volume, pitch); } else { @@ -915,7 +913,7 @@ public void makeSound(String sound, float volume, float pitch) { * do NOT drop anything */ @Override - protected boolean isDropExperience() { + protected boolean shouldDropExperience() { return false; } @@ -923,28 +921,28 @@ protected boolean isDropExperience() { * do NOT drop anything */ @Override - protected void dropDeathLoot(DamageSource damagesource, int i, boolean flag) { + protected void dropCustomDeathLoot(DamageSource damagesource, int i, boolean flag) { } // Obfuscated Methods ------------------------------------------------------------------------------------------- @Override - public net.minecraft.world.entity.EntitySize a(EntityPose entitypose) { + public EntityDimensions getDimensions(Pose entitypose) { EntitySize es = this.getClass().getAnnotation(EntitySize.class); if (es != null) { float width = es.width(); float height = java.lang.Float.isNaN(es.height()) ? width : es.height(); - return new net.minecraft.world.entity.EntitySize(width, height, false); + return new EntityDimensions(width, height, false); } - return super.a(entitypose); + return super.getDimensions(entitypose); } /** * Allows handlePlayerInteraction() to * be fired when a lead is used */ - @Override - public boolean a(EntityHuman entityhuman) { + @Override + public boolean canBeLeashed(net.minecraft.world.entity.player.Player entityhuman) { return false; } @@ -956,27 +954,27 @@ public boolean a(EntityHuman entityhuman) { * -> handlePlayerInteraction(EntityHuman) */ @Override - public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) { + public InteractionResult mobInteract(net.minecraft.world.entity.player.Player entityhuman, InteractionHand enumhand) { try { - ItemStack itemstack = entityhuman.b(enumhand); - EnumInteractionResult result = handlePlayerInteraction(entityhuman, enumhand, itemstack); - if (!result.a() && getMyPet().getOwner().equals(entityhuman) && entityhuman.isSneaking()) { - result = EnumInteractionResult.a(toggleSitting()); + ItemStack itemstack = entityhuman.getItemInHand(enumhand); + InteractionResult result = handlePlayerInteraction(entityhuman, enumhand, itemstack); + if (!result.consumesAction() && getMyPet().getOwner().equals(entityhuman) && entityhuman.isShiftKeyDown()) { + result = InteractionResult.sidedSuccess(toggleSitting()); } return result; } catch (Exception e) { e.printStackTrace(); } - return EnumInteractionResult.d; + return InteractionResult.PASS; } /** * -> playStepSound() */ @Override - protected void b(BlockPosition blockposition, IBlockData iblockdata) { + protected void playStepSound(BlockPos blockposition, BlockState iblockdata) { try { - playStepSound(blockposition, iblockdata); + playMyPetStepSound(blockposition, iblockdata); } catch (Exception e) { e.printStackTrace(); } @@ -987,9 +985,9 @@ protected void b(BlockPosition blockposition, IBlockData iblockdata) { * -> getHurtSound() */ @Override - protected SoundEffect getSoundHurt(DamageSource damagesource) { + protected SoundEvent getHurtSound(DamageSource damagesource) { try { - return IRegistry.T.get(new MinecraftKey(getHurtSound())); + return Registry.SOUND_EVENT.get(new ResourceLocation(getHurtSound())); } catch (Exception e) { e.printStackTrace(); } @@ -998,12 +996,11 @@ protected SoundEffect getSoundHurt(DamageSource damagesource) { /** * Returns the sound that is played when the MyPet dies - * -> getDeathSound() */ @Override - protected SoundEffect getSoundDeath() { + protected SoundEvent getDeathSound() { try { - return IRegistry.T.get(new MinecraftKey(getDeathSound())); + return Registry.SOUND_EVENT.get(new ResourceLocation(getMyPetDeathSound())); } catch (Exception e) { e.printStackTrace(); } @@ -1023,79 +1020,79 @@ protected float sp() { } @Override - public void movementTick() { //Speed-Probleme? + public void aiStep() { //Speed-Probleme? if (this.jumpDelay > 0) { --this.jumpDelay; } - if (this.dn()) { - this.bs = 0; - this.d(this.locX(), this.locY(), this.locZ()); + if (this.isAlwaysTicking()) { + this.lerpX = 0; + this.setPacketCoordinates(this.getX(), this.getY(), this.getZ()); } - if (this.bs > 0) { - double newX = this.locX() + (this.bA - this.locX()) / this.bs; - double newY = this.locY() + (this.bB - this.locY()) / this.bs; - double newZ = this.locZ() + (this.bC - this.locZ()) / this.bs; - double d3 = MathHelper.g(EntityMyPet.az - (double) this.getYRot()); - this.setYRot((float) ((double) this.getYRot() + d3 / this.bs)); - this.setXRot((float) ((double) this.getXRot() + (this.aT - (double) this.getXRot()) / this.bs)); - --this.bs; - this.setPosition(newX, newY, newZ); - this.setYawPitch(this.getYRot(), this.getXRot()); + if (this.lerpX > 0) { + double newX = this.getX() + (this.useItemRemaining - this.getX()) / this.lerpX; + double newY = this.getY() + (this.fallFlyTicks - this.getY()) / this.lerpX; + double newZ = this.getZ() + (this.autoSpinAttackTicks - this.getZ()) / this.lerpX; + double d3 = Mth.frac(this.animationSpeed - (double) this.getYRot()); //TODO animationSpeed might be wrong (was az which might have been wrong...) + this.setYRot((float) ((double) this.getYRot() + d3 / this.lerpX)); + this.setXRot((float) ((double) this.getXRot() + (this.animationPosition - (double) this.getXRot()) / this.lerpX)); + --this.lerpX; + this.setPos(newX, newY, newZ); + this.setRot(this.getYRot(), this.getXRot()); } else { - this.setMot(this.getMot().a(0.98D)); + this.setDeltaMovement(this.getDeltaMovement().scale(0.98D)); } - Vec3D vec3d = this.getMot(); - double motX = vec3d.getX(); - double motY = vec3d.getY(); - double motZ = vec3d.getZ(); + Vec3 vec3d = this.getDeltaMovement(); + double motX = vec3d.x(); + double motY = vec3d.y(); + double motZ = vec3d.z(); - if (Math.abs(vec3d.getX()) < 0.003D) { + if (Math.abs(vec3d.x()) < 0.003D) { motX = 0.0D; } - if (Math.abs(vec3d.getY()) < 0.003D) { + if (Math.abs(vec3d.y()) < 0.003D) { motY = 0.0D; } - if (Math.abs(vec3d.getZ()) < 0.003D) { + if (Math.abs(vec3d.z()) < 0.003D) { motZ = 0.0D; } - this.setMot(motX, motY, motZ); + this.setDeltaMovement(motX, motY, motZ); this.doMyPetTick(); - if (this.bn) { + if (this.jumping) { double d7; - if (this.aX()) { - d7 = this.b(TagsFluid.c); + if (this.isInLava()) { + d7 = this.getFluidHeight(FluidTags.LAVA); } else { - d7 = this.b(TagsFluid.b); + d7 = this.getFluidHeight(FluidTags.WATER); } boolean flag = this.isInWater() && d7 > 0.0D; - double d8 = this.cN(); - if (flag && (!this.z || d7 > d8)) { - this.c(TagsFluid.b); - } else if (this.aX() && (!this.z || d7 > d8)) { - this.c(TagsFluid.c); - } else if ((this.z || flag && d7 <= d8) && this.jumpDelay == 0) { - this.jump(); + double d8 = this.getFluidJumpThreshold(); + if (flag && (!this.onGround || d7 > d8)) { + this.jumpInLiquid(FluidTags.WATER); + } else if (this.isInLava() && (!this.onGround || d7 > d8)) { + this.jumpInLiquid(FluidTags.LAVA); + } else if ((this.onGround || flag && d7 <= d8) && this.jumpDelay == 0) { + this.jumpFromGround(); this.jumpDelay = 10; } } else { this.jumpDelay = 0; } - this.aR *= 0.98F; - this.aT *= 0.98F; + this.animationSpeedOld *= 0.98F; + this.animationPosition *= 0.98F; // this.n(); //no Elytra flight - this.f(new Vec3D(this.aR, this.aZ, this.aT)); - this.collideNearby(); + this.travel(new Vec3(this.animationSpeedOld, this.yHeadRot, this.animationPosition)); + this.pushEntities(); } @Override @@ -1103,7 +1100,7 @@ protected boolean addPassenger(Entity entity) { boolean returnVal = false; // don't allow anything but the owner to ride this entity Ride rideSkill = myPet.getSkills().get(RideImpl.class); - if (rideSkill != null && entity instanceof EntityPlayer && getOwner().equals(entity)) { + if (rideSkill != null && entity instanceof ServerPlayer && getOwner().equals(entity)) { if (entity.getVehicle() != this) { throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)"); } else { @@ -1119,12 +1116,12 @@ protected boolean addPassenger(Entity entity) { } } - if (this instanceof IJumpable) { + if (this instanceof PlayerRideableJumping) { double factor = 1; if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.HungerSystem.AFFECT_RIDE_SPEED) { factor = Math.log10(myPet.getSaturation()) / 2; } - getAttributeInstance(GenericAttributes.d).setValue((0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F))) * factor); + getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue((0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F))) * factor); } } return returnVal; @@ -1146,21 +1143,21 @@ public static boolean callEvent(final CraftEntity player, final CraftMyPet pet) protected boolean removePassenger(Entity entity) { boolean result = super.removePassenger(entity); PlatformHelper platformHelper = (PlatformHelper) MyPetApi.getPlatformHelper(); - AxisAlignedBB bb = entity.getBoundingBox(); - bb = getBBAtPosition(bb, this.locX(), this.locY(), this.locZ()); - if (!platformHelper.canSpawn(getBukkitEntity().getLocation(), bb)) { - entity.a(this, true); + AABB bb = entity.getBoundingBox(); + bb = getBBAtPosition(bb, this.getX(), this.getY(), this.getZ()); + if (!platformHelper.canSpawn(getBukkitEntity().getLocation(), (MyPetMinecraftEntity) bb)) { + entity.startRiding(this, true); } else { - entity.setPosition(locX(), locY(), locZ()); + entity.setPos(getX(), getY(), getZ()); } return result; } - protected AxisAlignedBB getBBAtPosition(AxisAlignedBB bb, double x, double y, double z) { - double width = bb.b() / 2; - double height = bb.c(); - double depth = bb.d() / 2; - return new AxisAlignedBB(x - width, y, z - depth, x + width, y + height, z + width); + protected AABB getBBAtPosition(AABB bb, double x, double y, double z) { + double width = bb.getXsize() / 2; + double height = bb.getYsize(); + double depth = bb.getZsize() / 2; + return new AABB(x - width, y, z - depth, x + width, y + height, z + width); } /** @@ -1169,14 +1166,14 @@ protected AxisAlignedBB getBBAtPosition(AxisAlignedBB bb, double x, double y, do */ protected void doMyPetTick() { try { - ++this.bf; + ++this.noActionTime; if (isAlive()) { - getEntitySenses().a(); // sensing + getSensing().tick(); // sensing Player p = getOwner().getPlayer(); if (p == null || !p.isOnline()) { - this.die(); + this.discard(); return; } @@ -1187,7 +1184,7 @@ protected void doMyPetTick() { } Ride rideSkill = myPet.getSkills().get(RideImpl.class); - if (this.z && rideSkill.getFlyLimit().getValue().doubleValue() > 0) { + if (this.onGround && rideSkill.getFlyLimit().getValue().doubleValue() > 0) { limitCounter += rideSkill.getFlyRegenRate().getValue().doubleValue(); if (limitCounter > rideSkill.getFlyLimit().getValue().doubleValue()) { limitCounter = rideSkill.getFlyLimit().getValue().floatValue(); @@ -1195,12 +1192,12 @@ protected void doMyPetTick() { } } - mobTick(); + customServerAiStep(); // controls - getControllerMove().a(); // move - getControllerLook().a(); // look - getControllerJump().b(); // jump + getMoveControl().tick(); // move + getLookControl().tick(); // look + getJumpControl().tick(); // jump } catch (Exception e) { e.printStackTrace(); } @@ -1210,7 +1207,7 @@ protected void doMyPetTick() { * MyPets are not persistant so no data needs to be saved */ @Override - public boolean d(NBTTagCompound nbttagcompound) { + public boolean saveAsPassenger(CompoundTag nbttagcompound) { return false; } @@ -1218,9 +1215,9 @@ public boolean d(NBTTagCompound nbttagcompound) { * -> falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!this.isFlying) { - return super.d(f, f1); + return super.calculateFallDamage(f, f1); } return 0; } @@ -1229,21 +1226,22 @@ public int d(float f, float f1) { /** * -> travel */ - public void f(Vec3D vec3d) { + @Override + public void travel(Vec3 vec3d) { if (!hasRider || !this.isVehicle()) { - g(vec3d); + super.travel(vec3d); return; } - if (this.z && this.isFlying) { + if (this.onGround && this.isFlying) { isFlying = false; - this.J = 0; + this.flyDist = 0; } - EntityLiving passenger = (EntityLiving) this.getFirstPassenger(); + LivingEntity passenger = (LivingEntity) this.getFirstPassenger(); - if (this.a(TagsFluid.b)) { - this.setMot(this.getMot().add(0, 0.4, 0)); + if (this.isEyeInFluid(FluidTags.WATER)) { + this.setDeltaMovement(this.getDeltaMovement().add(0, 0.4, 0)); } Ride rideSkill = myPet.getSkills().get(RideImpl.class); @@ -1253,16 +1251,15 @@ public void f(Vec3D vec3d) { } //apply pitch & yaw - this.x = passenger.getYRot(); + this.yRotO = passenger.getYRot(); this.setYRot(passenger.getYRot()); this.setXRot(passenger.getXRot() * 0.5F); - setYawPitch(this.getYRot(), this.getXRot()); - this.bg = (this.aX = this.getYRot()); + setRot(this.getYRot(), this.getXRot()); + this.oRun = (this.yBodyRot = this.getYRot()); - //TODO Got the right fields, now speed is something // get motion from passenger (player) - double motionSideways = passenger.bo; - double motionForward = passenger.bq * 2; + double motionSideways = passenger.xxa; + double motionForward = passenger.zza * 2; // backwards is slower if (motionForward <= 0.0F) { @@ -1280,15 +1277,15 @@ public void f(Vec3D vec3d) { ascendSpeed *= factor; } - ride(motionSideways, motionForward, vec3d.getY(), speed); // apply motion + ride(motionSideways, motionForward, vec3d.y(), speed); // apply motion // throw player move event if (Configuration.Misc.THROW_PLAYER_MOVE_EVENT_WHILE_RIDING && !(this instanceof EntityMyHorse)) { - double delta = Math.pow(this.locX() - this.u, 2.0D) + Math.pow(this.locY() - this.v, 2.0D) + Math.pow(this.locZ() - this.w, 2.0D); - float deltaAngle = Math.abs(this.getYRot() - x) + Math.abs(this.getXRot() - y); + double delta = Math.pow(this.getX() - this.xo, 2.0D) + Math.pow(this.getY() - this.yo, 2.0D) + Math.pow(this.getZ() - this.zo, 2.0D); + float deltaAngle = Math.abs(this.getYRot() - yRotO) + Math.abs(this.getXRot() - xRotO); if (delta > 0.00390625D || deltaAngle > 10.0F) { Location to = getBukkitEntity().getLocation(); - Location from = new Location(t.getWorld(), this.u, this.v, this.w, this.x, this.y); + Location from = new Location(level.getWorld(), this.xo, this.yo, this.zo, this.yRotO, this.xRotO); if (from.getX() != Double.MAX_VALUE) { Location oldTo = to.clone(); PlayerMoveEvent event = new PlayerMoveEvent((Player) passenger.getBukkitEntity(), from, to); @@ -1306,13 +1303,12 @@ public void f(Vec3D vec3d) { } if (jump != null && this.isVehicle()) { - this.getBlockJumpFactor(); // TODO why? boolean doJump = false; - if (this instanceof IJumpable) { + if (this instanceof PlayerRideableJumping) { if (this.jumpPower > 0.0F) { doJump = true; this.jumpPower = 0.0F; - } else if (!this.z && jump != null) { + } else if (!this.onGround && jump != null) { try { doJump = jump.getBoolean(passenger); } catch (IllegalAccessException ignored) { @@ -1328,15 +1324,15 @@ public void f(Vec3D vec3d) { } if (doJump) { - if (z) { + if (onGround) { jumpHeight = new BigDecimal(jumpHeight).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); String jumpHeightString = JumpHelper.JUMP_FORMAT.format(jumpHeight); Double jumpVelocity = JumpHelper.JUMP_MAP.get(jumpHeightString); jumpVelocity = jumpVelocity == null ? 0.44161199999510264 : jumpVelocity; - if (this instanceof IJumpable) { - getAttributeInstance(GenericAttributes.m).setValue(jumpVelocity); + if (this instanceof PlayerRideableJumping) { + getAttribute(Attributes.JUMP_STRENGTH).setBaseValue(jumpVelocity); } - this.setMot(this.getMot().getX(), jumpVelocity, this.getMot().getZ()); + this.setDeltaMovement(this.getDeltaMovement().x(), jumpVelocity, this.getDeltaMovement().z()); } else if (rideSkill.getCanFly().getValue()) { if (limitCounter <= 0 && rideSkill.getFlyLimit().getValue().doubleValue() > 0) { canFly = false; @@ -1348,9 +1344,9 @@ public void f(Vec3D vec3d) { flyCheckCounter = 5; } if (canFly) { - if (this.getMot().getY() < ascendSpeed) { - this.setMot(this.getMot().getX(), ascendSpeed, this.getMot().getZ()); - this.J = 0; + if (this.getDeltaMovement().y() < ascendSpeed) { + this.setDeltaMovement(this.getDeltaMovement().x(), ascendSpeed, this.getDeltaMovement().z()); + this.flyDist = 0; this.isFlying = true; } } @@ -1361,9 +1357,9 @@ public void f(Vec3D vec3d) { } if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.Skilltree.Skill.Ride.HUNGER_PER_METER > 0) { - double dX = locX() - u; - double dY = Math.max(0, locY() - v); - double dZ = locZ() - w; + double dX = getX() - xo; + double dY = Math.max(0, getY() - yo); + double dZ = getZ() - zo; if (dX != 0 || dY != 0 || dZ != 0) { double distance = Math.sqrt(dX * dX + dY * dY + dZ * dZ); if (isFlying && rideSkill.getFlyLimit().getValue().doubleValue() > 0) { @@ -1371,8 +1367,8 @@ public void f(Vec3D vec3d) { } myPet.decreaseSaturation(Configuration.Skilltree.Skill.Ride.HUNGER_PER_METER * distance); double factor = Math.log10(myPet.getSaturation()) / 2; - getAttributeInstance(GenericAttributes.d).setValue((0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F))) * factor); - this.n((float) this.getAttributeInstance(GenericAttributes.d).getValue()); + getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue((0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F))) * factor); + this.setSpeed((float) this.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); } } } @@ -1395,7 +1391,7 @@ public void tick() { * -> getLivingSound() */ @Override - protected SoundEffect getSoundAmbient() { + protected SoundEvent getAmbientSound() { try { if (getLivingSound() != null && playIdleSound()) { makeLivingSound(); @@ -1408,15 +1404,20 @@ protected SoundEffect getSoundAmbient() { } @Override - protected void d(DamageSource damagesource) { + protected void playHurtSound(DamageSource damagesource) { CraftEventFactory.callEntityDeathEvent(this); } @Override - public DamageSource dW() { + public DamageSource getLastDamageSource() { if (deathReason != null) { return deathReason; } - return super.dW(); + return super.getLastDamageSource(); + } + + @Override + public UUID getUniqueID() { + return this.uuid; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPetPart.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPetPart.java index 0e973521e3..787eae3e1f 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPetPart.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPetPart.java @@ -23,66 +23,63 @@ import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftPart; import de.Keyle.MyPet.api.util.ReflectionUtil; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityPose; -import net.minecraft.world.entity.EntitySize; -import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Pose; public class EntityMyPetPart extends Entity implements MyPetMinecraftPart { public final EntityMyPet owner; - private final EntitySize size; + private final EntityDimensions size; private final String part; protected CraftMyPetPart bukkitEntity = null; public EntityMyPetPart(EntityMyPet owner, String part, float width, float height) { - super(EntityTypes.v, owner.t); - ReflectionUtil.setFieldValue("bukkitEntity", this, new CraftMyPetPart(this.t.getCraftServer(), this)); + super(EntityType.ENDER_DRAGON, owner.level); + ReflectionUtil.setFieldValue("bukkitEntity", this, new CraftMyPetPart(this.level.getCraftServer(), this)); this.owner = owner; this.part = part; - this.size = EntitySize.b(width, height); + this.size = EntityDimensions.scalable(width, height); } @Override - protected void initDatawatcher() { + protected void defineSynchedData() { } - @Override - public boolean isInteractable() { + public boolean isPickable() { return true; } @Override - protected void loadData(NBTTagCompound nbtTagCompound) { - + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - protected void saveData(NBTTagCompound nbtTagCompound) { - + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public boolean damageEntity(DamageSource var1, float var2) { + public boolean hurt(DamageSource var1, float var2) { return false; } @Override - public boolean q(Entity var1) { + public boolean is(Entity var1) { return this == var1 || this.owner == var1; } @Override - public Packet getPacket() { + public Packet getAddEntityPacket() { throw new UnsupportedOperationException(); } @Override - public EntitySize a(EntityPose entitypose) { + public EntityDimensions getDimensions(Pose entitypose) { return this.size; } @@ -94,7 +91,7 @@ public MyPetMinecraftEntity getPetOwner() { @Override public CraftMyPetPart getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetPart(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetPart(this.level.getCraftServer(), this); } return this.bukkitEntity; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityRegistry.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityRegistry.java index 5b5ddccdc0..757a685f76 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityRegistry.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityRegistry.java @@ -20,8 +20,19 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.ChatColor; +import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; +import org.bukkit.event.entity.CreatureSpawnEvent; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.MyPet; @@ -30,47 +41,33 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.api.util.ReflectionUtil; import lombok.SneakyThrows; -import net.minecraft.core.IRegistry; -import net.minecraft.core.RegistryBlocks; -import net.minecraft.core.RegistryMaterials; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntitySize; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.EnumCreatureType; -import net.minecraft.world.entity.animal.EntityFox; -import net.minecraft.world.level.World; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; -import org.bukkit.event.entity.CreatureSpawnEvent; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; +import net.minecraft.core.DefaultedRegistry; +import net.minecraft.core.MappedRegistry; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.Level; @Compat("v1_17_R1") public class EntityRegistry extends de.Keyle.MyPet.api.entity.EntityRegistry { BiMap> entityClasses = HashBiMap.create(); - Map entityTypes = new HashMap<>(); + Map entityTypes = new HashMap<>(); - protected void registerEntityType(MyPetType petType, String key, RegistryBlocks> entityRegistry) { //TODO 2021/08/19 The only thing left: They need to follow the player - EntityTypes types = (EntityTypes) entityRegistry.get(new MinecraftKey(key)); + protected void registerEntityType(MyPetType petType, String key, DefaultedRegistry> entityRegistry) { //TODO 2021/08/19 The only thing left: They need to follow the player + EntityType types = (EntityType) entityRegistry.get(new ResourceLocation(key)); entityTypes.put(petType, types); registerDefaultAttributes(entityTypes.get(petType), types); overwriteEntityID(entityTypes.get(petType), getEntityTypeId(petType, entityRegistry), entityRegistry); } @SneakyThrows - public static void registerDefaultAttributes(EntityTypes customType, EntityTypes rootType) { - MyAttributeDefaults.registerCustomEntityTypes(customType, rootType); + public static void registerDefaultAttributes(EntityType customType, EntityType rootType) { + MyAttributeDefaults.registerCustomEntityType(customType, rootType); } - protected void registerEntity(MyPetType type, RegistryBlocks> entityRegistry) { + protected void registerEntity(MyPetType type, DefaultedRegistry> entityRegistry) { Class entityClass = ReflectionUtil.getClass("de.Keyle.MyPet.compat.v1_17_R1.entity.types.EntityMy" + type.name()); entityClasses.forcePut(type, entityClass); @@ -86,10 +83,10 @@ public MyPetType getMyPetType(Class clazz) { public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bukkitWorld) { EntityMyPet petEntity = null; Class entityClass = entityClasses.get(pet.getPetType()); - World world = ((CraftWorld) bukkitWorld).getHandle(); + Level world = ((CraftWorld) bukkitWorld).getHandle(); try { - Constructor ctor = entityClass.getConstructor(World.class, MyPet.class); + Constructor ctor = entityClass.getConstructor(Level.class, MyPet.class); Object obj = ctor.newInstance(world, pet); if (obj instanceof EntityMyPet) { petEntity = (EntityMyPet) obj; @@ -105,7 +102,7 @@ public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bu @Override public boolean spawnMinecraftEntity(MyPetMinecraftEntity entity, org.bukkit.World bukkitWorld) { if (entity != null) { - World world = ((CraftWorld) bukkitWorld).getHandle(); + Level world = ((CraftWorld) bukkitWorld).getHandle(); return world.addEntity(((EntityMyPet) entity), CreatureSpawnEvent.SpawnReason.CUSTOM); } return false; @@ -113,7 +110,7 @@ public boolean spawnMinecraftEntity(MyPetMinecraftEntity entity, org.bukkit.Worl @Override public void registerEntityTypes() { - RegistryBlocks> entityRegistry = getRegistry(IRegistry.Y); + DefaultedRegistry> entityRegistry = getRegistry(Registry.ENTITY_TYPE); for (MyPetType type : MyPetType.all()) { registerEntity(type, entityRegistry); } @@ -127,16 +124,16 @@ public T getEntityType(MyPetType petType) { public void unregisterEntityTypes() { } - public RegistryBlocks> getRegistry(RegistryBlocks registryMaterials) { - if (!registryMaterials.getClass().getName().equals(RegistryBlocks.class.getName())) { + public DefaultedRegistry> getRegistry(DefaultedRegistry registryMaterials) { + if (!registryMaterials.getClass().getName().equals(DefaultedRegistry.class.getName())) { MyPetApi.getLogger().info("Custom entity registry found: " + registryMaterials.getClass().getName()); for (Field field : registryMaterials.getClass().getDeclaredFields()) { - if (field.getType() == RegistryMaterials.class) { + if (field.getType() == DefaultedRegistry.class) { field.setAccessible(true); try { - RegistryBlocks> reg = (RegistryBlocks>) field.get(registryMaterials); + DefaultedRegistry> reg = (DefaultedRegistry>) field.get(registryMaterials); - if (!reg.getClass().getName().equals(RegistryBlocks.class.getName())) { + if (!reg.getClass().getName().equals(DefaultedRegistry.class.getName())) { reg = getRegistry(reg); } @@ -150,11 +147,11 @@ public RegistryBlocks> getRegistry(RegistryBlocks registryMateria return registryMaterials; } - protected void overwriteEntityID(EntityTypes types, int id, RegistryBlocks> entityRegistry) { + protected void overwriteEntityID(EntityType types, int id, DefaultedRegistry> entityRegistry) { try { - Field bgF = RegistryMaterials.class.getDeclaredField("bw"); + Field bgF = MappedRegistry.class.getDeclaredField("bw"); //TODO Might fail. bgF.setAccessible(true); Object map = bgF.get(entityRegistry); Class clazz = map.getClass(); @@ -168,8 +165,8 @@ protected void overwriteEntityID(EntityTypes types, int id, RegistryBlocks> entityRegistry) { - EntityTypes types = entityRegistry.get(new MinecraftKey(type.getTypeID().toString())); + protected int getEntityTypeId(MyPetType type, DefaultedRegistry> entityRegistry) { + EntityType types = entityRegistry.get(new ResourceLocation(type.getTypeID().toString())); return entityRegistry.getId(types); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/MyAttributeDefaults.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/MyAttributeDefaults.java index 0d48472154..d86cee908e 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/MyAttributeDefaults.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/MyAttributeDefaults.java @@ -22,170 +22,178 @@ import java.util.HashMap; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.GlowSquid; -import net.minecraft.world.entity.ai.attributes.AttributeProvider; -import net.minecraft.world.entity.ambient.EntityBat; -import net.minecraft.world.entity.animal.EntityBee; -import net.minecraft.world.entity.animal.EntityCat; -import net.minecraft.world.entity.animal.EntityChicken; -import net.minecraft.world.entity.animal.EntityCow; -import net.minecraft.world.entity.animal.EntityDolphin; -import net.minecraft.world.entity.animal.EntityFish; -import net.minecraft.world.entity.animal.EntityFox; -import net.minecraft.world.entity.animal.EntityIronGolem; -import net.minecraft.world.entity.animal.EntityOcelot; -import net.minecraft.world.entity.animal.EntityPanda; -import net.minecraft.world.entity.animal.EntityParrot; -import net.minecraft.world.entity.animal.EntityPig; -import net.minecraft.world.entity.animal.EntityPolarBear; -import net.minecraft.world.entity.animal.EntityRabbit; -import net.minecraft.world.entity.animal.EntitySheep; -import net.minecraft.world.entity.animal.EntitySnowman; -import net.minecraft.world.entity.animal.EntitySquid; -import net.minecraft.world.entity.animal.EntityTurtle; -import net.minecraft.world.entity.animal.EntityWolf; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ambient.Bat; +import net.minecraft.world.entity.animal.Bee; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.entity.animal.Chicken; +import net.minecraft.world.entity.animal.Cod; +import net.minecraft.world.entity.animal.Cow; +import net.minecraft.world.entity.animal.Dolphin; +import net.minecraft.world.entity.animal.Fox; +import net.minecraft.world.entity.animal.IronGolem; +import net.minecraft.world.entity.animal.Ocelot; +import net.minecraft.world.entity.animal.Panda; +import net.minecraft.world.entity.animal.Parrot; +import net.minecraft.world.entity.animal.Pig; +import net.minecraft.world.entity.animal.PolarBear; +import net.minecraft.world.entity.animal.Pufferfish; +import net.minecraft.world.entity.animal.Rabbit; +import net.minecraft.world.entity.animal.Salmon; +import net.minecraft.world.entity.animal.Sheep; +import net.minecraft.world.entity.animal.SnowGolem; +import net.minecraft.world.entity.animal.Squid; +import net.minecraft.world.entity.animal.TropicalFish; +import net.minecraft.world.entity.animal.Turtle; +import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.animal.axolotl.Axolotl; import net.minecraft.world.entity.animal.goat.Goat; -import net.minecraft.world.entity.animal.horse.EntityHorse; -import net.minecraft.world.entity.animal.horse.EntityHorseDonkey; -import net.minecraft.world.entity.animal.horse.EntityHorseMule; -import net.minecraft.world.entity.animal.horse.EntityHorseSkeleton; -import net.minecraft.world.entity.animal.horse.EntityHorseZombie; -import net.minecraft.world.entity.animal.horse.EntityLlama; -import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon; -import net.minecraft.world.entity.boss.wither.EntityWither; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import net.minecraft.world.entity.monster.EntityBlaze; -import net.minecraft.world.entity.monster.EntityCaveSpider; -import net.minecraft.world.entity.monster.EntityCreeper; -import net.minecraft.world.entity.monster.EntityEnderman; -import net.minecraft.world.entity.monster.EntityEndermite; -import net.minecraft.world.entity.monster.EntityEvoker; -import net.minecraft.world.entity.monster.EntityGhast; -import net.minecraft.world.entity.monster.EntityGiantZombie; -import net.minecraft.world.entity.monster.EntityGuardian; -import net.minecraft.world.entity.monster.EntityGuardianElder; -import net.minecraft.world.entity.monster.EntityIllagerIllusioner; -import net.minecraft.world.entity.monster.EntityMagmaCube; -import net.minecraft.world.entity.monster.EntityMonster; -import net.minecraft.world.entity.monster.EntityPigZombie; -import net.minecraft.world.entity.monster.EntityPillager; -import net.minecraft.world.entity.monster.EntityRavager; -import net.minecraft.world.entity.monster.EntityShulker; -import net.minecraft.world.entity.monster.EntitySilverfish; -import net.minecraft.world.entity.monster.EntitySkeletonAbstract; -import net.minecraft.world.entity.monster.EntitySpider; -import net.minecraft.world.entity.monster.EntityStrider; -import net.minecraft.world.entity.monster.EntityVex; -import net.minecraft.world.entity.monster.EntityVindicator; -import net.minecraft.world.entity.monster.EntityWitch; -import net.minecraft.world.entity.monster.EntityZoglin; -import net.minecraft.world.entity.monster.EntityZombie; -import net.minecraft.world.entity.monster.hoglin.EntityHoglin; -import net.minecraft.world.entity.monster.piglin.EntityPiglin; -import net.minecraft.world.entity.monster.piglin.EntityPiglinBrute; -import net.minecraft.world.entity.npc.EntityVillager; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.animal.horse.Donkey; +import net.minecraft.world.entity.animal.horse.Horse; +import net.minecraft.world.entity.animal.horse.Llama; +import net.minecraft.world.entity.animal.horse.Mule; +import net.minecraft.world.entity.animal.horse.SkeletonHorse; +import net.minecraft.world.entity.animal.horse.TraderLlama; +import net.minecraft.world.entity.animal.horse.ZombieHorse; +import net.minecraft.world.entity.boss.enderdragon.EnderDragon; +import net.minecraft.world.entity.boss.wither.WitherBoss; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.entity.monster.Blaze; +import net.minecraft.world.entity.monster.CaveSpider; +import net.minecraft.world.entity.monster.Creeper; +import net.minecraft.world.entity.monster.ElderGuardian; +import net.minecraft.world.entity.monster.EnderMan; +import net.minecraft.world.entity.monster.Endermite; +import net.minecraft.world.entity.monster.Evoker; +import net.minecraft.world.entity.monster.Ghast; +import net.minecraft.world.entity.monster.Giant; +import net.minecraft.world.entity.monster.Guardian; +import net.minecraft.world.entity.monster.Husk; +import net.minecraft.world.entity.monster.Illusioner; +import net.minecraft.world.entity.monster.MagmaCube; +import net.minecraft.world.entity.monster.Phantom; +import net.minecraft.world.entity.monster.Pillager; +import net.minecraft.world.entity.monster.Ravager; +import net.minecraft.world.entity.monster.Shulker; +import net.minecraft.world.entity.monster.Silverfish; +import net.minecraft.world.entity.monster.Skeleton; +import net.minecraft.world.entity.monster.Slime; +import net.minecraft.world.entity.monster.Spider; +import net.minecraft.world.entity.monster.Stray; +import net.minecraft.world.entity.monster.Strider; +import net.minecraft.world.entity.monster.Vex; +import net.minecraft.world.entity.monster.Vindicator; +import net.minecraft.world.entity.monster.Witch; +import net.minecraft.world.entity.monster.WitherSkeleton; +import net.minecraft.world.entity.monster.Zoglin; +import net.minecraft.world.entity.monster.Zombie; +import net.minecraft.world.entity.monster.ZombieVillager; +import net.minecraft.world.entity.monster.ZombifiedPiglin; +import net.minecraft.world.entity.monster.hoglin.Hoglin; +import net.minecraft.world.entity.monster.piglin.Piglin; +import net.minecraft.world.entity.monster.piglin.PiglinBrute; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.entity.npc.WanderingTrader; +import net.minecraft.world.entity.player.Player; public class MyAttributeDefaults { - private static final FastMap, AttributeProvider> defaultAttribute = new FastMap<>(); + private static final FastMap, AttributeSupplier> defaultAttribute = new FastMap<>(); static { defaultAttribute - .putFast(EntityTypes.c, EntityArmorStand.dq().a()) //Armor-Stand - .putFast(EntityTypes.e, Axolotl.fE().a()) //Axolotl - .putFast(EntityTypes.f, EntityBat.n().a()) //Bat - .putFast(EntityTypes.g, EntityBee.fJ().a()) //Bee - .putFast(EntityTypes.h, EntityBlaze.n().a()) //Blaze - .putFast(EntityTypes.j, EntityCat.fK().a()) //Cat - .putFast(EntityTypes.k, EntityCaveSpider.n().a()) //CaveSpider - .putFast(EntityTypes.l, EntityChicken.p().a()) //Chicken - .putFast(EntityTypes.m, EntityFish.n().a()) //Cod - .putFast(EntityTypes.n, EntityCow.p().a()) //Cow - .putFast(EntityTypes.o, EntityCreeper.n().a()) //Creeper - .putFast(EntityTypes.p, EntityDolphin.fw().a()) //Dolphin - .putFast(EntityTypes.q, EntityHorseDonkey.t().a()) //Donkey - .putFast(EntityTypes.s, EntityZombie.fB().a()) //Drowned - .putFast(EntityTypes.t, EntityGuardianElder.n().a()) //Elder Guardian - .putFast(EntityTypes.w, EntityEnderman.n().a()) //Enderman - .putFast(EntityTypes.x, EntityEndermite.n().a()) //Endermite - .putFast(EntityTypes.v, EntityEnderDragon.n().a()) //Ender Dragon - .putFast(EntityTypes.y, EntityEvoker.p().a()) //Evoker - .putFast(EntityTypes.E, EntityFox.p().a()) //Fox - .putFast(EntityTypes.F, EntityGhast.t().a()) //Ghast - .putFast(EntityTypes.G, EntityGiantZombie.n().a()) //Giant - .putFast(EntityTypes.K, EntityGuardian.fw().a()) //Guardian - .putFast(EntityTypes.J, Goat.p().a()) //Goat - .putFast(EntityTypes.I, GlowSquid.fw().a()) //GlowSquid - .putFast(EntityTypes.L, EntityHoglin.p().a()) //Hoglin - .putFast(EntityTypes.M, EntityHorse.fS().a()) //Horse - .putFast(EntityTypes.N, EntityZombie.fB().a()) //Husk - .putFast(EntityTypes.O, EntityIllagerIllusioner.p().a()) //Illusioner - .putFast(EntityTypes.P, EntityIronGolem.n().a()) //Iron Golem - .putFast(EntityTypes.V, EntityLlama.gg().a()) //Llama - .putFast(EntityTypes.X, EntityMagmaCube.n().a()) //Magma Cube - .putFast(EntityTypes.ah, EntityCow.p().a()) //Mooshroom - .putFast(EntityTypes.ag, EntityHorseMule.t().a()) //Mule - .putFast(EntityTypes.ai, EntityOcelot.p().a()) //Ocelot - .putFast(EntityTypes.ak, EntityPanda.fI().a()) //Panda - .putFast(EntityTypes.al, EntityParrot.fE().a()) //Parrot - .putFast(EntityTypes.am, EntityMonster.fB().a()) //Phantom - .putFast(EntityTypes.an, EntityPig.p().a()) //Pig - .putFast(EntityTypes.ao, EntityPiglin.fB().a()) //Piglin - .putFast(EntityTypes.ap, EntityPiglinBrute.fB().a()) //Piglin Brute - .putFast(EntityTypes.aq, EntityPillager.p().a()) //Pillager - .putFast(EntityTypes.bi, EntityHuman.eY().a()) //Player - .putFast(EntityTypes.ar, EntityPolarBear.p().a()) //PolarBear - .putFast(EntityTypes.at, EntityFish.n().a()) //Pufferfish - .putFast(EntityTypes.au, EntityRabbit.t().a()) //Rabbit - .putFast(EntityTypes.av, EntityRavager.n().a()) //Ravager - .putFast(EntityTypes.aw, EntityFish.n().a()) //Salmon - .putFast(EntityTypes.ax, EntitySheep.p().a()) //Sheep - .putFast(EntityTypes.ay, EntityShulker.n().a()) //Shulker - .putFast(EntityTypes.aA, EntitySilverfish.n().a()) //Silverfish - .putFast(EntityTypes.aB, EntitySkeletonAbstract.n().a()) //Skeleton - .putFast(EntityTypes.aC, EntityHorseSkeleton.t().a()) //Skeleton Horse - .putFast(EntityTypes.aD, EntityMonster.fB().a()) //Slime - .putFast(EntityTypes.aF, EntitySnowman.n().a()) //Snow Golem - .putFast(EntityTypes.aI, EntitySpider.p().a()) //Spider - .putFast(EntityTypes.aJ, EntitySquid.fw().a()) //Squid - .putFast(EntityTypes.aK, EntitySkeletonAbstract.n().a()) //Stray - .putFast(EntityTypes.aL, EntityStrider.fw().a()) //Strider - .putFast(EntityTypes.aR, EntityLlama.gg().a()) //Trader_Llama - .putFast(EntityTypes.aS, EntityFish.n().a()) //Tropical Fish - .putFast(EntityTypes.aT, EntityTurtle.fw().a()) //Turtle - .putFast(EntityTypes.aU, EntityVex.n().a()) //Vex - .putFast(EntityTypes.aV, EntityVillager.fI().a()) //Villager - .putFast(EntityTypes.aW, EntityVindicator.p().a()) //Vindicator - .putFast(EntityTypes.aX, EntityInsentient.w().a()) //Wandering Trader - .putFast(EntityTypes.aY, EntityWitch.p().a()) //Witch - .putFast(EntityTypes.aZ, EntityWither.p().a()) //Wither - .putFast(EntityTypes.ba, EntitySkeletonAbstract.n().a()) //Wither Skeleton - .putFast(EntityTypes.bc, EntityWolf.fE().a()) //Wolf - .putFast(EntityTypes.bd, EntityZoglin.n().a()) //Zoglin - .putFast(EntityTypes.be, EntityZombie.fB().a()) //Zombie - .putFast(EntityTypes.bf, EntityHorseZombie.t().a()) //Zombie Horse - .putFast(EntityTypes.bg, EntityZombie.fB().a()) //Zombie Villager - .putFast(EntityTypes.bh, EntityPigZombie.fG().a()); //Zombie Piglin + .putFast(EntityType.ARMOR_STAND, ArmorStand.createLivingAttributes().build()) //Armor-Stand + .putFast(EntityType.AXOLOTL, Axolotl.createAttributes().build()) //Axolotl + .putFast(EntityType.BAT, Bat.createAttributes().build()) //Bat + .putFast(EntityType.BEE, Bee.createAttributes().build()) //Bee + .putFast(EntityType.BLAZE, Blaze.createAttributes().build()) //Blaze + .putFast(EntityType.CAT, Cat.createAttributes().build()) //Cat + .putFast(EntityType.CAVE_SPIDER, CaveSpider.createAttributes().build()) //CaveSpider + .putFast(EntityType.CHICKEN, Chicken.createAttributes().build()) //Chicken + .putFast(EntityType.COD, Cod.createAttributes().build()) //Cod + .putFast(EntityType.COW, Cow.createAttributes().build()) //Cow + .putFast(EntityType.CREEPER, Creeper.createAttributes().build()) //Creeper + .putFast(EntityType.DOLPHIN, Dolphin.createAttributes().build()) //Dolphin + .putFast(EntityType.DONKEY, Donkey.createLivingAttributes().build()) //Donkey + .putFast(EntityType.ZOMBIE, Zombie.createAttributes().build()) //Drowned + .putFast(EntityType.ELDER_GUARDIAN, ElderGuardian.createAttributes().build()) //Elder Guardian + .putFast(EntityType.ENDERMAN, EnderMan.createAttributes().build()) //Enderman + .putFast(EntityType.ENDERMITE, Endermite.createAttributes().build()) //Endermite + .putFast(EntityType.ENDER_DRAGON, EnderDragon.createAttributes().build()) //Ender Dragon + .putFast(EntityType.EVOKER, Evoker.createAttributes().build()) //Evoker + .putFast(EntityType.FOX, Fox.createAttributes().build()) //Fox + .putFast(EntityType.GHAST, Ghast.createAttributes().build()) //Ghast + .putFast(EntityType.GIANT, Giant.createAttributes().build()) //Giant + .putFast(EntityType.GUARDIAN, Guardian.createAttributes().build()) //Guardian + .putFast(EntityType.GOAT, Goat.createAttributes().build()) //Goat + .putFast(EntityType.GLOW_SQUID, GlowSquid.createAttributes().build()) //GlowSquid + .putFast(EntityType.HOGLIN, Hoglin.createAttributes().build()) //Hoglin + .putFast(EntityType.HORSE, Horse.createBaseHorseAttributes().build()) //Horse + .putFast(EntityType.HUSK, Husk.createAttributes().build()) //Husk + .putFast(EntityType.ILLUSIONER, Illusioner.createAttributes().build()) //Illusioner + .putFast(EntityType.IRON_GOLEM, IronGolem.createAttributes().build()) //Iron Golem + .putFast(EntityType.LLAMA, Llama.createAttributes().build()) //Llama + .putFast(EntityType.MAGMA_CUBE, MagmaCube.createAttributes().build()) //Magma Cube + .putFast(EntityType.COW, Cow.createAttributes().build()) //Mooshroom + .putFast(EntityType.MULE, Mule.createLivingAttributes().build()) //Mule + .putFast(EntityType.OCELOT, Ocelot.createAttributes().build()) //Ocelot + .putFast(EntityType.PANDA, Panda.createAttributes().build()) //Panda + .putFast(EntityType.PARROT, Parrot.createAttributes().build()) //Parrot + .putFast(EntityType.PHANTOM, Phantom.createLivingAttributes().build()) //Phantom + .putFast(EntityType.PIG, Pig.createAttributes().build()) //Pig + .putFast(EntityType.PIGLIN, Piglin.createAttributes().build()) //Piglin + .putFast(EntityType.PIGLIN_BRUTE, PiglinBrute.createAttributes().build()) //Piglin Brute + .putFast(EntityType.PILLAGER, Pillager.createAttributes().build()) //Pillager + .putFast(EntityType.PLAYER, Player.createAttributes().build()) //Player + .putFast(EntityType.POLAR_BEAR, PolarBear.createAttributes().build()) //PolarBear + .putFast(EntityType.PUFFERFISH, Pufferfish.createAttributes().build()) //Pufferfish + .putFast(EntityType.RABBIT, Rabbit.createAttributes().build()) //Rabbit + .putFast(EntityType.RAVAGER, Ravager.createAttributes().build()) //Ravager + .putFast(EntityType.SALMON, Salmon.createAttributes().build()) //Salmon + .putFast(EntityType.SHEEP, Sheep.createAttributes().build()) //Sheep + .putFast(EntityType.SHULKER, Shulker.createAttributes().build()) //Shulker + .putFast(EntityType.SILVERFISH, Silverfish.createAttributes().build()) //Silverfish + .putFast(EntityType.SKELETON, Skeleton.createAttributes().build()) //Skeleton + .putFast(EntityType.SKELETON_HORSE, SkeletonHorse.createAttributes().build()) //Skeleton Horse + .putFast(EntityType.SLIME, Slime.createLivingAttributes().build()) //Slime + .putFast(EntityType.SNOW_GOLEM, SnowGolem.createAttributes().build()) //Snow Golem + .putFast(EntityType.SPIDER, Spider.createAttributes().build()) //Spider + .putFast(EntityType.SQUID, Squid.createAttributes().build()) //Squid + .putFast(EntityType.STRAY, Stray.createAttributes().build()) //Stray + .putFast(EntityType.STRIDER, Strider.createAttributes().build()) //Strider + .putFast(EntityType.TRADER_LLAMA, TraderLlama.createAttributes().build()) //Trader_Llama + .putFast(EntityType.TROPICAL_FISH, TropicalFish.createAttributes().build()) //Tropical Fish + .putFast(EntityType.TURTLE, Turtle.createAttributes().build()) //Turtle + .putFast(EntityType.VEX, Vex.createAttributes().build()) //Vex + .putFast(EntityType.VILLAGER, Villager.createAttributes().build()) //Villager + .putFast(EntityType.VINDICATOR, Vindicator.createAttributes().build()) //Vindicator + .putFast(EntityType.WANDERING_TRADER, WanderingTrader.createLivingAttributes().build()) //Wandering Trader + .putFast(EntityType.WITCH, Witch.createAttributes().build()) //Witch + .putFast(EntityType.WITHER, WitherBoss.createAttributes().build()) //Wither + .putFast(EntityType.WITHER_SKELETON, WitherSkeleton.createAttributes().build()) //Wither Skeleton + .putFast(EntityType.WOLF, Wolf.createAttributes().build()) //Wolf + .putFast(EntityType.ZOGLIN, Zoglin.createAttributes().build()) //Zoglin + .putFast(EntityType.ZOMBIE, Zombie.createAttributes().build()) //Zombie + .putFast(EntityType.ZOMBIE_HORSE, ZombieHorse.createAttributes().build()) //Zombie Horse + .putFast(EntityType.ZOMBIE_VILLAGER, ZombieVillager.createAttributes().build()) //Zombie Villager + .putFast(EntityType.ZOMBIFIED_PIGLIN, ZombifiedPiglin.createAttributes().build()); //Zombie Piglin } - public static AttributeProvider getAttribute(EntityTypes types) { + public static AttributeSupplier getAttribute(EntityType types) { return defaultAttribute.get(types); } - public static void registerCustomEntityTypes(EntityTypes customType, EntityTypes rootType) { + public static void registerCustomEntityType(EntityType customType, EntityType rootType) { defaultAttribute.put(customType, getAttribute(rootType)); } static class FastMap extends HashMap { - public FastMap putFast(K key, V value) { - put(key, value); + public FastMap putFast(K key, AttributeSupplier attributeSupplier) { + put(key, (V) attributeSupplier); return this; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/attack/MeleeAttack.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/attack/MeleeAttack.java index 756c641d1d..8ad175aa20 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/attack/MeleeAttack.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/attack/MeleeAttack.java @@ -20,6 +20,9 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.entity.LivingEntity; + import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPetEquipment; @@ -27,20 +30,17 @@ import de.Keyle.MyPet.api.skill.skills.Behavior; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTameableAnimal; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.entity.LivingEntity; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.decoration.ArmorStand; @Compat("v1_17_R1") public class MeleeAttack implements AIGoal { MyPet myPet; EntityMyPet petEntity; - EntityLiving targetEntity; + net.minecraft.world.entity.LivingEntity targetEntity; double range; float walkSpeedModifier; private int ticksUntilNextHitLeft = 0; @@ -63,12 +63,12 @@ public boolean shouldStart() { if (!this.petEntity.hasTarget()) { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + net.minecraft.world.entity.LivingEntity targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); - if (targetEntity instanceof EntityArmorStand) { + if (targetEntity instanceof ArmorStand) { return false; } - if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.h(targetEntity.locX(), targetEntity.getBoundingBox().b, targetEntity.locZ()) >= 20) { + if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.distanceToSqr(targetEntity.getX(), targetEntity.getBoundingBox().minY, targetEntity.getY()) >= 20) { return false; } @@ -78,13 +78,13 @@ public boolean shouldStart() { return false; } if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Raid) { - if (targetEntity instanceof EntityTameableAnimal && ((EntityTameableAnimal) targetEntity).isTamed()) { + if (targetEntity instanceof TamableAnimal && ((TamableAnimal) targetEntity).isTame()) { return false; } if (targetEntity instanceof EntityMyPet) { return false; } - if (targetEntity instanceof EntityPlayer) { + if (targetEntity instanceof ServerPlayer) { return false; } } @@ -97,10 +97,10 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!this.petEntity.hasTarget() || !this.petEntity.canMove()) { return true; - } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getTarget()) { + } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getMyPetTarget()) { return true; } - if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.h(targetEntity.locX(), targetEntity.getBoundingBox().b, targetEntity.locZ()) >= 20) { + if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.distanceToSqr(targetEntity.getX(), targetEntity.getBoundingBox().minY, targetEntity.getZ()) >= 20) { return true; } @@ -110,13 +110,13 @@ public boolean shouldFinish() { return true; } if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Raid) { - if (this.targetEntity instanceof EntityTameableAnimal && ((EntityTameableAnimal) this.targetEntity).isTamed()) { + if (this.targetEntity instanceof TamableAnimal && ((TamableAnimal) this.targetEntity).isTame()) { return true; } if (this.targetEntity instanceof EntityMyPet) { return true; } - return this.targetEntity instanceof EntityPlayer; + return this.targetEntity instanceof ServerPlayer; } } return false; @@ -125,7 +125,7 @@ public boolean shouldFinish() { @Override public void start() { this.petEntity.getPetNavigation().getParameters().addSpeedModifier("MeleeAttack", walkSpeedModifier); - this.petEntity.getPetNavigation().navigateTo((LivingEntity) this.targetEntity.getBukkitEntity()); + this.petEntity.getPetNavigation().navigateTo((LivingEntity) this.targetEntity.getBukkitEntity()); this.timeUntilNextNavigationUpdate = 0; } @@ -138,17 +138,17 @@ public void finish() { @Override public void tick() { - this.petEntity.getControllerLook().a(targetEntity, 30.0F, 30.0F); + this.petEntity.getLookControl().setLookAt(targetEntity, 30.0F, 30.0F); if (--this.timeUntilNextNavigationUpdate <= 0) { this.timeUntilNextNavigationUpdate = (4 + this.petEntity.getRandom().nextInt(7)); this.petEntity.getPetNavigation().navigateTo((LivingEntity) targetEntity.getBukkitEntity()); } - if (this.petEntity.h(targetEntity.locX(), targetEntity.getBoundingBox().b, targetEntity.locZ()) - (targetEntity.getHeight() * (2. / 3.)) <= this.range && this.ticksUntilNextHitLeft-- <= 0) { - if (this.petEntity.getEntitySenses().a(targetEntity)) { + if (this.petEntity.distanceToSqr(targetEntity.getX(), targetEntity.getBoundingBox().minY, targetEntity.getZ()) - (targetEntity.getBbHeight() * (2. / 3.)) <= this.range && this.ticksUntilNextHitLeft-- <= 0) { + if (this.petEntity.getSensing().hasLineOfSight(targetEntity)) { this.ticksUntilNextHitLeft = ticksUntilNextHit; if (this.petEntity instanceof MyPetEquipment) { if (((MyPetEquipment) this.petEntity).getEquipment(EquipmentSlot.MainHand) != null) { - this.petEntity.swingHand(EnumHand.a); // -> swingItem() + this.petEntity.swing(InteractionHand.MAIN_HAND); // -> swingItem() } } this.petEntity.attack(targetEntity); diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/attack/RangedAttack.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/attack/RangedAttack.java index eb42acf194..54be8ccc5a 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/attack/RangedAttack.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/attack/RangedAttack.java @@ -20,6 +20,8 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; + import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.ai.AIGoal; import de.Keyle.MyPet.api.skill.skills.Behavior; @@ -27,22 +29,30 @@ import de.Keyle.MyPet.api.skill.skills.Ranged.Projectile; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.*; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTameableAnimal; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import net.minecraft.world.entity.projectile.EntityArrow; -import net.minecraft.world.level.World; -import net.royawesome.jlibnoise.MathHelper; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetArrow; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetDragonFireball; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetEgg; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetEnderPearl; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetLargeFireball; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetLlamaSpit; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetSmallFireball; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetSnowball; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetTrident; +import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.nms.MyPetWitherSkull; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.entity.projectile.Arrow; +import net.minecraft.world.level.Level; @Compat("v1_17_R1") public class RangedAttack implements AIGoal { private final MyPet myPet; private final EntityMyPet entityMyPet; - private EntityLiving target; + private LivingEntity target; private int shootTimer; private final float walkSpeedModifier; private int lastSeenTimer; @@ -69,13 +79,13 @@ public boolean shouldStart() { return false; } - EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getTarget()).getHandle(); + LivingEntity target = ((CraftLivingEntity) this.entityMyPet.getMyPetTarget()).getHandle(); - if (target instanceof EntityArmorStand) { + if (target instanceof ArmorStand) { return false; } double meleeDamage = myPet.getDamage(); - if (meleeDamage > 0 && this.entityMyPet.h(target.locX(), target.getBoundingBox().b, target.locZ()) < 4) { + if (meleeDamage > 0 && this.entityMyPet.distanceToSqr(target.getX(), target.getBoundingBox().minY, target.getZ()) < 4) { Ranged rangedSkill = myPet.getSkills().get(Ranged.class); if (meleeDamage > rangedSkill.getDamage().getValue().doubleValue()) { return false; @@ -88,13 +98,13 @@ public boolean shouldStart() { return false; } if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Raid) { - if (target instanceof EntityTameableAnimal && ((EntityTameableAnimal) target).isTamed()) { + if (target instanceof TamableAnimal && ((TamableAnimal) target).isTame()) { return false; } if (target instanceof EntityMyPet) { return false; } - if (target instanceof EntityPlayer) { + if (target instanceof ServerPlayer) { return false; } } @@ -108,11 +118,11 @@ public boolean shouldFinish() { if (!entityMyPet.hasTarget() || myPet.getRangedDamage() <= 0 || !entityMyPet.canMove()) { return true; } - if (this.target.getBukkitEntity() != entityMyPet.getTarget()) { + if (this.target != entityMyPet.getTarget()) { return true; } double meleeDamage = myPet.getDamage(); - if (meleeDamage > 0 && this.entityMyPet.h(target.locX(), this.target.getBoundingBox().b, target.locZ()) < 4) { + if (meleeDamage > 0 && this.entityMyPet.distanceToSqr(target.getX(), this.target.getBoundingBox().minY, target.getZ()) < 4) { Ranged rangedSkill = myPet.getSkills().get(Ranged.class); if (meleeDamage > rangedSkill.getDamage().getValue().doubleValue()) { return true; @@ -125,13 +135,13 @@ public boolean shouldFinish() { return true; } if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Raid) { - if (this.target instanceof EntityTameableAnimal && ((EntityTameableAnimal) this.target).isTamed()) { + if (this.target instanceof TamableAnimal && ((TamableAnimal) this.target).isTame()) { return true; } if (this.target instanceof EntityMyPet) { return true; } - return this.target instanceof EntityPlayer; + return this.target instanceof ServerPlayer; } } return false; @@ -147,8 +157,8 @@ public void finish() { @Override public void tick() { - double distanceToTarget = this.entityMyPet.h(this.target.locX(), this.target.getBoundingBox().b, this.target.locZ()); - boolean canSee = this.entityMyPet.getEntitySenses().a(this.target); // a -> canSee + double distanceToTarget = this.entityMyPet.distanceToSqr(this.target.getX(), this.target.getBoundingBox().minY, this.target.getZ()); + boolean canSee = this.entityMyPet.getSensing().hasLineOfSight(this.target); if (canSee) { this.lastSeenTimer++; @@ -164,7 +174,7 @@ public void tick() { this.entityMyPet.getPetNavigation().navigateTo(this.target.getBukkitEntity().getLocation()); } - this.entityMyPet.getControllerLook().a(this.target, 30.0F, 30.0F); + this.entityMyPet.getLookControl().setLookAt(this.target, 30.0F, 30.0F); if (--this.shootTimer <= 0) { if (distanceToTarget < this.range && canSee) { @@ -183,128 +193,128 @@ private Projectile getProjectile() { return Projectile.Arrow; } - public void shootProjectile(EntityLiving target, float damage, Projectile projectile) { - World world = target.t; + public void shootProjectile(LivingEntity target, float damage, Projectile projectile) { + Level world = target.level; - double minY = this.target.getBoundingBox().b; + double minY = this.target.getBoundingBox().minY; switch (projectile) { case Snowball: { MyPetSnowball snowball = new MyPetSnowball(world, entityMyPet); - double distanceX = target.locX() - entityMyPet.locX(); - double distanceY = target.locY() + target.getHeadHeight() - 1.100000023841858D - snowball.locY(); - double distanceZ = target.locZ() - entityMyPet.locZ(); - double distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F; + double distanceX = target.getX() - entityMyPet.getX(); + double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - snowball.getY(); + double distanceZ = target.getZ() - entityMyPet.getZ(); + double distance20percent = Mth.sqrt((float)(distanceX * distanceX + distanceZ * distanceZ)) * 0.2F; snowball.setDamage(damage); snowball.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1); entityMyPet.makeSound("entity.arrow.shoot", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F)); - world.addEntity(snowball); + world.addFreshEntity(snowball); break; } case Egg: { MyPetEgg egg = new MyPetEgg(world, entityMyPet); - double distanceX = target.locX() - entityMyPet.locX(); - double distanceY = target.locY() + target.getHeadHeight() - 1.100000023841858D - egg.locY(); - double distanceZ = target.locZ() - entityMyPet.locZ(); - double distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F; + double distanceX = target.getX() - entityMyPet.getX(); + double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - egg.getY(); + double distanceZ = target.getZ() - entityMyPet.getZ(); + double distance20percent = Mth.sqrt((float)(distanceX * distanceX + distanceZ * distanceZ)) * 0.2F; egg.setDamage(damage); egg.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1); entityMyPet.makeSound("entity.arrow.shoot", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F)); - world.addEntity(egg); + world.addFreshEntity(egg); break; } case LargeFireball: { - double distanceX = this.target.locX() - entityMyPet.locX(); - double distanceY = minY + (double) (this.target.getHeight() / 2.0F) - (0.5D + entityMyPet.locY() + (double) (entityMyPet.getHeight() / 2.0F)); - double distanceZ = this.target.locZ() - entityMyPet.locZ(); + double distanceX = this.target.getX() - entityMyPet.getX(); + double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F)); + double distanceZ = this.target.getZ() - entityMyPet.getZ(); MyPetLargeFireball largeFireball = new MyPetLargeFireball(world, entityMyPet, distanceX, distanceY, distanceZ); - largeFireball.setPositionRaw(largeFireball.locX(), (entityMyPet.locY() + entityMyPet.getHeight() / 2.0F + 0.5D), largeFireball.locZ()); + largeFireball.setPosRaw(largeFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), largeFireball.getZ()); largeFireball.setDamage(damage); - world.addEntity(largeFireball); + world.addFreshEntity(largeFireball); entityMyPet.makeSound("entity.ghast.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F); break; } case SmallFireball: { - double distanceX = this.target.locX() - entityMyPet.locX(); - double distanceY = minY + (this.target.getHeight() / 2.0F) - (0.5D + entityMyPet.locY() + (entityMyPet.getHeight() / 2.0F)); - double distanceZ = this.target.locZ() - entityMyPet.locZ(); + double distanceX = this.target.getX() - entityMyPet.getX(); + double distanceY = minY + (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (entityMyPet.getBbHeight() / 2.0F)); + double distanceZ = this.target.getZ() - entityMyPet.getZ(); MyPetSmallFireball smallFireball = new MyPetSmallFireball(world, entityMyPet, distanceX, distanceY, distanceZ); - smallFireball.setPositionRaw(smallFireball.locX(), (entityMyPet.locY() + entityMyPet.getHeight() / 2.0F + 0.5D), smallFireball.locZ()); + smallFireball.setPosRaw(smallFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), smallFireball.getZ()); smallFireball.setDamage(damage); - world.addEntity(smallFireball); + world.addFreshEntity(smallFireball); entityMyPet.makeSound("entity.ghast.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F); break; } case WitherSkull: { - double distanceX = this.target.locX() - entityMyPet.locX(); - double distanceY = minY + (double) (this.target.getHeight() / 2.0F) - (0.5D + entityMyPet.locY() + (double) (entityMyPet.getHeight() / 2.0F)); - double distanceZ = this.target.locZ() - entityMyPet.locZ(); + double distanceX = this.target.getX() - entityMyPet.getX(); + double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F)); + double distanceZ = this.target.getZ() - entityMyPet.getZ(); MyPetWitherSkull witherSkull = new MyPetWitherSkull(world, entityMyPet, distanceX, distanceY, distanceZ); - witherSkull.setPositionRaw(witherSkull.locX(), (entityMyPet.locY() + entityMyPet.getHeight() / 2.0F + 0.5D), witherSkull.locZ()); + witherSkull.setPosRaw(witherSkull.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), witherSkull.getZ()); witherSkull.setDamage(damage); - world.addEntity(witherSkull); + world.addFreshEntity(witherSkull); entityMyPet.makeSound("entity.wither.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F); break; } case DragonFireball: { - double distanceX = this.target.locX() - entityMyPet.locX(); - double distanceY = minY + (double) (this.target.getHeight() / 2.0F) - (0.5D + entityMyPet.locY() + (double) (entityMyPet.getHeight() / 2.0F)); - double distanceZ = this.target.locZ() - entityMyPet.locZ(); + double distanceX = this.target.getX() - entityMyPet.getX(); + double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F)); + double distanceZ = this.target.getZ() - entityMyPet.getZ(); MyPetDragonFireball dragonFireball = new MyPetDragonFireball(world, entityMyPet, distanceX, distanceY, distanceZ); - dragonFireball.setPositionRaw(dragonFireball.locX(), (entityMyPet.locY() + entityMyPet.getHeight() / 2.0F + 0.5D), dragonFireball.locZ()); + dragonFireball.setPosRaw(dragonFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), dragonFireball.getZ()); dragonFireball.setDamage(damage); - world.addEntity(dragonFireball); + world.addFreshEntity(dragonFireball); entityMyPet.makeSound("entity.ender_dragon.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F); break; } case Trident: { MyPetTrident trident = new MyPetTrident(world, entityMyPet); - trident.setDamage(damage); - trident.setCritical(false); + trident.setBaseDamage(damage); + trident.setCritArrow(false); entityMyPet.makeSound("item.trident.throw", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F)); - double distanceX = target.locX() - entityMyPet.locX(); - double distanceY = target.locY() + target.getHeadHeight() - 1.100000023841858D - trident.locY(); - double distanceZ = target.locZ() - entityMyPet.locZ(); - double distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F; + double distanceX = target.getX() - entityMyPet.getX(); + double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - trident.getY(); + double distanceZ = target.getZ() - entityMyPet.getZ(); + double distance20percent = Mth.sqrt((float)(distanceX * distanceX + distanceZ * distanceZ)) * 0.2F; trident.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1); - world.addEntity(trident); + world.addFreshEntity(trident); break; } case EnderPearl: { MyPetEnderPearl enderPearl = new MyPetEnderPearl(world, entityMyPet); enderPearl.setDamage(damage); entityMyPet.makeSound("entity.ender_pearl.throw", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F)); - double distanceX = target.locX() - entityMyPet.locX(); - double distanceY = target.locY() + target.getHeadHeight() - 1.100000023841858D - enderPearl.locY(); - double distanceZ = target.locZ() - entityMyPet.locZ(); - double distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F; + double distanceX = target.getX() - entityMyPet.getX(); + double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - enderPearl.getY(); + double distanceZ = target.getZ() - entityMyPet.getZ(); + double distance20percent = Mth.sqrt((float)(distanceX * distanceX + distanceZ * distanceZ)) * 0.2F; enderPearl.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1); - world.addEntity(enderPearl); + world.addFreshEntity(enderPearl); break; } case LlamaSpit: { MyPetLlamaSpit llamaSpit = new MyPetLlamaSpit(world, entityMyPet); llamaSpit.setDamage(damage); entityMyPet.makeSound("entity.llama.spit", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F)); - double distanceX = target.locX() - entityMyPet.locX(); - double distanceY = target.locY() + (target.getHeadHeight() / 3.0F) - llamaSpit.locY(); - double distanceZ = target.locZ() - entityMyPet.locZ(); - double distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2D; + double distanceX = target.getX() - entityMyPet.getX(); + double distanceY = target.getY() + (target.getEyeHeight() / 3.0F) - llamaSpit.getY(); + double distanceZ = target.getZ() - entityMyPet.getZ(); + double distance20percent = Mth.sqrt((float)(distanceX * distanceX + distanceZ * distanceZ)) * 0.2D; llamaSpit.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.5F, 10.0F); - world.addEntity(llamaSpit); + world.addFreshEntity(llamaSpit); break; } case Arrow: default: { - EntityArrow arrow = new MyPetArrow(world, entityMyPet); - arrow.setDamage(damage); - arrow.setCritical(false); + Arrow arrow = new MyPetArrow(world, entityMyPet); + arrow.setBaseDamage(damage); + arrow.setCritArrow(false); entityMyPet.makeSound("entity.arrow.shoot", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F)); - double distanceX = target.locX() - entityMyPet.locX(); - double distanceY = target.locY() + target.getHeadHeight() - 1.100000023841858D - arrow.locY(); - double distanceZ = target.locZ() - entityMyPet.locZ(); - double distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F; + double distanceX = target.getX() - entityMyPet.getX(); + double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - arrow.getY(); + double distanceZ = target.getZ() - entityMyPet.getZ(); + double distance20percent = Mth.sqrt((float)(distanceX * distanceX + distanceZ * distanceZ)) * 0.2F; arrow.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1); - world.addEntity(arrow); + world.addFreshEntity(arrow); break; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/EatGrass.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/EatGrass.java index b320548125..6150d9a76e 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/EatGrass.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/EatGrass.java @@ -20,34 +20,35 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.movement; +import java.util.function.Predicate; + +import org.bukkit.GameRule; +import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.ai.AIGoal; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.types.EntityMySheep; -import net.minecraft.core.BlockPosition; -import net.minecraft.util.MathHelper; -import net.minecraft.world.level.World; +import net.minecraft.core.BlockPos; +import net.minecraft.util.Mth; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.predicate.BlockStatePredicate; -import org.bukkit.GameRule; -import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; - -import java.util.function.Predicate; @Compat("v1_17_R1") public class EatGrass implements AIGoal { private final EntityMySheep entityMySheep; - private final World world; + private final Level world; int eatTicks = 0; - private static final Predicate GRASS = BlockStatePredicate.a(Blocks.aX); + private static final Predicate GRASS = BlockStatePredicate.forBlock(Blocks.GRASS); public EatGrass(EntityMySheep entityMySheep) { this.entityMySheep = entityMySheep; - this.world = entityMySheep.t; + this.world = entityMySheep.level; } @Override @@ -58,16 +59,16 @@ public boolean shouldStart() { return false; } else if (entityMySheep.getRandom().nextInt(1000) != 0) { return false; - } else if (this.entityMySheep.getTarget() != null && !this.entityMySheep.getTarget().isDead()) { + } else if (this.entityMySheep.getTarget() != null && !this.entityMySheep.getMyPetTarget().isDead()) { return false; } - int blockLocX = MathHelper.floor(this.entityMySheep.locX()); - int blockLocY = MathHelper.floor(this.entityMySheep.locY()); - int blockLocZ = MathHelper.floor(this.entityMySheep.locZ()); + int blockLocX = Mth.floor(this.entityMySheep.getX()); + int blockLocY = Mth.floor(this.entityMySheep.getY()); + int blockLocZ = Mth.floor(this.entityMySheep.getZ()); - BlockPosition blockposition = new BlockPosition(blockLocX, blockLocY, blockLocZ); + BlockPos blockposition = new BlockPos(blockLocX, blockLocY, blockLocZ); - return GRASS.test(this.world.getType(blockposition)) || this.world.getType(blockposition.down()).getBlock() == Blocks.aX; + return GRASS.test(this.world.getBlockState(blockposition)) || this.world.getBlockState(blockposition.down()).getBlock() == Blocks.GRASS; } @Override @@ -78,7 +79,7 @@ public boolean shouldFinish() { @Override public void start() { this.eatTicks = 30; - this.world.broadcastEntityEffect(this.entityMySheep, (byte) 10); + this.world.broadcastEntityEvent(this.entityMySheep, (byte) 10); this.entityMySheep.getPetNavigation().stop(); } @@ -90,32 +91,32 @@ public void finish() { @Override public void tick() { if (--this.eatTicks == 0) { - int blockLocX = MathHelper.floor(this.entityMySheep.locX()); - int blockLocY = MathHelper.floor(this.entityMySheep.locY()); - int blockLocZ = MathHelper.floor(this.entityMySheep.locZ()); + int blockLocX = Mth.floor(this.entityMySheep.getX()); + int blockLocY = Mth.floor(this.entityMySheep.getY()); + int blockLocZ = Mth.floor(this.entityMySheep.getZ()); - BlockPosition blockAt = new BlockPosition(blockLocX, blockLocY, blockLocZ); - if (GRASS.test(this.world.getType(blockAt))) { + BlockPos blockAt = new BlockPos(blockLocX, blockLocY, blockLocZ); + if (GRASS.test(this.world.getBlockState(blockAt))) { if (!CraftEventFactory.callEntityChangeBlockEvent( this.entityMySheep, blockAt, - Blocks.a.getBlockData(), + Blocks.AIR.defaultBlockState(), !this.world.getWorld().getGameRuleValue(GameRule.MOB_GRIEFING) ).isCancelled()) { - this.world.b(blockAt, false); + this.world.destroyBlock(blockAt, false); } entityMySheep.getMyPet().setSheared(false); } else { - BlockPosition blockUnder = blockAt.down(); - if (this.world.getType(blockUnder).getBlock() == Blocks.aX) { + BlockPos blockUnder = blockAt.down(); + if (this.world.getBlockState(blockUnder).getBlock() == Blocks.GRASS) { if (!CraftEventFactory.callEntityChangeBlockEvent( this.entityMySheep, blockAt, - Blocks.a.getBlockData(), + Blocks.AIR.defaultBlockState(), !this.world.getWorld().getGameRuleValue(GameRule.MOB_GRIEFING) ).isCancelled()) { - this.world.triggerEffect(2001, blockUnder, Block.getCombinedId(Blocks.i.getBlockData())); - this.world.setTypeAndData(blockUnder, Blocks.j.getBlockData(), 2); + this.world.levelEvent(2001, blockUnder, Block.getId(Blocks.GRASS_BLOCK.defaultBlockState())); + this.world.setBlock(blockUnder, Blocks.DIRT.defaultBlockState(), 2); } entityMySheep.getMyPet().setSheared(false); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Float.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Float.java index aeb67ef1de..24e594b9f7 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Float.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Float.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.movement; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; + import de.Keyle.MyPet.api.entity.ai.AIGoal; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.tags.TagsFluid; -import net.minecraft.world.entity.ai.navigation.Navigation; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import net.minecraft.tags.FluidTags; +import net.minecraft.world.entity.ai.navigation.PathNavigation; +import net.minecraft.world.entity.player.Player; @Compat("v1_17_R1") public class Float implements AIGoal { private final EntityMyPet entityMyPet; - private final EntityPlayer owner; + private final Player owner; private int lavaCounter = 10; private boolean inLava = false; @@ -41,7 +42,7 @@ public Float(EntityMyPet entityMyPet) { this.entityMyPet = entityMyPet; //entityMyPet.getNavigation().e(true); this.owner = ((CraftPlayer) entityMyPet.getOwner().getPlayer()).getHandle(); - ((Navigation) entityMyPet.getNavigation()).c(true); + ((PathNavigation) entityMyPet.getNavigation()).setCanFloat(true);; } @Override @@ -56,14 +57,14 @@ public void finish() { @Override public void tick() { - entityMyPet.setMot(entityMyPet.getMot().add(0, 0.05D, 0)); + entityMyPet.setDeltaMovement(entityMyPet.getDeltaMovement().add(0, 0.05D, 0)); if (inLava && lavaCounter-- <= 0) { if (entityMyPet.getPetNavigation().navigateTo(owner.getBukkitEntity())) { lavaCounter = 10; } } - if (!inLava && entityMyPet.a(TagsFluid.c)) { + if (!inLava && entityMyPet.isEyeInFluid(FluidTags.LAVA)) { inLava = true; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/FollowOwner.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/FollowOwner.java index 143a3d4e47..be80624023 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/FollowOwner.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/FollowOwner.java @@ -20,20 +20,19 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.movement; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.ai.AIGoal; import de.Keyle.MyPet.api.entity.ai.navigation.AbstractNavigation; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.server.level.EntityPlayer; import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.ai.attributes.AttributeModifiable; -import net.minecraft.world.entity.ai.attributes.GenericAttributes; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.player.Player; @Compat("v1_17_R1") public class FollowOwner implements AIGoal { @@ -45,7 +44,7 @@ public class FollowOwner implements AIGoal { private final double startDistance; private final float teleportDistance; private Control controlPathfinderGoal; - private final EntityPlayer owner; + private final Player owner; private boolean waitForGround = false; public FollowOwner(EntityMyPet entityMyPet, double startDistance, float stopDistance, float teleportDistance) { @@ -66,11 +65,11 @@ public boolean shouldStart() { } if (!this.petEntity.canMove()) { return false; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } else if (this.petEntity.getOwner() == null) { return false; - } else if (this.petEntity.f(owner) < this.startDistance) { + } else if (this.petEntity.distanceToSqr(owner) < this.startDistance) { return false; } else return controlPathfinderGoal == null || controlPathfinderGoal.moveTo == null; } @@ -81,11 +80,11 @@ public boolean shouldFinish() { return true; } else if (this.petEntity.getOwner() == null) { return true; - } else if (this.petEntity.f(owner) < this.stopDistance) { + } else if (this.petEntity.distanceToSqr(owner) < this.stopDistance) { return true; } else if (!this.petEntity.canMove()) { return true; - } else return this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead(); + } else return this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead(); } @Override @@ -109,19 +108,19 @@ public void tick() { } //Look at Owner - this.petEntity.getControllerLook().a(owner, this.petEntity.eZ(), this.petEntity.eZ()); + this.petEntity.getLookControl().setLookAt(owner, this.petEntity.getMaxHeadXRot(), this.petEntity.getMaxHeadXRot()); //TODO MIGHT be wrong (also in different places) ->getMaxHeadXRot //Teleportation if (this.petEntity.canMove()) { - if (!owner.getAbilities().b) { + if (!owner.getAbilities().flying) { if (!waitForGround) { - if (owner.J <= 4) { - if (this.petEntity.f(owner) >= this.teleportDistance) { + if (owner.flyDist <= 4) { + if (this.petEntity.distanceToSqr(owner) >= this.teleportDistance) { if (controlPathfinderGoal.moveTo == null) { if (!petEntity.hasTarget()) { if (MyPetApi.getPlatformHelper().canSpawn(ownerLocation, this.petEntity)) { - this.petEntity.J = 0; - this.petEntity.setPositionRotation(ownerLocation.getX(), ownerLocation.getY(), ownerLocation.getZ(), this.petEntity.getYRot(), this.petEntity.getXRot()); + this.petEntity.flyDist = 0; + this.petEntity.moveTo(ownerLocation.getX(), ownerLocation.getY(), ownerLocation.getZ(), this.petEntity.getYRot(), this.petEntity.getXRot()); this.setPathTimer = 0; return; } @@ -139,31 +138,31 @@ public void tick() { if (--this.setPathTimer <= 0) { this.setPathTimer = 10; if (this.nav.navigateTo(owner.getBukkitEntity())) { //TODO 2021/08/19 Seemingly not doing that properly? - applyWalkSpeed(); //It get's called so it returned true + applyWalkSpeed(); //It get's called so it returned true} } } } } private void applyWalkSpeed() { - float walkSpeed = owner.getAbilities().g; - if (owner.getAbilities().b) { + float walkSpeed = owner.getAbilities().walkingSpeed; + if (owner.getAbilities().flying) { // make the pet faster when the player is flying - walkSpeed += owner.getAbilities().f; + walkSpeed += owner.getAbilities().flyingSpeed; } else if (owner.isSprinting()) { // make the pet faster when the player is sprinting - if (owner.getAttributeMap().a(GenericAttributes.d) != null) { - walkSpeed += owner.getAttributeMap().a(GenericAttributes.d).getValue(); + if (owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED) != null) { + walkSpeed += owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED).getValue(); } - } else if (owner.isPassenger() && owner.getVehicle() instanceof EntityLiving) { + } else if (owner.isPassenger() && owner.getVehicle() instanceof LivingEntity) { // adjust the speed to the pet can catch up with the vehicle the player is in - AttributeModifiable vehicleSpeedAttribute = ((EntityLiving) owner.getVehicle()).getAttributeMap().a(GenericAttributes.d); + AttributeInstance vehicleSpeedAttribute = ((LivingEntity) owner.getVehicle()).getAttributes().getInstance(Attributes.MOVEMENT_SPEED); if (vehicleSpeedAttribute != null) { walkSpeed = (float) vehicleSpeedAttribute.getValue(); } - } else if (owner.hasEffect(MobEffects.a)) { + } else if (owner.hasEffect(MobEffects.MOVEMENT_SPEED)) { // make the pet faster when the player is has the SPEED effect - walkSpeed += owner.getEffect(MobEffects.a).getAmplifier() * 0.2 * walkSpeed; + walkSpeed += owner.getEffect(MobEffects.MOVEMENT_SPEED).getAmplifier() * 0.2 * walkSpeed; } // make the pet a little bit faster than the player so it can catch up walkSpeed += 0.07f; diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/LookAtPlayer.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/LookAtPlayer.java index 0a58f19e75..f3ecf724a5 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/LookAtPlayer.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/LookAtPlayer.java @@ -51,13 +51,13 @@ public boolean shouldStart() { if (this.petEntity.getRandom().nextFloat() >= this.lookAtPlayerChance) { return false; } - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { return false; } - this.targetPlayer = this.petEntity.t.findNearbyPlayer(this.petEntity, this.range); + this.targetPlayer = this.petEntity.level.getNearestPlayer(this.petEntity, this.range); return this.targetPlayer != null; } @@ -66,7 +66,7 @@ public boolean shouldFinish() { if (!this.targetPlayer.isAlive()) { return true; } - if (this.petEntity.f(this.targetPlayer) > this.range) { + if (this.petEntity.distanceToSqr(this.targetPlayer) > this.range) { return true; } if (this.petEntity.isVehicle()) { @@ -87,7 +87,7 @@ public void finish() { @Override public void tick() { - this.petEntity.getControllerLook().a(this.targetPlayer.locX(), this.targetPlayer.locY() + this.targetPlayer.getHeadHeight(), this.targetPlayer.locZ(), petEntity.eZ(), this.petEntity.eZ()); + this.petEntity.getLookControl().setLookAt(this.targetPlayer.getX(), this.targetPlayer.getY() + this.targetPlayer.getEyeHeight(), this.targetPlayer.getZ(), petEntity.getMaxHeadXRot(), this.petEntity.getMaxHeadXRot()); this.ticksUntilStopLooking -= 1; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/RandomLookaround.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/RandomLookaround.java index f84a5a5668..bf00997416 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/RandomLookaround.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/RandomLookaround.java @@ -38,7 +38,7 @@ public RandomLookaround(EntityMyPet petEntity) { @Override public boolean shouldStart() { - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { @@ -63,6 +63,6 @@ public void start() { @Override public void tick() { this.ticksUntilStopLookingAround--; - this.petEntity.getControllerLook().a(this.petEntity.locX() + this.directionX, this.petEntity.locY() + this.petEntity.getHeadHeight(), this.petEntity.locZ() + this.directionZ, this.petEntity.eZ(), this.petEntity.eZ()); + this.petEntity.getLookControl().setLookAt(this.petEntity.getX() + this.directionX, this.petEntity.getY() + this.petEntity.getEyeHeight(), this.petEntity.getZ() + this.directionZ, this.petEntity.getMaxHeadXRot(), this.petEntity.getMaxHeadXRot()); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Sit.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Sit.java index b5e99e9e88..a4f2aaacbc 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Sit.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Sit.java @@ -65,7 +65,7 @@ public void start() { } else if (this.entityMyPet instanceof EntityMyPanda) { ((EntityMyPanda) this.entityMyPet).updateActionsWatcher(8, true); } - entityMyPet.setGoalTarget(null); + entityMyPet.setTarget(null); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Sprint.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Sprint.java index 6e91aaa337..7da7e256ea 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Sprint.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/movement/Sprint.java @@ -20,6 +20,9 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.movement; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.scheduler.BukkitRunnable; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.ai.AIGoal; @@ -27,9 +30,7 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.skill.skills.SprintImpl; -import net.minecraft.world.entity.EntityLiving; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.scheduler.BukkitRunnable; +import net.minecraft.world.entity.LivingEntity; @Compat("v1_17_R1") public class Sprint implements AIGoal { @@ -38,7 +39,7 @@ public class Sprint implements AIGoal { private final EntityMyPet petEntity; private final float walkSpeedModifier; private final AbstractNavigation nav; - private EntityLiving lastTarget = null; + private LivingEntity lastTarget = null; public Sprint(EntityMyPet entityMyPet, float walkSpeedModifier) { this.petEntity = entityMyPet; @@ -59,7 +60,7 @@ public boolean shouldStart() { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + LivingEntity targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!targetEntity.isAlive()) { return false; @@ -67,7 +68,7 @@ public boolean shouldStart() { if (lastTarget == targetEntity) { return false; } - if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.f(targetEntity) >= 16) { + if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.distanceToSqr(targetEntity) >= 16) { return false; } this.lastTarget = targetEntity; @@ -78,7 +79,7 @@ public boolean shouldStart() { public boolean shouldFinish() { if (this.petEntity.getOwner() == null) { return true; - } else if (this.petEntity.f(this.lastTarget) < 16) { + } else if (this.petEntity.distanceToSqr(this.lastTarget) < 16) { return true; } else return !this.petEntity.canMove(); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/navigation/VanillaNavigation.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/navigation/VanillaNavigation.java index 1cb9b4240c..61935bfc4d 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/navigation/VanillaNavigation.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/navigation/VanillaNavigation.java @@ -20,42 +20,40 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.navigation; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.entity.LivingEntity; + import de.Keyle.MyPet.api.entity.ai.navigation.AbstractNavigation; import de.Keyle.MyPet.api.entity.ai.navigation.NavigationParameters; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.ai.attributes.GenericAttributes; -import net.minecraft.world.entity.ai.navigation.Navigation; - -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.navigation.PathNavigation; @Compat("v1_17_R1") public class VanillaNavigation extends AbstractNavigation { - Navigation nav; + PathNavigation nav; public VanillaNavigation(EntityMyPet entityMyPet) { super(entityMyPet); - nav = (Navigation) entityMyPet.getNavigation(); + nav = (PathNavigation) entityMyPet.getNavigation(); } public VanillaNavigation(EntityMyPet entityMyPet, NavigationParameters parameters) { super(entityMyPet, parameters); - nav = (Navigation) entityMyPet.getNavigation(); + nav = (PathNavigation) entityMyPet.getNavigation(); } @Override public void stop() { - nav.q(); + nav.stop(); } @Override public boolean navigateTo(double x, double y, double z) { applyNavigationParameters(); - if (this.nav.a(x, y, z, 1.D)) { + if (this.nav.moveTo(x, y, z, 1.D)) { applyNavigationParameters(); return true; } @@ -67,8 +65,8 @@ public boolean navigateTo(LivingEntity entity) { return navigateTo(((CraftLivingEntity) entity).getHandle()); } - public boolean navigateTo(EntityLiving entity) { - if (this.nav.a(entity, 1.D)) { + public boolean navigateTo(net.minecraft.world.entity.LivingEntity entity) { + if (this.nav.moveTo(entity, 1.D)) { applyNavigationParameters(); return true; } @@ -77,14 +75,14 @@ public boolean navigateTo(EntityLiving entity) { @Override public void tick() { - nav.c(); + nav.tick(); } @Override public void applyNavigationParameters() { - this.nav.a(parameters.avoidWater()); + this.nav.setCanFloat(parameters.avoidWater()); ((EntityMyPet) this.entityMyPet) - .getAttributeInstance(GenericAttributes.d) - .setValue(parameters.speed() + parameters.speedModifier()); + .getAttribute(Attributes.MOVEMENT_SPEED) + .setBaseValue(parameters.speed() + parameters.speedModifier()); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorAggressiveTarget.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorAggressiveTarget.java index 9af83e7c4e..f04942666b 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorAggressiveTarget.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorAggressiveTarget.java @@ -20,6 +20,11 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.target; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.ai.AIGoal; @@ -28,22 +33,17 @@ import de.Keyle.MyPet.api.skill.skills.Behavior.BehaviorMode; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTameableAnimal; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.decoration.ArmorStand; @Compat("v1_17_R1") public class BehaviorAggressiveTarget implements AIGoal { private final MyPet myPet; private final EntityMyPet petEntity; - private final EntityPlayer petOwnerEntity; - private EntityLiving target; + private final ServerPlayer petOwnerEntity; + private net.minecraft.world.entity.LivingEntity target; private final float range; public BehaviorAggressiveTarget(EntityMyPet petEntity, float range) { @@ -69,9 +69,9 @@ public boolean shouldStart() { return false; } - for (EntityLiving entityLiving : this.petEntity.t.a(EntityLiving.class, this.petOwnerEntity.getBoundingBox().grow(range, range, range))) { - if (entityLiving != petEntity && !(entityLiving instanceof EntityArmorStand) && entityLiving.isAlive() && petEntity.f(entityLiving) <= 91) { - if (entityLiving instanceof EntityPlayer) { + for (net.minecraft.world.entity.LivingEntity entityLiving : this.petEntity.level.getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, this.petOwnerEntity.getBoundingBox().inflate(range, range, range))) { + if (entityLiving != petEntity && !(entityLiving instanceof ArmorStand) && entityLiving.isAlive() && petEntity.distanceToSqr(entityLiving) <= 91) { + if (entityLiving instanceof ServerPlayer) { Player targetPlayer = (Player) entityLiving.getBukkitEntity(); if (myPet.getOwner().equals(targetPlayer)) { continue; @@ -84,9 +84,9 @@ public boolean shouldStart() { if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) { continue; } - } else if (entityLiving instanceof EntityTameableAnimal) { - EntityTameableAnimal tameable = (EntityTameableAnimal) entityLiving; - if (tameable.isTamed() && tameable.getOwner() != null) { + } else if (entityLiving instanceof TamableAnimal) { + TamableAnimal tameable = (TamableAnimal) entityLiving; + if (tameable.isTame() && tameable.getOwner() != null) { Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity(); if (myPet.getOwner().equals(tameableOwner)) { continue; @@ -112,7 +112,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) petEntity.getTarget()).getHandle(); + net.minecraft.world.entity.LivingEntity target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -122,16 +122,16 @@ public boolean shouldFinish() { return true; } else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) { return true; - } else if (target.t != petEntity.t) { + } else if (target.level != petEntity.level) { return true; - } else if (petEntity.f(target) > 400) { + } else if (petEntity.distanceToSqr(target) > 400) { return true; - } else return petEntity.f(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; + } else return petEntity.distanceToSqr(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; } @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorDuelTarget.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorDuelTarget.java index 0e906829af..010b9e6935 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorDuelTarget.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorDuelTarget.java @@ -20,6 +20,9 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.target; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; + import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.ai.AIGoal; @@ -29,17 +32,15 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.skill.skills.BehaviorImpl; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.entity.EntityLiving; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.LivingEntity; @Compat("v1_17_R1") public class BehaviorDuelTarget implements AIGoal { private final MyPet myPet; private final EntityMyPet petEntity; - private final EntityPlayer petOwnerEntity; + private final ServerPlayer petOwnerEntity; private MyPetMinecraftEntity target; private MyPetMinecraftEntity duelOpponent = null; private final float range; @@ -71,7 +72,7 @@ public boolean shouldStart() { return true; } - for (EntityMyPet entityMyPet : this.petEntity.t.a(EntityMyPet.class, this.petOwnerEntity.getBoundingBox().grow(range, range, range))) { + for (EntityMyPet entityMyPet : this.petEntity.level.getEntitiesOfClass(EntityMyPet.class, this.petOwnerEntity.getBoundingBox().inflate(range, range, range))) { MyPet targetMyPet = entityMyPet.getMyPet(); if (entityMyPet != petEntity && entityMyPet.isAlive()) { @@ -100,23 +101,23 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + LivingEntity target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); Behavior behaviorSkill = myPet.getSkills().get(Behavior.class); if (behaviorSkill.getBehavior() != BehaviorMode.Duel) { return true; } else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) { return true; - } else if (target.t != petEntity.t) { + } else if (target.level != petEntity.level) { return true; - } else if (petEntity.f(target) > 400) { + } else if (petEntity.distanceToSqr(target) > 400) { return true; - } else return petEntity.f(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; + } else return petEntity.distanceToSqr(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; } @Override public void start() { - petEntity.setTarget(this.target.getBukkitEntity(), TargetPriority.Duel); + petEntity.setMyPetTarget(this.target.getBukkitEntity(), TargetPriority.Duel); setDuelOpponent(this.target); if (target.getTargetSelector().hasGoal("DuelTarget")) { BehaviorDuelTarget duelGoal = (BehaviorDuelTarget) target.getTargetSelector().getGoal("DuelTarget"); diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorFarmTarget.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorFarmTarget.java index 2bda790cfd..ef6dcca560 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorFarmTarget.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/BehaviorFarmTarget.java @@ -20,6 +20,10 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.target; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.entity.LivingEntity; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.ai.AIGoal; @@ -28,20 +32,16 @@ import de.Keyle.MyPet.api.skill.skills.Behavior.BehaviorMode; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.monster.EntityMonster; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.monster.Monster; @Compat("v1_17_R1") public class BehaviorFarmTarget implements AIGoal { private final MyPet myPet; private final EntityMyPet petEntity; - private final EntityPlayer petOwnerEntity; - private EntityLiving target; + private final ServerPlayer petOwnerEntity; + private net.minecraft.world.entity.LivingEntity target; private final float range; public BehaviorFarmTarget(EntityMyPet petEntity, float range) { @@ -67,8 +67,8 @@ public boolean shouldStart() { return false; } - for (EntityMonster entityMonster : this.petEntity.t.a(EntityMonster.class, this.petOwnerEntity.getBoundingBox().grow(range, range, range))) { - if (!entityMonster.isAlive() || petEntity.f(entityMonster) > 91) { + for (Monster entityMonster : this.petEntity.level.getEntitiesOfClass(Monster.class, this.petOwnerEntity.getBoundingBox().inflate(range, range, range))) { + if (!entityMonster.isAlive() || petEntity.distanceToSqr(entityMonster) > 91) { continue; } if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityMonster.getBukkitEntity())) { @@ -88,7 +88,7 @@ public boolean shouldFinish() { if (!this.petEntity.hasTarget()) { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + net.minecraft.world.entity.LivingEntity target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -98,16 +98,16 @@ public boolean shouldFinish() { return true; } else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) { return true; - } else if (target.t != petEntity.t) { + } else if (target.level != petEntity.level) { return true; - } else if (petEntity.f(target) > 400) { + } else if (petEntity.distanceToSqr(target) > 400) { return true; - } else return petEntity.f(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; + } else return petEntity.distanceToSqr(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; } @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/ControlTarget.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/ControlTarget.java index 6320f5b4b0..7ba609e723 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/ControlTarget.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/ControlTarget.java @@ -20,6 +20,11 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.target; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.ai.AIGoal; @@ -29,21 +34,16 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.movement.Control; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTameableAnimal; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.decoration.ArmorStand; @Compat("v1_17_R1") public class ControlTarget implements AIGoal { private final MyPet myPet; private final EntityMyPet petEntity; - private EntityLiving target; + private net.minecraft.world.entity.LivingEntity target; private final float range; private Control controlPathfinderGoal; @@ -73,18 +73,18 @@ public boolean shouldStart() { return false; } } - for (EntityLiving entityLiving : this.petEntity.t.a(EntityLiving.class, this.petEntity.getBoundingBox().grow(this.range, 4.0D, this.range))) { - if (entityLiving != petEntity && !(entityLiving instanceof EntityArmorStand)) { - if (entityLiving instanceof EntityPlayer) { + for (net.minecraft.world.entity.LivingEntity entityLiving : this.petEntity.level.getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, this.petEntity.getBoundingBox().inflate(this.range, 4.0D, this.range))) { + if (entityLiving != petEntity && !(entityLiving instanceof ArmorStand)) { + if (entityLiving instanceof ServerPlayer) { Player targetPlayer = (Player) entityLiving.getBukkitEntity(); if (myPet.getOwner().equals(targetPlayer)) { continue; } else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) { continue; } - } else if (entityLiving instanceof EntityTameableAnimal) { - EntityTameableAnimal tameable = (EntityTameableAnimal) entityLiving; - if (tameable.isTamed() && tameable.getOwner() != null) { + } else if (entityLiving instanceof TamableAnimal) { + TamableAnimal tameable = (TamableAnimal) entityLiving; + if (tameable.isTame() && tameable.getOwner() != null) { Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity(); if (myPet.getOwner().equals(tameableOwner)) { continue; @@ -103,11 +103,11 @@ public boolean shouldStart() { } if (behaviorSkill != null) { if (behaviorSkill.getBehavior() == BehaviorMode.Raid) { - if (entityLiving instanceof EntityTameableAnimal) { + if (entityLiving instanceof TamableAnimal) { continue; } else if (entityLiving instanceof EntityMyPet) { continue; - } else if (entityLiving instanceof EntityPlayer) { + } else if (entityLiving instanceof ServerPlayer) { continue; } } @@ -130,18 +130,18 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + net.minecraft.world.entity.LivingEntity target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); - if (target.t != petEntity.t) { + if (target.level != petEntity.level) { return true; - } else if (petEntity.f(target) > 400) { + } else if (petEntity.distanceToSqr(target) > 400) { return true; - } else return petEntity.f(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; + } else return petEntity.distanceToSqr(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; } @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/HurtByTarget.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/HurtByTarget.java index 36c89ca62c..e4c24f1d11 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/HurtByTarget.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/HurtByTarget.java @@ -20,27 +20,27 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.target; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.ai.AIGoal; import de.Keyle.MyPet.api.entity.ai.target.TargetPriority; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTameableAnimal; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.decoration.ArmorStand; @Compat("v1_17_R1") public class HurtByTarget implements AIGoal { EntityMyPet petEntity; MyPet myPet; - EntityLiving target = null; + net.minecraft.world.entity.LivingEntity target = null; public HurtByTarget(EntityMyPet petEntity) { this.petEntity = petEntity; @@ -53,19 +53,19 @@ public boolean shouldStart() { if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) { return false; } - if (petEntity.getLastDamager() == null) { + if (petEntity.getLastHurtByMob() == null) { return false; } - if (target != petEntity.getLastDamager()) { - target = petEntity.getLastDamager(); + if (target != petEntity.getLastHurtByMob()) { + target = petEntity.getLastHurtByMob(); } if (target == petEntity) { return false; } - if (target instanceof EntityArmorStand) { + if (target instanceof ArmorStand) { return false; } - if (target instanceof EntityPlayer) { + if (target instanceof ServerPlayer) { Player targetPlayer = (Player) target.getBukkitEntity(); if (targetPlayer == myPet.getOwner().getPlayer()) { @@ -78,9 +78,9 @@ public boolean shouldStart() { if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) { return false; } - } else if (target instanceof EntityTameableAnimal) { - EntityTameableAnimal tameable = (EntityTameableAnimal) target; - if (tameable.isTamed() && tameable.getOwner() != null) { + } else if (target instanceof TamableAnimal) { + TamableAnimal tameable = (TamableAnimal) target; + if (tameable.isTame() && tameable.getOwner() != null) { Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity(); if (myPet.getOwner().equals(tameableOwner)) { return false; @@ -99,18 +99,18 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + net.minecraft.world.entity.LivingEntity target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); - if (target.t != petEntity.t) { + if (target.level != petEntity.level) { return true; - } else if (petEntity.f(target) > 400) { + } else if (petEntity.distanceToSqr(target) > 400) { return true; - } else return petEntity.f(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; + } else return petEntity.distanceToSqr(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; } @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/OwnerHurtByTarget.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/OwnerHurtByTarget.java index 022e5072ab..9e814f09af 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/OwnerHurtByTarget.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/ai/target/OwnerHurtByTarget.java @@ -20,6 +20,11 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.ai.target; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.ai.AIGoal; @@ -28,22 +33,17 @@ import de.Keyle.MyPet.api.skill.skills.Behavior.BehaviorMode; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTameableAnimal; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.decoration.ArmorStand; @Compat("v1_17_R1") public class OwnerHurtByTarget implements AIGoal { private final EntityMyPet petEntity; - private EntityLiving lastDamager; + private net.minecraft.world.entity.LivingEntity lastDamager; private final MyPet myPet; - private final EntityPlayer owner; + private final ServerPlayer owner; public OwnerHurtByTarget(EntityMyPet entityMyPet) { this.petEntity = entityMyPet; @@ -59,18 +59,18 @@ public boolean shouldStart() { if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) { return false; } - this.lastDamager = owner.getLastDamager(); + this.lastDamager = owner.getLastHurtByMob(); if (this.lastDamager == null || !lastDamager.isAlive()) { return false; } - if (lastDamager instanceof EntityArmorStand) { + if (lastDamager instanceof ArmorStand) { return false; } if (lastDamager == petEntity) { return false; } - if (lastDamager instanceof EntityPlayer) { + if (lastDamager instanceof ServerPlayer) { if (owner == lastDamager) { return false; } @@ -85,9 +85,9 @@ public boolean shouldStart() { if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) { return false; } - } else if (lastDamager instanceof EntityTameableAnimal) { - EntityTameableAnimal tameable = (EntityTameableAnimal) lastDamager; - if (tameable.isTamed() && tameable.getOwner() != null) { + } else if (lastDamager instanceof TamableAnimal) { + TamableAnimal tameable = (TamableAnimal) lastDamager; + if (tameable.isTame() && tameable.getOwner() != null) { Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity(); if (myPet.getOwner().equals(tameableOwner)) { return false; @@ -103,13 +103,13 @@ public boolean shouldStart() { return false; } if (behaviorSkill.getBehavior() == BehaviorMode.Raid) { - if (lastDamager instanceof EntityTameableAnimal && ((EntityTameableAnimal) lastDamager).isTamed()) { + if (lastDamager instanceof TamableAnimal && ((TamableAnimal) lastDamager).isTame()) { return false; } if (lastDamager instanceof EntityMyPet) { return false; } - return !(lastDamager instanceof EntityPlayer); + return !(lastDamager instanceof ServerPlayer); } } return true; @@ -124,18 +124,18 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + net.minecraft.world.entity.LivingEntity target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); - if (target.t != petEntity.t) { + if (target.level != petEntity.level) { return true; - } else if (petEntity.f(target) > 400) { + } else if (petEntity.distanceToSqr(target) > 400) { return true; - } else return petEntity.f(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; + } else return petEntity.distanceToSqr(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600; } @Override public void start() { - petEntity.setTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); + petEntity.setMyPetTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyAxolotl.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyAxolotl.java index aa895859ef..1d709e0505 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyAxolotl.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyAxolotl.java @@ -20,37 +20,27 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; -import de.Keyle.MyPet.MyPetApi; -import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyAxolotl; -import de.Keyle.MyPet.api.entity.types.MyMooshroom; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 1.3F) public class EntityMyAxolotl extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyAxolotl.class, DataWatcherRegistry.i); - private static final DataWatcherObject VARIANT_WATCHER = DataWatcher.a(EntityMyAxolotl.class, DataWatcherRegistry.b); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyAxolotl.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyAxolotl.class, EntityDataSerializers.INT); - public EntityMyAxolotl(World world, MyPet myPet) { + public EntityMyAxolotl(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.axolotl.death"; } @@ -65,16 +55,16 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(VARIANT_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(VARIANT_WATCHER, 0); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(VARIANT_WATCHER, getMyPet().getVariant()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBat.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBat.java index efb7892f46..994f537ab2 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBat.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBat.java @@ -24,17 +24,17 @@ import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.5F, height = 0.45f) public class EntityMyBat extends EntityMyPet { - private static final DataWatcherObject HANGING_WATCHER = DataWatcher.a(EntityMyBat.class, DataWatcherRegistry.a); + private static final EntityDataAccessor HANGING_WATCHER = SynchedEntityData.defineId(EntityMyBat.class, EntityDataSerializers.BYTE); - public EntityMyBat(World world, MyPet myPet) { + public EntityMyBat(Level world, MyPet myPet) { super(world, myPet); } @@ -43,7 +43,7 @@ public EntityMyBat(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.bat.death"; } @@ -67,17 +67,17 @@ public float getSoundSpeed() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(HANGING_WATCHER, (byte) 0xFFFFFFFE); // hanging + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(HANGING_WATCHER, (byte) 0xFFFFFFFE); // hanging } @Override public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Bat.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } } @@ -86,9 +86,9 @@ public void onLivingUpdate() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Bat.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBee.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBee.java index 3a4616225b..e2c712ba92 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBee.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBee.java @@ -20,6 +20,8 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.UUID; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; @@ -27,21 +29,21 @@ import de.Keyle.MyPet.api.skill.skills.Behavior; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.skill.skills.BehaviorImpl; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 0.6f) public class EntityMyBee extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyBee.class, DataWatcherRegistry.i); - private static final DataWatcherObject BEE_STATUS_WATCHER = DataWatcher.a(EntityMyBee.class, DataWatcherRegistry.a); - private static final DataWatcherObject ANGER_WATCHER = DataWatcher.a(EntityMyBee.class, DataWatcherRegistry.b); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyBee.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor BEE_STATUS_WATCHER = SynchedEntityData.defineId(EntityMyBee.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor ANGER_WATCHER = SynchedEntityData.defineId(EntityMyBee.class, EntityDataSerializers.INT); protected boolean isAngry = false; - public EntityMyBee(World world, MyPet myPet) { + public EntityMyBee(Level world, MyPet myPet) { super(world, myPet); } @@ -49,7 +51,7 @@ public EntityMyBee(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.bee.death"; } @@ -72,17 +74,17 @@ public float getSoundSpeed() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(BEE_STATUS_WATCHER, (byte) 0); - getDataWatcher().register(ANGER_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(BEE_STATUS_WATCHER, (byte) 0); + getEntityData().define(ANGER_WATCHER, 0); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(ANGER_WATCHER, (getMyPet().isAngry() || isAngry) ? 1 : 0); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(ANGER_WATCHER, (getMyPet().isAngry() || isAngry) ? 1 : 0); this.setBeeStatus(8, getMyPet().hasNectar()); this.setBeeStatus(4, getMyPet().hasStung()); } @@ -95,9 +97,9 @@ public void updateVisuals() { */ private void setBeeStatus(int status, boolean flag) { if (flag) { - this.Y.set(BEE_STATUS_WATCHER, (byte) (this.Y.get(BEE_STATUS_WATCHER) | status)); + this.entityData.set(BEE_STATUS_WATCHER, (byte) (this.entityData.get(BEE_STATUS_WATCHER) | status)); } else { - this.Y.set(BEE_STATUS_WATCHER, (byte) (this.Y.get(BEE_STATUS_WATCHER) & ~status)); + this.entityData.set(BEE_STATUS_WATCHER, (byte) (this.entityData.get(BEE_STATUS_WATCHER) & ~status)); } } @@ -111,8 +113,8 @@ public MyBee getMyPet() { public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Bee.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } } @@ -139,9 +141,9 @@ protected void doMyPetTick() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Bee.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBlaze.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBlaze.java index 394433ae3e..09668e415a 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBlaze.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBlaze.java @@ -20,35 +20,36 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.UUID; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyBlaze; import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; - -import java.lang.reflect.InvocationTargetException; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.7F) public class EntityMyBlaze extends EntityMyPet { - private static final DataWatcherObject BURNING_WATCHER = DataWatcher.a(EntityMyBlaze.class, DataWatcherRegistry.a); + private static final EntityDataAccessor BURNING_WATCHER = SynchedEntityData.defineId(EntityMyBlaze.class, EntityDataSerializers.BYTE); - public EntityMyBlaze(World world, MyPet myPet) { + public EntityMyBlaze(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.blaze.death"; } @@ -63,35 +64,35 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == EnumInteractionResult.b) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == InteractionResult.CONSUME) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (getMyPet().isOnFire() && itemStack.getItem() == Items.nX && getOwner().getPlayer().isSneaking()) { + if (getMyPet().isOnFire() && itemStack.getItem() == Items.WATER_BUCKET && getOwner().getPlayer().isSneaking()) { getMyPet().setOnFire(false); makeSound("block.fire.extinguish", 1.0F, 1.0F); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().flying) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, new ItemStack(Items.nW)); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, new ItemStack(Items.BUCKET)); } else { - if (!entityhuman.getInventory().pickup(new ItemStack(Items.nW))) { - entityhuman.drop(new ItemStack(Items.nW), true); + if (!entityhuman.getInventory().add(new ItemStack(Items.BUCKET))) { + entityhuman.drop(new ItemStack(Items.BUCKET), true); } } } - return EnumInteractionResult.b; - } else if (!getMyPet().isOnFire() && itemStack.getItem() == Items.me && getOwner().getPlayer().isSneaking()) { + return InteractionResult.CONSUME; + } else if (!getMyPet().isOnFire() && itemStack.getItem() == Items.FLINT_AND_STEEL && getOwner().getPlayer().isSneaking()) { getMyPet().setOnFire(true); makeSound("item.flintandsteel.use", 1.0F, 1.0F); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { @@ -100,29 +101,29 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En }); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(BURNING_WATCHER, (byte) 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(BURNING_WATCHER, (byte) 0); } @Override public void updateVisuals() { - getDataWatcher().set(BURNING_WATCHER, (byte) (getMyPet().isOnFire() ? 1 : 0)); + getEntityData().set(BURNING_WATCHER, (byte) (getMyPet().isOnFire() ? 1 : 0)); } @Override public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Blaze.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } } @@ -136,9 +137,9 @@ public MyBlaze getMyPet() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Blaze.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCat.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCat.java index 4f8aa6a5d2..cb232cf2cd 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCat.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCat.java @@ -20,51 +20,52 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.DyeColor; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyCat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemDye; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.DyeItem; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; -import org.bukkit.DyeColor; - -import java.util.Optional; -import java.util.UUID; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 0.8F) public class EntityMyCat extends EntityMyPet { - protected static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyCat.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SIT_WATCHER = DataWatcher.a(EntityMyCat.class, DataWatcherRegistry.a); - protected static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyCat.class, DataWatcherRegistry.o); - protected static final DataWatcherObject TYPE_WATCHER = DataWatcher.a(EntityMyCat.class, DataWatcherRegistry.b); - protected static final DataWatcherObject UNUSED_WATCHER_1 = DataWatcher.a(EntityMyCat.class, DataWatcherRegistry.i); - protected static final DataWatcherObject UNUSED_WATCHER_2 = DataWatcher.a(EntityMyCat.class, DataWatcherRegistry.i); - protected static final DataWatcherObject COLLAR_COLOR_WATCHER = DataWatcher.a(EntityMyCat.class, DataWatcherRegistry.b); + protected static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SIT_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.BYTE); + protected static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.OPTIONAL_UUID); + protected static final EntityDataAccessor TYPE_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.INT); + protected static final EntityDataAccessor UNUSED_WATCHER_1 = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor UNUSED_WATCHER_2 = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor COLLAR_COLOR_WATCHER = SynchedEntityData.defineId(EntityMyCat.class, EntityDataSerializers.INT); - public EntityMyCat(World world, MyPet myPet) { + public EntityMyCat(Level world, MyPet myPet) { super(world, myPet); } public void applySitting(boolean sitting) { - byte i = this.getDataWatcher().get(SIT_WATCHER); + byte i = this.getEntityData().get(SIT_WATCHER); if (sitting) { - this.getDataWatcher().set(SIT_WATCHER, (byte) (i | 1)); + this.getEntityData().set(SIT_WATCHER, (byte) (i | 1)); } else { - this.getDataWatcher().set(SIT_WATCHER, (byte) (i & -2)); + this.getEntityData().set(SIT_WATCHER, (byte) (i & -2)); } } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.cat.death"; } @@ -75,66 +76,65 @@ protected String getHurtSound() { @Override protected String getLivingSound() { - return this.Q.nextInt(4) == 0 ? "entity.cat.purr" : "entity.cat.ambient"; + return this.random.nextInt(4) == 0 ? "entity.cat.purr" : "entity.cat.ambient"; } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman)) { if (itemStack != null && canUseItem() && getOwner().getPlayer().isSneaking()) { - if (itemStack.getItem() instanceof ItemDye) { - if (((ItemDye) itemStack.getItem()).d().getColorIndex() != getMyPet().getCollarColor().ordinal()) { - getMyPet().setCollarColor(DyeColor.values()[((ItemDye) itemStack.getItem()).d().getColorIndex()]); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack.getItem() instanceof DyeItem) { + if (((DyeItem) itemStack.getItem()).getDyeColor().getId() != getMyPet().getCollarColor().ordinal()) { + getMyPet().setCollarColor(DyeColor.values()[((DyeItem) itemStack.getItem()).getDyeColor().getId()]); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.a; + return InteractionResult.SUCCESS; } } else if (Configuration.MyPet.Ocelot.GROW_UP_ITEM.compare(itemStack) && canUseItem() && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SIT_WATCHER, (byte) 0); - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); - getDataWatcher().register(TYPE_WATCHER, 1); - getDataWatcher().register(UNUSED_WATCHER_1, false); - getDataWatcher().register(UNUSED_WATCHER_2, false); - getDataWatcher().register(COLLAR_COLOR_WATCHER, 14); + protected void defineSynchedData() { + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SIT_WATCHER, (byte) 0); + getEntityData().define(OWNER_WATCHER, Optional.empty()); + getEntityData().define(TYPE_WATCHER, 1); + getEntityData().define(UNUSED_WATCHER_1, false); + getEntityData().define(UNUSED_WATCHER_2, false); + getEntityData().define(COLLAR_COLOR_WATCHER, 14); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(TYPE_WATCHER, getMyPet().getCatType().ordinal()); - this.getDataWatcher().set(COLLAR_COLOR_WATCHER, getMyPet().getCollarColor().ordinal()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(TYPE_WATCHER, getMyPet().getCatType().ordinal()); + this.getEntityData().set(COLLAR_COLOR_WATCHER, getMyPet().getCollarColor().ordinal()); - byte b0 = this.getDataWatcher().get(SIT_WATCHER); + byte b0 = this.getEntityData().get(SIT_WATCHER); if (getMyPet().isTamed()) { - this.getDataWatcher().set(SIT_WATCHER, (byte) (b0 | 0x4)); + this.getEntityData().set(SIT_WATCHER, (byte) (b0 | 0x4)); } else { - this.getDataWatcher().set(SIT_WATCHER, (byte) (b0 & 0xFFFFFFFB)); + this.getEntityData().set(SIT_WATCHER, (byte) (b0 & 0xFFFFFFFB)); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCaveSpider.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCaveSpider.java index e8c28e88ac..6ecae56211 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCaveSpider.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCaveSpider.java @@ -20,25 +20,27 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.UUID; + import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 0.45F) public class EntityMyCaveSpider extends EntityMyPet { - private static final DataWatcherObject UNUSED_WATCHER = DataWatcher.a(EntityMyCaveSpider.class, DataWatcherRegistry.a); + private static final EntityDataAccessor UNUSED_WATCHER = SynchedEntityData.defineId(EntityMyCaveSpider.class, EntityDataSerializers.BYTE); - public EntityMyCaveSpider(World world, MyPet myPet) { + public EntityMyCaveSpider(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.spider.death"; } @@ -53,9 +55,8 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(UNUSED_WATCHER, (byte) 0); + protected void defineSynchedData() { + getEntityData().define(UNUSED_WATCHER, (byte) 0); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyChicken.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyChicken.java index 8a8a8cb565..81b7ea8064 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyChicken.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyChicken.java @@ -20,35 +20,37 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.UUID; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyChicken; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.4F, height = 0.7F) public class EntityMyChicken extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyChicken.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyChicken.class, EntityDataSerializers.BOOLEAN); private int nextEggTimer; - public EntityMyChicken(World world, MyPet myPet) { + public EntityMyChicken(Level world, MyPet myPet) { super(world, myPet); - nextEggTimer = (this.Q.nextInt(6000) + 6000); + nextEggTimer = (this.random.nextInt(6000) + 6000); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.chicken.death"; } @@ -63,35 +65,35 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { if (Configuration.MyPet.Chicken.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); } @Override @@ -99,15 +101,15 @@ public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Chicken.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } if (Configuration.MyPet.Chicken.CAN_LAY_EGGS && canUseItem() && --nextEggTimer <= 0) { - this.makeSound("entity.chicken.egg", 1.0F, (this.Q.nextFloat() - this.Q.nextFloat()) * 0.2F + 1.0F); - a(Items.oo, 1); - nextEggTimer = this.Q.nextInt(6000) + 6000; + this.makeSound("entity.chicken.egg", 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); + spawnAtLocation(Items.EGG, 1); + nextEggTimer = this.random.nextInt(6000) + 6000; } } @@ -125,9 +127,9 @@ public MyChicken getMyPet() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Chicken.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCod.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCod.java index 083497ac8e..fa8cc14df6 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCod.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCod.java @@ -20,27 +20,29 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.UUID; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.compat.ParticleCompat; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.5F, height = 0.3f) public class EntityMyCod extends EntityMyPet { - private static final DataWatcherObject FROM_BUCKET_WATCHER = DataWatcher.a(EntityMyCod.class, DataWatcherRegistry.i); + private static final EntityDataAccessor FROM_BUCKET_WATCHER = SynchedEntityData.defineId(EntityMyCod.class, EntityDataSerializers.BOOLEAN); - public EntityMyCod(World world, MyPet myPet) { + public EntityMyCod(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.cod.death"; } @@ -57,14 +59,14 @@ protected String getLivingSound() { @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (!isInWater() && this.Q.nextBoolean()) { + if (!isInWater() && this.random.nextBoolean()) { MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, 0.7, 0), ParticleCompat.WATER_SPLASH.get(), 0.2F, 0.2F, 0.2F, 0.5F, 10, 20); } } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(FROM_BUCKET_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(FROM_BUCKET_WATCHER, false); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCow.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCow.java index 4b68459b04..fe7fc395ac 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCow.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCow.java @@ -20,32 +20,34 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.UUID; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyCow; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 1.3F) public class EntityMyCow extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyCow.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyCow.class, EntityDataSerializers.BOOLEAN); - public EntityMyCow(World world, MyPet myPet) { + public EntityMyCow(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.cow.death"; } @@ -60,40 +62,40 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.nW && Configuration.MyPet.Cow.CAN_GIVE_MILK) { - ItemStack milkBucket = new ItemStack(Items.oc); + if (itemStack.getItem() == Items.BUCKET && Configuration.MyPet.Cow.CAN_GIVE_MILK) { + ItemStack milkBucket = new ItemStack(Items.MILK_BUCKET); - entityhuman.getInventory().setItem(entityhuman.getInventory().k, milkBucket); - return EnumInteractionResult.b; + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, milkBucket); + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Cow.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCreeper.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCreeper.java index 40cc9bfd19..ec5a0b7d52 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCreeper.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyCreeper.java @@ -20,28 +20,30 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.UUID; + import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyCreeper; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyCreeper extends EntityMyPet { - private static final DataWatcherObject FUSE_WATCHER = DataWatcher.a(EntityMyCreeper.class, DataWatcherRegistry.b); - private static final DataWatcherObject POWERED_WATCHER = DataWatcher.a(EntityMyCreeper.class, DataWatcherRegistry.i); - private static final DataWatcherObject UNUSED_WATCHER = DataWatcher.a(EntityMyCreeper.class, DataWatcherRegistry.i); + private static final EntityDataAccessor FUSE_WATCHER = SynchedEntityData.defineId(EntityMyCreeper.class, EntityDataSerializers.INT); + private static final EntityDataAccessor POWERED_WATCHER = SynchedEntityData.defineId(EntityMyCreeper.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor UNUSED_WATCHER = SynchedEntityData.defineId(EntityMyCreeper.class, EntityDataSerializers.BOOLEAN); - public EntityMyCreeper(World world, MyPet myPet) { + public EntityMyCreeper(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.creeper.death"; } @@ -56,16 +58,16 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(FUSE_WATCHER, -1); - getDataWatcher().register(POWERED_WATCHER, false); - getDataWatcher().register(UNUSED_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(FUSE_WATCHER, -1); + getEntityData().define(POWERED_WATCHER, false); + getEntityData().define(UNUSED_WATCHER, false); } @Override public void updateVisuals() { - getDataWatcher().set(POWERED_WATCHER, getMyPet().isPowered()); + getEntityData().set(POWERED_WATCHER, getMyPet().isPowered()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDolphin.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDolphin.java index 2385a04917..0c7060ed05 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDolphin.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDolphin.java @@ -20,30 +20,32 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.UUID; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.compat.ParticleCompat; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.BlockPosition; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.core.BlockPos; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.9F, height = 0.6f) public class EntityMyDolphin extends EntityMyPet { - private static final DataWatcherObject TREASURE_POS_WATCHER = DataWatcher.a(EntityMyDolphin.class, DataWatcherRegistry.l); - private static final DataWatcherObject GOT_FISH_WATCHER = DataWatcher.a(EntityMyDolphin.class, DataWatcherRegistry.i); - private static final DataWatcherObject MOISTNESS_WATCHER = DataWatcher.a(EntityMyDolphin.class, DataWatcherRegistry.b); + private static final EntityDataAccessor TREASURE_POS_WATCHER = SynchedEntityData.defineId(EntityMyDolphin.class, EntityDataSerializers.BLOCK_POS); + private static final EntityDataAccessor GOT_FISH_WATCHER = SynchedEntityData.defineId(EntityMyDolphin.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor MOISTNESS_WATCHER = SynchedEntityData.defineId(EntityMyDolphin.class, EntityDataSerializers.INT); - public EntityMyDolphin(World world, MyPet myPet) { + public EntityMyDolphin(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.dolphin.death"; } @@ -60,17 +62,17 @@ protected String getLivingSound() { @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (!isInWater() && this.Q.nextBoolean()) { + if (!isInWater() && this.random.nextBoolean()) { MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, 0.7, 0), ParticleCompat.WATER_SPLASH.get(), 0.2F, 0.2F, 0.2F, 0.5F, 10, 20); } } @Override - protected void initDatawatcher() { - super.initDatawatcher(); + protected void defineSynchedData() { + super.defineSynchedData(); - getDataWatcher().register(TREASURE_POS_WATCHER, BlockPosition.b); - getDataWatcher().register(GOT_FISH_WATCHER, false); - getDataWatcher().register(MOISTNESS_WATCHER, 2400); + getEntityData().define(TREASURE_POS_WATCHER, BlockPos.ZERO); + getEntityData().define(GOT_FISH_WATCHER, false); + getEntityData().define(MOISTNESS_WATCHER, 2400); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDonkey.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDonkey.java index 2da5f8529d..d5a32380cf 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDonkey.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDonkey.java @@ -20,49 +20,49 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyDonkey; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.BlockPosition; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.sounds.SoundEffects; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.core.BlockPos; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.IJumpable; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.PlayerRideableJumping; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SoundEffectType; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Optional; -import java.util.UUID; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; @EntitySize(width = 1.4F, height = 1.6F) -public class EntityMyDonkey extends EntityMyPet implements IJumpable { +public class EntityMyDonkey extends EntityMyPet implements PlayerRideableJumping { - protected static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyDonkey.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SADDLE_WATCHER = DataWatcher.a(EntityMyDonkey.class, DataWatcherRegistry.a); - protected static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyDonkey.class, DataWatcherRegistry.o); - private static final DataWatcherObject CHEST_WATCHER = DataWatcher.a(EntityMyDonkey.class, DataWatcherRegistry.i); + protected static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyDonkey.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SADDLE_WATCHER = SynchedEntityData.defineId(EntityMyDonkey.class, EntityDataSerializers.BYTE); + protected static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyDonkey.class, EntityDataSerializers.OPTIONAL_UUID); + private static final EntityDataAccessor CHEST_WATCHER = SynchedEntityData.defineId(EntityMyDonkey.class, EntityDataSerializers.BOOLEAN); int soundCounter = 0; int rearCounter = -1; - public EntityMyDonkey(World world, MyPet myPet) { + public EntityMyDonkey(Level world, MyPet myPet) { super(world, myPet); } @@ -75,11 +75,11 @@ public EntityMyDonkey(World world, MyPet myPet) { * 128 mouth open */ protected void applyVisual(int value, boolean flag) { - int i = this.getDataWatcher().get(SADDLE_WATCHER); + int i = this.getEntityData().get(SADDLE_WATCHER); if (flag) { - this.getDataWatcher().set(SADDLE_WATCHER, (byte) (i | value)); + this.getEntityData().set(SADDLE_WATCHER, (byte) (i | value)); } else { - this.getDataWatcher().set(SADDLE_WATCHER, (byte) (i & (~value))); + this.getEntityData().set(SADDLE_WATCHER, (byte) (i & (~value))); } } @@ -100,55 +100,55 @@ public boolean attack(Entity entity) { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.lL && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Item.getItemOf(Blocks.pq) && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Item.byBlock(Blocks.CHEST) && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && canEquip()) { getMyPet().setChest(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { if (getMyPet().hasChest()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } if (getMyPet().hasSaddle()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setChest(null); getMyPet().setSaddle(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -156,39 +156,39 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Donkey.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SADDLE_WATCHER, (byte) 0); - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); - getDataWatcher().register(CHEST_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SADDLE_WATCHER, (byte) 0); + getEntityData().define(OWNER_WATCHER, Optional.empty()); + getEntityData().define(CHEST_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(CHEST_WATCHER, getMyPet().hasChest()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest()); applyVisual(4, getMyPet().hasSaddle()); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.donkey.death"; } @@ -223,25 +223,25 @@ public void onLivingUpdate() { @Override - public void playStepSound(BlockPosition blockposition, IBlockData blockdata) { + public void playStepSound(BlockPos blockposition, BlockState blockdata) { if (!blockdata.getMaterial().isLiquid()) { - IBlockData blockdataUp = this.t.getType(blockposition.up()); - SoundEffectType soundeffecttype = blockdata.getStepSound(); - if (blockdataUp.getBlock() == Blocks.cK) { - soundeffecttype = blockdata.getStepSound(); + BlockState blockdataUp = this.level.getBlockState(blockposition.up()); + SoundType soundeffecttype = blockdata.getSoundType(); + if (blockdataUp.getBlock() == Blocks.SNOW) { + soundeffecttype = blockdata.getSoundType(); } if (this.isVehicle()) { ++this.soundCounter; if (this.soundCounter > 5 && this.soundCounter % 3 == 0) { - this.playSound(SoundEffects.iB, soundeffecttype.getVolume() * 0.16F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_GALLOP, soundeffecttype.getVolume() * 0.16F, soundeffecttype.getPitch()); } else if (this.soundCounter <= 5) { - this.playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.16F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.16F, soundeffecttype.getPitch()); } } else if (!blockdata.getMaterial().isLiquid()) { this.soundCounter += 1; - playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.16F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.16F, soundeffecttype.getPitch()); } else { - playSound(SoundEffects.iG, soundeffecttype.getVolume() * 0.16F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP, soundeffecttype.getVolume() * 0.16F, soundeffecttype.getPitch()); } } } @@ -252,22 +252,22 @@ public MyDonkey getMyPet() { } @Override - public void a(int i) { - // I don't know. + public void onPlayerJump(int i) { + // I don't know. <- this was here before the remap } /* Jump power methods */ @Override - public boolean a() { + public boolean canJump() { return true; } @Override - public void b(int i) { + public void handleStartJump(int i) { this.jumpPower = i; } @Override - public void b() { + public void handleStopJump() { } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDrowned.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDrowned.java index cbc39f4bc6..910cc032fc 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDrowned.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyDrowned.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -28,39 +35,32 @@ import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyDrowned; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.95F) public class EntityMyDrowned extends EntityMyPet { - private static final DataWatcherObject BABY_WATCHER = DataWatcher.a(EntityMyDrowned.class, DataWatcherRegistry.i); - private static final DataWatcherObject UNUSED_WATCHER_1 = DataWatcher.a(EntityMyDrowned.class, DataWatcherRegistry.b); - private static final DataWatcherObject UNUSED_WATCHER_2 = DataWatcher.a(EntityMyDrowned.class, DataWatcherRegistry.i); - private static final DataWatcherObject UNUSED_WATCHER_3 = DataWatcher.a(EntityMyDrowned.class, DataWatcherRegistry.i); + private static final EntityDataAccessor BABY_WATCHER = SynchedEntityData.defineId(EntityMyDrowned.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor UNUSED_WATCHER_1 = SynchedEntityData.defineId(EntityMyDrowned.class, EntityDataSerializers.INT); + private static final EntityDataAccessor UNUSED_WATCHER_2 = SynchedEntityData.defineId(EntityMyDrowned.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor UNUSED_WATCHER_3 = SynchedEntityData.defineId(EntityMyDrowned.class, EntityDataSerializers.BOOLEAN); - public EntityMyDrowned(World world, MyPet myPet) { + public EntityMyDrowned(Level world, MyPet myPet) { super(world, myPet); } @@ -68,7 +68,7 @@ public EntityMyDrowned(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.drowned.death" + (isInWater() ? "_water" : ""); } @@ -95,34 +95,34 @@ protected String getLivingSound() { * false: no reaction on rightclick */ @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -130,50 +130,50 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Zombie.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(BABY_WATCHER, false); - getDataWatcher().register(UNUSED_WATCHER_1, 0); - getDataWatcher().register(UNUSED_WATCHER_2, false); - getDataWatcher().register(UNUSED_WATCHER_3, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(BABY_WATCHER, false); + getEntityData().define(UNUSED_WATCHER_1, 0); + getEntityData().define(UNUSED_WATCHER_2, false); + getEntityData().define(UNUSED_WATCHER_3, false); } @Override public void updateVisuals() { - getDataWatcher().set(BABY_WATCHER, getMyPet().isBaby()); + getEntityData().set(BABY_WATCHER, getMyPet().isBaby()); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { @@ -195,17 +195,17 @@ public MyDrowned getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyElderGuardian.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyElderGuardian.java index 7834eecb18..681199230e 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyElderGuardian.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyElderGuardian.java @@ -24,17 +24,17 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyElderGuardian; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 0.85F) public class EntityMyElderGuardian extends EntityMyPet { - public EntityMyElderGuardian(World world, MyPet myPet) { + public EntityMyElderGuardian(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.elder_guardian.death"; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEnderDragon.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEnderDragon.java index c97b8e2792..69eaf79ac1 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEnderDragon.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEnderDragon.java @@ -20,18 +20,18 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.Arrays; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPetPart; import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack.MeleeAttack; -import net.minecraft.server.level.WorldServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.World; - -import java.util.Arrays; +import net.minecraft.world.level.Level; @EntitySize(width = 1.F, height = 1.F) public class EntityMyEnderDragon extends EntityMyPet { @@ -42,7 +42,7 @@ public class EntityMyEnderDragon extends EntityMyPet { public EntityMyPetPart[] children; - public EntityMyEnderDragon(World world, MyPet myPet) { + public EntityMyEnderDragon(Level world, MyPet myPet) { super(world, myPet); children = new EntityMyPetPart[]{ @@ -58,7 +58,7 @@ public EntityMyEnderDragon(World world, MyPet myPet) { } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.ender_dragon.death"; } @@ -82,15 +82,15 @@ public void setPathfinder() { public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.EnderDragon.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } if (!registered && this.valid) { - if (this.getWorld() instanceof WorldServer) { - WorldServer world = (WorldServer) this.getWorld(); + if (this.getCommandSenderWorld() instanceof ServerLevel) { + ServerLevel world = (ServerLevel) this.getCommandSenderWorld(); Arrays.stream(this.children) - .forEach(entityMyPetPart -> world.addEntity(entityMyPetPart)); // TODO: 2021/07/14 I don't know if this is the right replacement. + .forEach(entityMyPetPart -> world.addFreshEntity(entityMyPetPart)); // TODO: 2021/07/14 I don't know if this is the right replacement. } this.registered = true; } @@ -100,30 +100,30 @@ public void onLivingUpdate() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.EnderDragon.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } /* fmm... @Override - public void die() { - super.die(); - Arrays.stream(this.children).forEach((en) -> (en.getBukkitEntity().getHandle()).die()); + public void discard() { + super.discard(); + Arrays.stream(this.children).forEach((en) -> (en.getBukkitEntity().getHandle()).discard()); } */ @Override public void die(DamageSource damagesource) { super.die(damagesource); - Arrays.stream(this.children).forEach(Entity::die); + Arrays.stream(this.children).forEach(Entity::discard); } @Override - public void movementTick() { - super.movementTick(); + public void aiStep() { + super.aiStep(); // if (++this.d == this.c.length) { // this.d = 0; @@ -136,18 +136,18 @@ public void movementTick() { // float f11 = MathHelper.sin(f10); // float f12 = MathHelper.cos(f10); // this.children[2].tick(); - // this.children[2].setPositionRotation(this.locX() + (double) (f11 * 0.5F), this.locY(), this.locZ() - (double) (f12 * 0.5F), 0.0F, 0.0F); + // this.children[2].setPositionRotation(this.getX() + (double) (f11 * 0.5F), this.getY(), this.getZ() - (double) (f12 * 0.5F), 0.0F, 0.0F); // this.children[6].tick(); - // this.children[6].setPositionRotation(this.locX() + (double) (f12 * 4.5F), this.locY() + 2.0D, this.locZ() + (double) (f11 * 4.5F), 0.0F, 0.0F); + // this.children[6].setPositionRotation(this.getX() + (double) (f12 * 4.5F), this.getY() + 2.0D, this.getZ() + (double) (f11 * 4.5F), 0.0F, 0.0F); // this.children[7].tick(); - // this.children[7].setPositionRotation(this.locX() - (double) (f12 * 4.5F), this.locY() + 2.0D, this.locZ() - (double) (f11 * 4.5F), 0.0F, 0.0F); + // this.children[7].setPositionRotation(this.getX() - (double) (f12 * 4.5F), this.getY() + 2.0D, this.getZ() - (double) (f11 * 4.5F), 0.0F, 0.0F); // // float f13 = MathHelper.sin(this.yaw * 0.017453292F - this.be * 0.01F); // float f14 = MathHelper.cos(this.yaw * 0.017453292F - this.be * 0.01F); // this.children[0].tick(); // this.children[1].tick(); // double f3 = this.v(1.0F); - // this.children[0].setPositionRotation(this.locX() + (double) (f13 * 6.5F * f8), this.locY() + (double) f3 + (double) (f9 * 6.5F), this.locZ() - (double) (f14 * 6.5F * f8), 0.0F, 0.0F); - // this.children[1].setPositionRotation(this.locX() + (double) (f13 * 5.5F * f8), this.locY() + (double) f3 + (double) (f9 * 5.5F), this.locZ() - (double) (f14 * 5.5F * f8), 0.0F, 0.0F); + // this.children[0].setPositionRotation(this.getX() + (double) (f13 * 6.5F * f8), this.getY() + (double) f3 + (double) (f9 * 6.5F), this.getZ() - (double) (f14 * 6.5F * f8), 0.0F, 0.0F); + // this.children[1].setPositionRotation(this.getX() + (double) (f13 * 5.5F * f8), this.getY() + (double) f3 + (double) (f9 * 5.5F), this.getZ() - (double) (f14 * 5.5F * f8), 0.0F, 0.0F); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEnderman.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEnderman.java index 2bc208dd16..823e23345d 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEnderman.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEnderman.java @@ -20,45 +20,45 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers; + import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyEnderman; import de.Keyle.MyPet.api.skill.skills.Behavior; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.skill.skills.BehaviorImpl; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers; - -import java.lang.reflect.InvocationTargetException; -import java.util.Optional; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; @EntitySize(width = 0.6F, height = 2.55F) public class EntityMyEnderman extends EntityMyPet { - private static final DataWatcherObject> BLOCK_WATCHER = DataWatcher.a(EntityMyEnderman.class, DataWatcherRegistry.h); - private static final DataWatcherObject SCREAMING_WATCHER = DataWatcher.a(EntityMyEnderman.class, DataWatcherRegistry.i); + private static final EntityDataAccessor> BLOCK_WATCHER = SynchedEntityData.defineId(EntityMyEnderman.class, EntityDataSerializers.BLOCK_STATE); + private static final EntityDataAccessor SCREAMING_WATCHER = SynchedEntityData.defineId(EntityMyEnderman.class, EntityDataSerializers.BOOLEAN); - public EntityMyEnderman(World world, MyPet myPet) { + public EntityMyEnderman(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.enderman.death"; } @@ -73,27 +73,27 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.pq && getMyPet().hasBlock() && getOwner().getPlayer().isSneaking()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getBlock())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); + if (itemStack.getItem() == Items.SHEARS && getMyPet().hasBlock() && getOwner().getPlayer().isSneaking()) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getBlock())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setBlock(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -101,39 +101,39 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (getMyPet().getBlock() == null && Util.isBetween(1, 255, Item.getId(itemStack.getItem())) && getOwner().getPlayer().isSneaking()) { getMyPet().setBlock(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(BLOCK_WATCHER, Optional.empty()); - getDataWatcher().register(SCREAMING_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(BLOCK_WATCHER, Optional.empty()); + getEntityData().define(SCREAMING_WATCHER, false); } @Override public void updateVisuals() { - Optional block; + Optional block; if (getMyPet().getBlock() != null) { - IBlockData data = CraftMagicNumbers.getBlock(getMyPet().getBlock().getData()); + BlockState data = CraftMagicNumbers.getBlock(getMyPet().getBlock().getData()); block = Optional.ofNullable(data); } else { block = Optional.empty(); } - getDataWatcher().set(BLOCK_WATCHER, block); - getDataWatcher().set(SCREAMING_WATCHER, getMyPet().isScreaming()); + getEntityData().set(BLOCK_WATCHER, block); + getEntityData().set(SCREAMING_WATCHER, getMyPet().isScreaming()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEndermite.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEndermite.java index a81b2258d3..59981df8bd 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEndermite.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEndermite.java @@ -23,17 +23,17 @@ import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.4F, height = 0.1F) public class EntityMyEndermite extends EntityMyPet { - public EntityMyEndermite(World world, MyPet myPet) { + public EntityMyEndermite(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.endermite.death"; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEvoker.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEvoker.java index 3555e41902..1278753a5c 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEvoker.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyEvoker.java @@ -24,18 +24,18 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyEvoker; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.95F) public class EntityMyEvoker extends EntityMyPet { - protected static final DataWatcherObject RAID_WATCHER = DataWatcher.a(EntityMyEvoker.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SPELL_WATCHER = DataWatcher.a(EntityMyEvoker.class, DataWatcherRegistry.a); + protected static final EntityDataAccessor RAID_WATCHER = SynchedEntityData.defineId(EntityMyEvoker.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SPELL_WATCHER = SynchedEntityData.defineId(EntityMyEvoker.class, EntityDataSerializers.BYTE); - public EntityMyEvoker(World world, MyPet myPet) { + public EntityMyEvoker(Level world, MyPet myPet) { super(world, myPet); } @@ -43,7 +43,7 @@ public EntityMyEvoker(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.evoker.death"; } @@ -64,10 +64,10 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(RAID_WATCHER, false); - getDataWatcher().register(SPELL_WATCHER, (byte) 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(RAID_WATCHER, false); + getEntityData().define(SPELL_WATCHER, (byte) 0); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyFox.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyFox.java index 751b7f2c0d..3a50cf3158 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyFox.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyFox.java @@ -20,7 +20,16 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -28,46 +37,37 @@ import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyFox; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.Optional; -import java.util.UUID; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 0.8F) public class EntityMyFox extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyFox.class, DataWatcherRegistry.i); - private static final DataWatcherObject FOX_TYPE_WATCHER = DataWatcher.a(EntityMyFox.class, DataWatcherRegistry.b); - private static final DataWatcherObject ACTIONS_WATCHER = DataWatcher.a(EntityMyFox.class, DataWatcherRegistry.a); - private static final DataWatcherObject> FRIEND_A_WATCHER = DataWatcher.a(EntityMyFox.class, DataWatcherRegistry.o); - private static final DataWatcherObject> FRIEND_B_WATCHER = DataWatcher.a(EntityMyFox.class, DataWatcherRegistry.o); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor FOX_TYPE_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.INT); + private static final EntityDataAccessor ACTIONS_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor> FRIEND_A_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.OPTIONAL_UUID); + private static final EntityDataAccessor> FRIEND_B_WATCHER = SynchedEntityData.defineId(EntityMyFox.class, EntityDataSerializers.OPTIONAL_UUID); - public EntityMyFox(World world, MyPet myPet) { + public EntityMyFox(Level world, MyPet myPet) { super(world, myPet); - this.getControllerLook().a(this, 60.0F, 30.0F); + this.getLookControl().setLookAt(this, 60.0F, 30.0F); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.fox.death"; } @@ -82,60 +82,60 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman)) { - if (itemStack != null && itemStack.getItem() != Items.a && canUseItem() && getOwner().getPlayer().isSneaking()) { - if (itemStack.getItem() != Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack != null && itemStack.getItem() != Items.AIR && canUseItem() && getOwner().getPlayer().isSneaking()) { + if (itemStack.getItem() != Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.MainHand)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(EquipmentSlot.MainHand, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Ocelot.GROW_UP_ITEM.compare(itemStack) && canUseItem() && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -143,27 +143,27 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(FRIEND_A_WATCHER, Optional.empty()); - getDataWatcher().register(FRIEND_B_WATCHER, Optional.empty()); - getDataWatcher().register(FOX_TYPE_WATCHER, 0); - getDataWatcher().register(ACTIONS_WATCHER, (byte) 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(FRIEND_A_WATCHER, Optional.empty()); + getEntityData().define(FRIEND_B_WATCHER, Optional.empty()); + getEntityData().define(FOX_TYPE_WATCHER, 0); + getEntityData().define(ACTIONS_WATCHER, (byte) 0); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(FOX_TYPE_WATCHER, getMyPet().getType().ordinal()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(FOX_TYPE_WATCHER, getMyPet().getType().ordinal()); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { @@ -184,32 +184,32 @@ public void updateVisuals() { */ public void updateActionsWatcher(int i, boolean flag) { if (flag) { - this.Y.set(ACTIONS_WATCHER, (byte) (this.Y.get(ACTIONS_WATCHER) | i)); + this.entityData.set(ACTIONS_WATCHER, (byte) (this.entityData.get(ACTIONS_WATCHER) | i)); } else { - this.Y.set(ACTIONS_WATCHER, (byte) (this.Y.get(ACTIONS_WATCHER) & ~i)); + this.entityData.set(ACTIONS_WATCHER, (byte) (this.entityData.get(ACTIONS_WATCHER) & ~i)); } } @Override - public void movementTick() { - super.movementTick(); + public void aiStep() { + super.aiStep(); // foxes can't look up this.setXRot(0F); } public void setPetEquipment(ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.a, itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.MAINHAND, itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGhast.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGhast.java index f8210bcdec..02f4837507 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGhast.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGhast.java @@ -25,17 +25,17 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack.MeleeAttack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 4.F, height = 4.F) public class EntityMyGhast extends EntityMyPet { - public EntityMyGhast(World world, MyPet myPet) { + public EntityMyGhast(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.ghast.death"; } @@ -59,8 +59,8 @@ public void setPathfinder() { public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Ghast.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } } @@ -69,9 +69,9 @@ public void onLivingUpdate() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Ghast.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGiant.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGiant.java index 085cdb6541..efd1f86e7a 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGiant.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGiant.java @@ -20,43 +20,43 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyGiant; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack.MeleeAttack; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 6.0f, height = 10.440001F) public class EntityMyGiant extends EntityMyPet { - public EntityMyGiant(World world, MyPet myPet) { + public EntityMyGiant(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.zombie.death"; } @@ -84,34 +84,34 @@ public void setPathfinder() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -119,27 +119,27 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override @@ -154,18 +154,18 @@ public void updateVisuals() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGoat.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGoat.java index d29dd986d8..d4391df9e4 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGoat.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGoat.java @@ -23,30 +23,29 @@ import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; -import de.Keyle.MyPet.api.entity.types.MyCow; import de.Keyle.MyPet.api.entity.types.MyGoat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 1.3F) public class EntityMyGoat extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyGoat.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyGoat.class, EntityDataSerializers.BOOLEAN); - public EntityMyGoat(World world, MyPet myPet) { + public EntityMyGoat(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.goat.death"; } @@ -61,39 +60,39 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.nW && Configuration.MyPet.Goat.CAN_GIVE_MILK) { - ItemStack milkBucket = new ItemStack(Items.oc); + if (itemStack.getItem() == Items.BUCKET && Configuration.MyPet.Goat.CAN_GIVE_MILK) { + ItemStack milkBucket = new ItemStack(Items.MILK_BUCKET); - entityhuman.getInventory().setItem(entityhuman.getInventory().k, milkBucket); - return EnumInteractionResult.b; + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, milkBucket); + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Goat.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGuardian.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGuardian.java index 4cc4f82c03..cd848c7ab3 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGuardian.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyGuardian.java @@ -24,17 +24,17 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyGuardian; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 0.85F) public class EntityMyGuardian extends EntityMyPet { - public EntityMyGuardian(World world, MyPet myPet) { + public EntityMyGuardian(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.guardian.death"; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHoglin.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHoglin.java index 4a761b4fa8..682ff1c85a 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHoglin.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHoglin.java @@ -25,26 +25,26 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyHoglin; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 1.3965F, height = 1.4F) public class EntityMyHoglin extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyHoglin.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyHoglin.class, EntityDataSerializers.BOOLEAN); - public EntityMyHoglin(World world, MyPet myPet) { + public EntityMyHoglin(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.hoglin.death"; } @@ -59,35 +59,35 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(final Player entityhuman, InteractionHand enumhand, final ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (Configuration.MyPet.Hoglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHorse.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHorse.java index 1ff888167b..f76e590024 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHorse.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHorse.java @@ -20,7 +20,16 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -28,49 +37,40 @@ import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyHorse; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.BlockPosition; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.sounds.SoundEffects; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.core.BlockPos; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.IJumpable; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.PlayerRideableJumping; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SoundEffectType; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.Optional; -import java.util.UUID; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; @EntitySize(width = 1.3965F, height = 1.6F) -public class EntityMyHorse extends EntityMyPet implements IJumpable { +public class EntityMyHorse extends EntityMyPet implements PlayerRideableJumping { - protected static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyHorse.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SADDLE_CHEST_WATCHER = DataWatcher.a(EntityMyHorse.class, DataWatcherRegistry.a); - protected static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyHorse.class, DataWatcherRegistry.o); - private static final DataWatcherObject VARIANT_WATCHER = DataWatcher.a(EntityMyHorse.class, DataWatcherRegistry.b); + protected static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyHorse.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SADDLE_CHEST_WATCHER = SynchedEntityData.defineId(EntityMyHorse.class, EntityDataSerializers.BYTE); + protected static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyHorse.class, EntityDataSerializers.OPTIONAL_UUID); + private static final EntityDataAccessor VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyHorse.class, EntityDataSerializers.INT); int soundCounter = 0; int rearCounter = -1; - public EntityMyHorse(World world, MyPet myPet) { + public EntityMyHorse(Level world, MyPet myPet) { super(world, myPet); } @@ -82,11 +82,11 @@ public EntityMyHorse(World world, MyPet myPet) { * 64 rear */ protected void applyVisual(int value, boolean flag) { - int i = this.getDataWatcher().get(SADDLE_CHEST_WATCHER); + int i = this.getEntityData().get(SADDLE_CHEST_WATCHER); if (flag) { - this.getDataWatcher().set(SADDLE_CHEST_WATCHER, (byte) (i | value)); + this.getEntityData().set(SADDLE_CHEST_WATCHER, (byte) (i | value)); } else { - this.getDataWatcher().set(SADDLE_CHEST_WATCHER, (byte) (i & (~value))); + this.getEntityData().set(SADDLE_CHEST_WATCHER, (byte) (i & (~value))); } } @@ -107,7 +107,7 @@ public boolean attack(Entity entity) { } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.horse.death"; } @@ -122,63 +122,63 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (itemStack != null && canUseItem()) { org.bukkit.inventory.ItemStack is = CraftItemStack.asBukkitCopy(itemStack); - if (itemStack.getItem() == Items.lL && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { getMyPet().setSaddle(is); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (!getMyPet().hasArmor() && getOwner().getPlayer().isSneaking() && canEquip() && isArmor(is)) { getMyPet().setArmor(is); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { if (getMyPet().hasArmor()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getArmor())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getArmor())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } if (getMyPet().hasChest()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } if (getMyPet().hasSaddle()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setChest(null); getMyPet().setSaddle(null); getMyPet().setArmor(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -186,19 +186,19 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Horse.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } protected boolean isArmor(org.bukkit.inventory.ItemStack item) { @@ -215,18 +215,18 @@ protected boolean isArmor(org.bukkit.inventory.ItemStack item) { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SADDLE_CHEST_WATCHER, (byte) 0); - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); - getDataWatcher().register(VARIANT_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SADDLE_CHEST_WATCHER, (byte) 0); + getEntityData().define(OWNER_WATCHER, Optional.empty()); + getEntityData().define(VARIANT_WATCHER, 0); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(VARIANT_WATCHER, getMyPet().getVariant()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant()); applyVisual(4, getMyPet().hasSaddle()); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { @@ -255,42 +255,42 @@ public void onLivingUpdate() { } @Override - public void playStepSound(BlockPosition blockposition, IBlockData blockdata) { + public void playStepSound(BlockPos blockposition, BlockState blockdata) { if (!blockdata.getMaterial().isLiquid()) { - IBlockData blockdataUp = this.t.getType(blockposition.up()); - SoundEffectType soundeffecttype = blockdata.getStepSound(); - if (blockdataUp.getBlock() == Blocks.cK) { - soundeffecttype = blockdata.getStepSound(); + BlockState blockdataUp = this.level.getBlockState(blockposition.up()); + SoundType soundeffecttype = blockdata.getSoundType(); + if (blockdataUp.getBlock() == Blocks.SNOW) { + soundeffecttype = blockdata.getSoundType(); } if (this.isVehicle()) { ++this.soundCounter; if (this.soundCounter > 5 && this.soundCounter % 3 == 0) { - this.playSound(SoundEffects.iB, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_GALLOP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } else if (this.soundCounter <= 5) { - this.playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } } else if (!blockdata.getMaterial().isLiquid()) { this.soundCounter += 1; - playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } else { - playSound(SoundEffects.iG, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } } } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (slot == EquipmentSlot.Chestplate && getMyPet().getArmor() != null) { return CraftItemStack.asNMSCopy(getMyPet().getArmor()); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } @Override @@ -300,22 +300,22 @@ public MyHorse getMyPet() { @Override - public void a(int i) { - // I don't know. + public void onPlayerJump(int i) { + // I don't know. <- this was here before the remap } /* Jump power methods */ @Override - public boolean a() { + public boolean canJump() { return true; } @Override - public void b(int i) { + public void handleStartJump(int i) { this.jumpPower = i; } @Override - public void b() { + public void handleStopJump() { } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHusk.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHusk.java index 393614aa2c..6dfced09fa 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHusk.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyHusk.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -28,37 +35,30 @@ import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyHusk; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyHusk extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyHusk.class, DataWatcherRegistry.i); - private static final DataWatcherObject TYPE_WATCHER = DataWatcher.a(EntityMyHusk.class, DataWatcherRegistry.b); - private static final DataWatcherObject UNUSED_WATCHER = DataWatcher.a(EntityMyHusk.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyHusk.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor TYPE_WATCHER = SynchedEntityData.defineId(EntityMyHusk.class, EntityDataSerializers.INT); + private static final EntityDataAccessor UNUSED_WATCHER = SynchedEntityData.defineId(EntityMyHusk.class, EntityDataSerializers.BOOLEAN); - public EntityMyHusk(World world, MyPet myPet) { + public EntityMyHusk(Level world, MyPet myPet) { super(world, myPet); } @@ -66,7 +66,7 @@ public EntityMyHusk(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.husk.death"; } @@ -94,34 +94,34 @@ protected String getLivingSound() { */ @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -129,49 +129,49 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Zombie.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); // is baby - getDataWatcher().register(TYPE_WATCHER, 0); // type - getDataWatcher().register(UNUSED_WATCHER, false); // N/A + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); // is baby + getEntityData().define(TYPE_WATCHER, 0); // type + getEntityData().define(UNUSED_WATCHER, false); // N/A } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { @@ -193,17 +193,17 @@ public MyHusk getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyIllusioner.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyIllusioner.java index 36d2a8dd3a..cfd0fa960f 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyIllusioner.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyIllusioner.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EntitySize; @@ -29,33 +36,27 @@ import de.Keyle.MyPet.api.entity.types.MyIllusioner; import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.95F) public class EntityMyIllusioner extends EntityMyPet { - protected static final DataWatcherObject RAID_WATCHER = DataWatcher.a(EntityMyIllusioner.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SPELL_WATCHER = DataWatcher.a(EntityMyIllusioner.class, DataWatcherRegistry.a); + protected static final EntityDataAccessor RAID_WATCHER = SynchedEntityData.defineId(EntityMyIllusioner.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SPELL_WATCHER = SynchedEntityData.defineId(EntityMyIllusioner.class, EntityDataSerializers.BYTE); - public EntityMyIllusioner(World world, MyPet myPet) { + public EntityMyIllusioner(Level world, MyPet myPet) { super(world, myPet); } @@ -63,7 +64,7 @@ public EntityMyIllusioner(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.illusioner.death"; } @@ -90,32 +91,32 @@ protected String getLivingSound() { * false: no reaction on rightclick */ @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { @@ -125,41 +126,41 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); if (slot == EquipmentSlot.MainHand) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(RAID_WATCHER, false); - getDataWatcher().register(SPELL_WATCHER, (byte) 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(RAID_WATCHER, false); + getEntityData().define(SPELL_WATCHER, (byte) 0); } @Override public void updateVisuals() { - getDataWatcher().set(SPELL_WATCHER, (byte) (getMyPet().getEquipment(EquipmentSlot.MainHand) != null ? 1 : 0)); + getEntityData().set(SPELL_WATCHER, (byte) (getMyPet().getEquipment(EquipmentSlot.MainHand) != null ? 1 : 0)); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { @@ -174,17 +175,17 @@ public MyIllusioner getMyPet() { } public void setPetEquipment(ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.a, itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.MAINHAND, itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyIronGolem.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyIronGolem.java index 2f61ef345a..2cdb890d38 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyIronGolem.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyIronGolem.java @@ -20,40 +20,40 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyIronGolem; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; @EntitySize(width = 1.4F, height = 2.7F) public class EntityMyIronGolem extends EntityMyPet { - protected static final DataWatcherObject UNUSED_WATCHER = DataWatcher.a(EntityMyIronGolem.class, DataWatcherRegistry.a); + protected static final EntityDataAccessor UNUSED_WATCHER = SynchedEntityData.defineId(EntityMyIronGolem.class, EntityDataSerializers.BYTE); int flowerCounter = 0; boolean flower = false; - public EntityMyIronGolem(World world, MyPet myPet) { + public EntityMyIronGolem(Level world, MyPet myPet) { super(world, myPet); } @@ -61,10 +61,10 @@ public EntityMyIronGolem(World world, MyPet myPet) { public boolean attack(Entity entity) { boolean flag = false; try { - this.t.broadcastEntityEffect(this, (byte) 4); + this.level.broadcastEntityEvent(this, (byte) 4); flag = super.attack(entity); if (Configuration.MyPet.IronGolem.CAN_TOSS_UP && flag) { - entity.setMot(entity.getMot().add(0, 0.4000000059604645D, 0)); + entity.setDeltaMovement(entity.getDeltaMovement().add(0, 0.4000000059604645D, 0)); this.makeSound("entity.iron_golem.attack", 1.0F, 1.0F); } } catch (Exception e) { @@ -74,7 +74,7 @@ public boolean attack(Entity entity) { } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.iron_golem.death"; } @@ -89,18 +89,18 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(UNUSED_WATCHER, (byte) 0); // N/A + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(UNUSED_WATCHER, (byte) 0); // N/A } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } - if (itemStack.getItem() == Items.mq) { + if (itemStack.getItem() == Items.IRON_INGOT) { Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { super.setHealth(this.getHealth() + 0.0001F); @@ -113,31 +113,31 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En }, 10L); } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Blocks.bw.getItem() && !getMyPet().hasFlower() && getOwner().getPlayer().isSneaking()) { + if (itemStack.getItem() == Blocks.POPPY.asItem() && !getMyPet().hasFlower() && getOwner().getPlayer().isSneaking()) { getMyPet().setFlower(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getMyPet().hasFlower() && getOwner().getPlayer().isSneaking()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getFlower())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasFlower() && getOwner().getPlayer().isSneaking()) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getFlower())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setFlower(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -145,10 +145,10 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override @@ -171,7 +171,7 @@ public void playPetStepSound() { public void onLivingUpdate() { super.onLivingUpdate(); if (this.flower && this.flowerCounter-- <= 0) { - this.t.broadcastEntityEffect(this, (byte) 11); + this.level.broadcastEntityEvent(this, (byte) 11); flowerCounter = 300; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyLlama.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyLlama.java index dd227f10bd..9fa70d239b 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyLlama.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyLlama.java @@ -20,50 +20,50 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyLlama; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.tags.TagsItem; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.tags.ItemTags; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BlockCarpet; import net.minecraft.world.level.block.Blocks; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Optional; -import java.util.UUID; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.block.WoolCarpetBlock; @EntitySize(width = 0.9F, height = 1.87F) public class EntityMyLlama extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyLlama.class, DataWatcherRegistry.i); - private static final DataWatcherObject SADDLE_CHEST_WATCHER = DataWatcher.a(EntityMyLlama.class, DataWatcherRegistry.a); - private static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyLlama.class, DataWatcherRegistry.o); - private static final DataWatcherObject CHEST_WATCHER = DataWatcher.a(EntityMyLlama.class, DataWatcherRegistry.i); - private static final DataWatcherObject STRENGTH_WATCHER = DataWatcher.a(EntityMyLlama.class, DataWatcherRegistry.b); - private static final DataWatcherObject COLOR_WATCHER = DataWatcher.a(EntityMyLlama.class, DataWatcherRegistry.b); - private static final DataWatcherObject VARIANT_WATCHER = DataWatcher.a(EntityMyLlama.class, DataWatcherRegistry.b); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor SADDLE_CHEST_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.OPTIONAL_UUID); + private static final EntityDataAccessor CHEST_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor STRENGTH_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.INT); + private static final EntityDataAccessor COLOR_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.INT); + private static final EntityDataAccessor VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyLlama.class, EntityDataSerializers.INT); - public EntityMyLlama(World world, MyPet myPet) { + public EntityMyLlama(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.llama.death"; } @@ -78,55 +78,55 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (itemStack != null && canUseItem()) { - if (TagsItem.g.isTagged(itemStack.getItem()) && !getMyPet().hasDecor() && getOwner().getPlayer().isSneaking() && canEquip()) { + if (ItemTags.CARPETS.contains(itemStack.getItem()) && !getMyPet().hasDecor() && getOwner().getPlayer().isSneaking() && canEquip()) { getMyPet().setDecor(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Blocks.bX.getItem() && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && !getMyPet().isBaby() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Blocks.CHEST.asItem() && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && !getMyPet().isBaby() && canEquip()) { getMyPet().setChest(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { if (getMyPet().hasChest()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } if (getMyPet().hasDecor()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getDecor())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getDecor())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setChest(null); getMyPet().setDecor(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -134,46 +134,46 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Llama.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SADDLE_CHEST_WATCHER, (byte) 0); // saddle & chest - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); // owner - getDataWatcher().register(CHEST_WATCHER, true); - getDataWatcher().register(STRENGTH_WATCHER, 0); - getDataWatcher().register(COLOR_WATCHER, 0); - getDataWatcher().register(VARIANT_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SADDLE_CHEST_WATCHER, (byte) 0); // saddle & chest + getEntityData().define(OWNER_WATCHER, Optional.empty()); // owner + getEntityData().define(CHEST_WATCHER, true); + getEntityData().define(STRENGTH_WATCHER, 0); + getEntityData().define(COLOR_WATCHER, 0); + getEntityData().define(VARIANT_WATCHER, 0); } @Override public void updateVisuals() { - this.getDataWatcher().set(CHEST_WATCHER, getMyPet().hasChest()); - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); if (getMyPet().hasDecor()) { ItemStack is = CraftItemStack.asNMSCopy(getMyPet().getDecor()); - Block block = Block.asBlock(is.getItem()); - int color = block instanceof BlockCarpet ? ((BlockCarpet) block).c().getColorIndex() : 0; - this.getDataWatcher().set(COLOR_WATCHER, color); + Block block = Block.byItem(is.getItem()); + int color = block instanceof WoolCarpetBlock ? ((WoolCarpetBlock) block).getColor().getId() : 0; + this.getEntityData().set(COLOR_WATCHER, color); } else { - this.getDataWatcher().set(COLOR_WATCHER, -1); + this.getEntityData().set(COLOR_WATCHER, -1); } - this.getDataWatcher().set(VARIANT_WATCHER, getMyPet().getVariant()); + this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMagmaCube.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMagmaCube.java index b5f7a419eb..4c41e76282 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMagmaCube.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMagmaCube.java @@ -25,25 +25,25 @@ import de.Keyle.MyPet.api.entity.types.MyMagmaCube; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack.MeleeAttack; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.entity.EntityPose; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.Pose; +import net.minecraft.world.level.Level; @EntitySize(width = 0.5100001F, height = 0.5100001F) public class EntityMyMagmaCube extends EntityMyPet { - private static final DataWatcherObject SIZE_WATCHER = DataWatcher.a(EntityMyMagmaCube.class, DataWatcherRegistry.b); + private static final EntityDataAccessor SIZE_WATCHER = SynchedEntityData.defineId(EntityMyMagmaCube.class, EntityDataSerializers.INT); int jumpDelay; - public EntityMyMagmaCube(World world, MyPet myPet) { + public EntityMyMagmaCube(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.magma_cube.death"; } @@ -58,42 +58,42 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(SIZE_WATCHER, 1); //size + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(SIZE_WATCHER, 1); //size } @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (this.z && jumpDelay-- <= 0) { - getControllerJump().jump(); - jumpDelay = (this.Q.nextInt(20) + 50); - this.makeSound("entity.magma_cube.jump", 1.0F, ((this.Q.nextFloat() - this.Q.nextFloat()) * 0.2F + 1.0F) / 0.8F); + if (this.onGround && jumpDelay-- <= 0) { + getJumpControl().jump(); + jumpDelay = (this.random.nextInt(20) + 50); + this.makeSound("entity.magma_cube.jump", 1.0F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F); } } @Override public void updateVisuals() { int size = Math.max(1, getMyPet().getSize()); - getDataWatcher().set(SIZE_WATCHER, size); - this.updateSize(); + getEntityData().set(SIZE_WATCHER, size); + this.refreshDimensions(); if (petPathfinderSelector != null && petPathfinderSelector.hasGoal("MeleeAttack")) { petPathfinderSelector.replaceGoal("MeleeAttack", new MeleeAttack(this, 0.1F, 3 + (getMyPet().getSize() * 0.51), 20)); } } @Override - public net.minecraft.world.entity.EntitySize a(EntityPose entitypose) { + public net.minecraft.world.entity.EntityDimensions getDimensions(Pose entitypose) { EntitySize es = this.getClass().getAnnotation(EntitySize.class); if (es != null) { int size = Math.max(1, getMyPet().getSize()); float width = es.width(); float height = Float.isNaN(es.height()) ? width : es.height(); - return new net.minecraft.world.entity.EntitySize(width * size, height * size, false); + return new net.minecraft.world.entity.EntityDimensions(width * size, height * size, false); } - return super.a(entitypose); + return super.getDimensions(entitypose); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMooshroom.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMooshroom.java index 247de36ffe..523ce6cd07 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMooshroom.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMooshroom.java @@ -20,35 +20,36 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import org.bukkit.Bukkit; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyMooshroom; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 1.3F) public class EntityMyMooshroom extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyMooshroom.class, DataWatcherRegistry.i); - private static final DataWatcherObject COLOR_WATCHER = DataWatcher.a(EntityMyMooshroom.class, DataWatcherRegistry.d); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyMooshroom.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor COLOR_WATCHER = SynchedEntityData.defineId(EntityMyMooshroom.class, EntityDataSerializers.STRING); - public EntityMyMooshroom(World world, MyPet myPet) { + public EntityMyMooshroom(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.cow.death"; } @@ -63,59 +64,59 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (itemStack != null) { - if (itemStack.getItem().equals(Items.nc)) { + if (itemStack.getItem().equals(Items.BOWL)) { if (!getOwner().equals(entityhuman) || !canUseItem() || !Configuration.MyPet.Mooshroom.CAN_GIVE_SOUP) { - final int itemInHandIndex = entityhuman.getInventory().k; - ItemStack is = new ItemStack(Items.nd); + final int itemInHandIndex = entityhuman.getInventory().selected; + ItemStack is = new ItemStack(Items.MUSHROOM_STEW); final ItemStack oldIs = entityhuman.getInventory().getItem(itemInHandIndex); entityhuman.getInventory().setItem(itemInHandIndex, is); Bukkit.getScheduler().scheduleSyncDelayedTask(MyPetApi.getPlugin(), () -> entityhuman.getInventory().setItem(itemInHandIndex, oldIs), 2L); } else { - itemStack.subtract(1); + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, new ItemStack(Items.nd)); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, new ItemStack(Items.MUSHROOM_STEW)); } else { - if (!entityhuman.getInventory().pickup(new ItemStack(Items.nd))) { - entityhuman.drop(new ItemStack(Items.pG), true); + if (!entityhuman.getInventory().add(new ItemStack(Items.MUSHROOM_STEW))) { + entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } if (getOwner().equals(entityhuman) && canUseItem()) { if (Configuration.MyPet.Mooshroom.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(COLOR_WATCHER, "red"); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(COLOR_WATCHER, "red"); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(COLOR_WATCHER, getMyPet().getType().getType()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(COLOR_WATCHER, getMyPet().getType().getType()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMule.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMule.java index 99a38bf092..567207019c 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMule.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyMule.java @@ -20,49 +20,49 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyMule; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.BlockPosition; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.sounds.SoundEffects; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.core.BlockPos; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.IJumpable; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.PlayerRideableJumping; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SoundEffectType; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Optional; -import java.util.UUID; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; @EntitySize(width = 1.4F, height = 1.6F) -public class EntityMyMule extends EntityMyPet implements IJumpable { +public class EntityMyMule extends EntityMyPet implements PlayerRideableJumping { - protected static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyMule.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SADDLE_WATCHER = DataWatcher.a(EntityMyMule.class, DataWatcherRegistry.a); - protected static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyMule.class, DataWatcherRegistry.o); - private static final DataWatcherObject CHEST_WATCHER = DataWatcher.a(EntityMyMule.class, DataWatcherRegistry.i); + protected static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyMule.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SADDLE_WATCHER = SynchedEntityData.defineId(EntityMyMule.class, EntityDataSerializers.BYTE); + protected static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyMule.class, EntityDataSerializers.OPTIONAL_UUID); + private static final EntityDataAccessor CHEST_WATCHER = SynchedEntityData.defineId(EntityMyMule.class, EntityDataSerializers.BOOLEAN); int soundCounter = 0; int rearCounter = -1; - public EntityMyMule(World world, MyPet myPet) { + public EntityMyMule(Level world, MyPet myPet) { super(world, myPet); } @@ -75,11 +75,11 @@ public EntityMyMule(World world, MyPet myPet) { * 128 mouth open */ protected void applyVisual(int value, boolean flag) { - int i = this.getDataWatcher().get(SADDLE_WATCHER); + int i = this.getEntityData().get(SADDLE_WATCHER); if (flag) { - this.getDataWatcher().set(SADDLE_WATCHER, (byte) (i | value)); + this.getEntityData().set(SADDLE_WATCHER, (byte) (i | value)); } else { - this.getDataWatcher().set(SADDLE_WATCHER, (byte) (i & (~value))); + this.getEntityData().set(SADDLE_WATCHER, (byte) (i & (~value))); } } @@ -100,55 +100,55 @@ public boolean attack(Entity entity) { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.lL && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Item.getItemOf(Blocks.bX) && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Item.byBlock(Blocks.CHEST) && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && canEquip()) { getMyPet().setChest(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { if (getMyPet().hasChest()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } if (getMyPet().hasSaddle()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setChest(null); getMyPet().setSaddle(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -156,39 +156,39 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Mule.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SADDLE_WATCHER, (byte) 0); - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); - getDataWatcher().register(CHEST_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SADDLE_WATCHER, (byte) 0); + getEntityData().define(OWNER_WATCHER, Optional.empty()); + getEntityData().define(CHEST_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(CHEST_WATCHER, getMyPet().hasChest()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest()); applyVisual(4, getMyPet().hasSaddle()); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.mule.death"; } @@ -222,25 +222,25 @@ public void onLivingUpdate() { } @Override - public void playStepSound(BlockPosition blockposition, IBlockData blockdata) { + public void playStepSound(BlockPos blockposition, BlockState blockdata) { if (!blockdata.getMaterial().isLiquid()) { - IBlockData blockdataUp = this.t.getType(blockposition.up()); - SoundEffectType soundeffecttype = blockdata.getStepSound(); - if (blockdataUp.getBlock() == Blocks.cK) { - soundeffecttype = blockdata.getStepSound(); + BlockState blockdataUp = this.level.getBlockState(blockposition.up()); + SoundType soundeffecttype = blockdata.getSoundType(); + if (blockdataUp.getBlock() == Blocks.SNOW) { + soundeffecttype = blockdata.getSoundType(); } if (this.isVehicle()) { ++this.soundCounter; if (this.soundCounter > 5 && this.soundCounter % 3 == 0) { - this.playSound(SoundEffects.hB, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_GALLOP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } else if (this.soundCounter <= 5) { - this.playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } } else if (!blockdata.getMaterial().isLiquid()) { this.soundCounter += 1; - playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } else { - playSound(SoundEffects.iG, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } } } @@ -251,22 +251,22 @@ public MyMule getMyPet() { } @Override - public void a(int i) { - // I don't know. + public void onPlayerJump(int i) { + // I don't know. <- this was here before the remap } /* Jump power methods */ @Override - public boolean a() { + public boolean canJump() { return true; } @Override - public void b(int i) { + public void handleStartJump(int i) { this.jumpPower = i; } @Override - public void b() { + public void handleStopJump() { } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyOcelot.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyOcelot.java index b5388e61ce..3601e65190 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyOcelot.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyOcelot.java @@ -25,27 +25,27 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyOcelot; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 0.8F) public class EntityMyOcelot extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyOcelot.class, DataWatcherRegistry.i); - private static final DataWatcherObject TRUSTING_WATCHER = DataWatcher.a(EntityMyOcelot.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyOcelot.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor TRUSTING_WATCHER = SynchedEntityData.defineId(EntityMyOcelot.class, EntityDataSerializers.BOOLEAN); - public EntityMyOcelot(World world, MyPet myPet) { + public EntityMyOcelot(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.ocelot.death"; } @@ -60,38 +60,38 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman)) { if (itemStack != null && canUseItem() && getOwner().getPlayer().isSneaking()) { if (Configuration.MyPet.Ocelot.GROW_UP_ITEM.compare(itemStack) && canUseItem() && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(TRUSTING_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(TRUSTING_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPanda.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPanda.java index f45023e50b..44356049d1 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPanda.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPanda.java @@ -25,32 +25,32 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyPanda; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 1.825F, height = 1.25F) public class EntityMyPanda extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyPanda.class, DataWatcherRegistry.i); - private static final DataWatcherObject ASK_FOR_BAMBOO_TICKS_WATCHER = DataWatcher.a(EntityMyPanda.class, DataWatcherRegistry.b); - private static final DataWatcherObject SNEEZE_PROGRESS_WATCHER = DataWatcher.a(EntityMyPanda.class, DataWatcherRegistry.b); - private static final DataWatcherObject EATING_TICKS_WATCHER = DataWatcher.a(EntityMyPanda.class, DataWatcherRegistry.b); - private static final DataWatcherObject MAIN_GENE_WATCHER = DataWatcher.a(EntityMyPanda.class, DataWatcherRegistry.a); - private static final DataWatcherObject HIDDEN_GENE_WATCHER = DataWatcher.a(EntityMyPanda.class, DataWatcherRegistry.a); - private static final DataWatcherObject ACTIONS_WATCHER = DataWatcher.a(EntityMyPanda.class, DataWatcherRegistry.a); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyPanda.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor ASK_FOR_BAMBOO_TICKS_WATCHER = SynchedEntityData.defineId(EntityMyPanda.class, EntityDataSerializers.INT); + private static final EntityDataAccessor SNEEZE_PROGRESS_WATCHER = SynchedEntityData.defineId(EntityMyPanda.class, EntityDataSerializers.INT); + private static final EntityDataAccessor EATING_TICKS_WATCHER = SynchedEntityData.defineId(EntityMyPanda.class, EntityDataSerializers.INT); + private static final EntityDataAccessor MAIN_GENE_WATCHER = SynchedEntityData.defineId(EntityMyPanda.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor HIDDEN_GENE_WATCHER = SynchedEntityData.defineId(EntityMyPanda.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor ACTIONS_WATCHER = SynchedEntityData.defineId(EntityMyPanda.class, EntityDataSerializers.BYTE); - public EntityMyPanda(World world, MyPet myPet) { + public EntityMyPanda(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.panda.death"; } @@ -65,45 +65,45 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman)) { if (itemStack != null && canUseItem() && getOwner().getPlayer().isSneaking()) { if (Configuration.MyPet.Ocelot.GROW_UP_ITEM.compare(itemStack) && canUseItem() && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(ASK_FOR_BAMBOO_TICKS_WATCHER, 0); - getDataWatcher().register(SNEEZE_PROGRESS_WATCHER, 0); - getDataWatcher().register(MAIN_GENE_WATCHER, (byte) 0); - getDataWatcher().register(HIDDEN_GENE_WATCHER, (byte) 0); - getDataWatcher().register(ACTIONS_WATCHER, (byte) 0); - getDataWatcher().register(EATING_TICKS_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(ASK_FOR_BAMBOO_TICKS_WATCHER, 0); + getEntityData().define(SNEEZE_PROGRESS_WATCHER, 0); + getEntityData().define(MAIN_GENE_WATCHER, (byte) 0); + getEntityData().define(HIDDEN_GENE_WATCHER, (byte) 0); + getEntityData().define(ACTIONS_WATCHER, (byte) 0); + getEntityData().define(EATING_TICKS_WATCHER, 0); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(MAIN_GENE_WATCHER, (byte) getMyPet().getMainGene().ordinal()); - this.getDataWatcher().set(HIDDEN_GENE_WATCHER, (byte) getMyPet().getHiddenGene().ordinal()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(MAIN_GENE_WATCHER, (byte) getMyPet().getMainGene().ordinal()); + this.getEntityData().set(HIDDEN_GENE_WATCHER, (byte) getMyPet().getHiddenGene().ordinal()); } /* @@ -114,9 +114,9 @@ public void updateVisuals() { */ public void updateActionsWatcher(int i, boolean flag) { if (flag) { - this.Y.set(ACTIONS_WATCHER, (byte) (this.Y.get(ACTIONS_WATCHER) | i)); + this.entityData.set(ACTIONS_WATCHER, (byte) (this.entityData.get(ACTIONS_WATCHER) | i)); } else { - this.Y.set(ACTIONS_WATCHER, (byte) (this.Y.get(ACTIONS_WATCHER) & ~i)); + this.entityData.set(ACTIONS_WATCHER, (byte) (this.entityData.get(ACTIONS_WATCHER) & ~i)); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyParrot.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyParrot.java index 9af98bcc4c..b58ad6e15a 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyParrot.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyParrot.java @@ -20,28 +20,28 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.Optional; +import java.util.UUID; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyParrot; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; - -import java.util.Optional; -import java.util.UUID; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.5F, height = 0.9f) public class EntityMyParrot extends EntityMyPet { + + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyParrot.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SIT_WATCHER = SynchedEntityData.defineId(EntityMyParrot.class, EntityDataSerializers.BYTE); + protected static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyParrot.class, EntityDataSerializers.OPTIONAL_UUID); + private static final EntityDataAccessor VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyParrot.class, EntityDataSerializers.INT); - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyParrot.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SIT_WATCHER = DataWatcher.a(EntityMyParrot.class, DataWatcherRegistry.a); - protected static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyParrot.class, DataWatcherRegistry.o); - private static final DataWatcherObject VARIANT_WATCHER = DataWatcher.a(EntityMyParrot.class, DataWatcherRegistry.b); - - public EntityMyParrot(World world, MyPet myPet) { + public EntityMyParrot(Level world, MyPet myPet) { super(world, myPet); } @@ -54,7 +54,7 @@ public MyParrot getMyPet() { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.parrot.death"; } @@ -72,17 +72,16 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SIT_WATCHER, (byte) 0); - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); - getDataWatcher().register(VARIANT_WATCHER, 0); + protected void defineSynchedData() { + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SIT_WATCHER, (byte) 0); + getEntityData().define(OWNER_WATCHER, Optional.empty()); + getEntityData().define(VARIANT_WATCHER, 0); } @Override public void updateVisuals() { - this.getDataWatcher().set(VARIANT_WATCHER, getMyPet().getVariant()); + this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant()); } @Override @@ -90,8 +89,8 @@ public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Parrot.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } } @@ -100,9 +99,9 @@ public void onLivingUpdate() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Parrot.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPhantom.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPhantom.java index 7381da27da..db24c5fa06 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPhantom.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPhantom.java @@ -26,23 +26,23 @@ import de.Keyle.MyPet.api.entity.types.MyPhantom; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack.MeleeAttack; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.entity.EntityPose; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.Pose; +import net.minecraft.world.level.Level; @EntitySize(width = 0.51F, height = 0.51F) public class EntityMyPhantom extends EntityMyPet { - private static final DataWatcherObject SIZE_WATCHER = DataWatcher.a(EntityMyPhantom.class, DataWatcherRegistry.b); + private static final EntityDataAccessor SIZE_WATCHER = SynchedEntityData.defineId(EntityMyPhantom.class, EntityDataSerializers.INT); - public EntityMyPhantom(World world, MyPet myPet) { + public EntityMyPhantom(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.phantom.death"; } @@ -57,32 +57,32 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); + protected void defineSynchedData() { + super.defineSynchedData(); - getDataWatcher().register(SIZE_WATCHER, 0); + getEntityData().define(SIZE_WATCHER, 0); } @Override public void updateVisuals() { int size = Math.max(1, getMyPet().getSize()); - getDataWatcher().set(SIZE_WATCHER, size); - this.updateSize(); + getEntityData().set(SIZE_WATCHER, size); + this.refreshDimensions(); if (petPathfinderSelector != null && petPathfinderSelector.hasGoal("MeleeAttack")) { petPathfinderSelector.replaceGoal("MeleeAttack", new MeleeAttack(this, 0.1F, 3 + (getMyPet().getSize() * 0.2), 20)); } } @Override - public net.minecraft.world.entity.EntitySize a(EntityPose entitypose) { + public net.minecraft.world.entity.EntityDimensions getDimensions(Pose entitypose) { EntitySize es = this.getClass().getAnnotation(EntitySize.class); if (es != null) { int size = Math.max(1, getMyPet().getSize()); float width = es.width(); float height = Float.isNaN(es.height()) ? width : es.height(); - return new net.minecraft.world.entity.EntitySize(width * size, height * size, false); + return new net.minecraft.world.entity.EntityDimensions(width * size, height * size, false); } - return super.a(entitypose); + return super.getDimensions(entitypose); } @Override @@ -95,8 +95,8 @@ public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Phantom.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } } @@ -105,9 +105,9 @@ public void onLivingUpdate() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Phantom.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPig.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPig.java index f71641440d..d739785b73 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPig.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPig.java @@ -20,45 +20,44 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyPig; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import java.lang.reflect.InvocationTargetException; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 0.9F) public class EntityMyPig extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyPig.class, DataWatcherRegistry.i); - private static final DataWatcherObject SADDLE_WATCHER = DataWatcher.a(EntityMyPig.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyPig.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor SADDLE_WATCHER = SynchedEntityData.defineId(EntityMyPig.class, EntityDataSerializers.BOOLEAN); - public EntityMyPig(World world, MyPet myPet) { + public EntityMyPig(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.pig.death"; } @@ -73,17 +72,17 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) { - if (enumhand == EnumHand.b) { + public InteractionResult handlePlayerInteraction(final net.minecraft.world.entity.player.Player entityhuman, InteractionHand enumhand, final ItemStack itemStack) { + if (enumhand == InteractionHand.OFF_HAND) { if (itemStack != null) { - if (itemStack.getItem() == Items.rP) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutAttachEntity(this, null)); - entityhuman.a(EnumHand.b, ItemStack.b); + if (itemStack.getItem() == Items.LEAD) { + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEntityLinkPacket(this, null)); + entityhuman.setItemInHand(InteractionHand.OFF_HAND, ItemStack.EMPTY); new BukkitRunnable() { @Override public void run() { - if (entityhuman instanceof EntityPlayer) { - entityhuman.a(EnumHand.b, itemStack); + if (entityhuman instanceof ServerPlayer) { + entityhuman.setItemInHand(InteractionHand.OFF_HAND, itemStack);//TODO Player p = (Player) entityhuman.getBukkitEntity(); if (!p.isOnline()) { p.saveData(); @@ -93,39 +92,39 @@ public void run() { }.runTaskLater(MyPetApi.getPlugin(), 5); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.lL && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { + if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setSaddle(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -133,32 +132,32 @@ public void run() { } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Pig.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SADDLE_WATCHER, false); // saddle + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SADDLE_WATCHER, false); // saddle } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(SADDLE_WATCHER, getMyPet().hasSaddle()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(SADDLE_WATCHER, getMyPet().hasSaddle()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPiglin.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPiglin.java index 3e3766c330..35d68f993b 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPiglin.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPiglin.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -29,40 +36,33 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPet.PetState; import de.Keyle.MyPet.api.entity.types.MyPiglin; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyPiglin extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyPiglin.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyPiglin.class, EntityDataSerializers.BOOLEAN); - public EntityMyPiglin(World world, MyPet myPet) { + public EntityMyPiglin(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.piglin.death"; } @@ -77,34 +77,34 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == EnumInteractionResult.b) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == InteractionResult.CONSUME) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -112,42 +112,42 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Piglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); // is baby + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); // is baby } /** @@ -161,7 +161,7 @@ public float getSoundSpeed() { @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == PetState.Here) { @@ -178,17 +178,17 @@ public MyPiglin getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPiglinBrute.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPiglinBrute.java index 899581c72a..6f9013a018 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPiglinBrute.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPiglinBrute.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -30,85 +37,76 @@ import de.Keyle.MyPet.api.entity.MyPet.PetState; import de.Keyle.MyPet.api.entity.types.MyPiglinBrute; import de.Keyle.MyPet.api.util.NMSUtil; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.sounds.SoundEffects; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyPiglinBrute extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyPiglinBrute.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyPiglinBrute.class, EntityDataSerializers.BOOLEAN); - public EntityMyPiglinBrute(World world, MyPet myPet) { + public EntityMyPiglinBrute(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { - - - return NMSUtil.getSoundEffectId(SoundEffects.nZ); + protected String getMyPetDeathSound() { + return NMSUtil.getSoundEffectId(SoundEvents.PIGLIN_BRUTE_DEATH); } @Override protected String getHurtSound() { - return NMSUtil.getSoundEffectId(SoundEffects.oa); + return NMSUtil.getSoundEffectId(SoundEvents.PIGLIN_BRUTE_HURT); } @Override protected String getLivingSound() { - return NMSUtil.getSoundEffectId(SoundEffects.nX); + return NMSUtil.getSoundEffectId(SoundEvents.PIGLIN_BRUTE_AMBIENT); } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == EnumInteractionResult.b) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == InteractionResult.CONSUME) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -116,42 +114,42 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.PiglinBrute.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); // is baby + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); // is baby } /** @@ -165,7 +163,7 @@ public float getSoundSpeed() { @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == PetState.Here) { @@ -182,17 +180,17 @@ public MyPiglinBrute getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPillager.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPillager.java index 42284afba8..fca932b50f 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPillager.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPillager.java @@ -20,44 +20,44 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyPillager; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemBanner; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BannerItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.95F) public class EntityMyPillager extends EntityMyPet { - protected static final DataWatcherObject RAID_WATCHER = DataWatcher.a(EntityMyPillager.class, DataWatcherRegistry.i); - private static final DataWatcherObject CROSSBOW_WATCHER = DataWatcher.a(EntityMyPillager.class, DataWatcherRegistry.i); + protected static final EntityDataAccessor RAID_WATCHER = SynchedEntityData.defineId(EntityMyPillager.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor CROSSBOW_WATCHER = SynchedEntityData.defineId(EntityMyPillager.class, EntityDataSerializers.BOOLEAN); - public EntityMyPillager(World world, MyPet myPet) { + public EntityMyPillager(Level world, MyPet myPet) { super(world, myPet); } @@ -65,7 +65,7 @@ public EntityMyPillager(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.pillager.death"; } @@ -92,34 +92,34 @@ protected String getLivingSound() { * false: no reaction on rightclick */ @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -127,60 +127,60 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); if (slot == EquipmentSlot.MainHand) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } - } else if (itemStack.getItem() instanceof ItemBanner && getOwner().getPlayer().isSneaking() && canEquip()) { + } else if (itemStack.getItem() instanceof BannerItem && getOwner().getPlayer().isSneaking() && canEquip()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.Helmet)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(EquipmentSlot.Helmet, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(RAID_WATCHER, false); - getDataWatcher().register(CROSSBOW_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(RAID_WATCHER, false); + getEntityData().define(CROSSBOW_WATCHER, false); } @Override public void updateVisuals() { Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { - setPetEquipment(CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.MainHand)), EnumItemSlot.a); - setPetEquipment(CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.Helmet)), EnumItemSlot.f); + setPetEquipment(CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.MainHand)), net.minecraft.world.entity.EquipmentSlot.MAINHAND); + setPetEquipment(CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.Helmet)), net.minecraft.world.entity.EquipmentSlot.HEAD); } }, 5L); } @@ -190,21 +190,21 @@ public MyPillager getMyPet() { return (MyPillager) myPet; } - public void setPetEquipment(ItemStack itemStack, EnumItemSlot slot) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(slot, itemStack)))); - if (slot == EnumItemSlot.a) { - getDataWatcher().set(CROSSBOW_WATCHER, itemStack.getItem() == Items.sS); + public void setPetEquipment(ItemStack itemStack, net.minecraft.world.entity.EquipmentSlot slot) { + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(slot, itemStack)))); + if (slot == net.minecraft.world.entity.EquipmentSlot.MAINHAND) { + getEntityData().set(CROSSBOW_WATCHER, itemStack.getItem() == Items.CROSSBOW); } } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPolarBear.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPolarBear.java index bdb3ec10dc..8685957d82 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPolarBear.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPolarBear.java @@ -25,30 +25,30 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyPolarBear; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 1.3F, height = 1.4F) public class EntityMyPolarBear extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyPolarBear.class, DataWatcherRegistry.i); - private static final DataWatcherObject REAR_WATCHER = DataWatcher.a(EntityMyPolarBear.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyPolarBear.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor REAR_WATCHER = SynchedEntityData.defineId(EntityMyPolarBear.class, EntityDataSerializers.BOOLEAN); int rearCounter = -1; - public EntityMyPolarBear(World world, MyPet myPet) { + public EntityMyPolarBear(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.polar_bear.death"; } @@ -63,31 +63,31 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (Configuration.MyPet.Cow.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(REAR_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(REAR_WATCHER, false); } @@ -97,7 +97,7 @@ public boolean attack(Entity entity) { try { flag = super.attack(entity); if (flag) { - this.getDataWatcher().set(REAR_WATCHER, true); + this.getEntityData().set(REAR_WATCHER, true); rearCounter = 10; } } catch (Exception e) { @@ -110,14 +110,14 @@ public boolean attack(Entity entity) { public void onLivingUpdate() { super.onLivingUpdate(); if (rearCounter > -1 && rearCounter-- == 0) { - this.getDataWatcher().set(REAR_WATCHER, false); + this.getEntityData().set(REAR_WATCHER, false); rearCounter = -1; } } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPufferfish.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPufferfish.java index 83a7ddaa26..76aacf873d 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPufferfish.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyPufferfish.java @@ -26,23 +26,23 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyPufferfish; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.5F, height = 0.5f) public class EntityMyPufferfish extends EntityMyPet { - private static final DataWatcherObject FROM_BUCKET_WATCHER = DataWatcher.a(EntityMyPufferfish.class, DataWatcherRegistry.i); - private static final DataWatcherObject PUFF_WATCHER = DataWatcher.a(EntityMyPufferfish.class, DataWatcherRegistry.b); + private static final EntityDataAccessor FROM_BUCKET_WATCHER = SynchedEntityData.defineId(EntityMyPufferfish.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor PUFF_WATCHER = SynchedEntityData.defineId(EntityMyPufferfish.class, EntityDataSerializers.INT); - public EntityMyPufferfish(World world, MyPet myPet) { + public EntityMyPufferfish(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.puffer_fish.death"; } @@ -59,7 +59,7 @@ protected String getLivingSound() { @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (!isInWater() && this.Q.nextBoolean()) { + if (!isInWater() && this.random.nextBoolean()) { MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, 0.7, 0), ParticleCompat.WATER_SPLASH.get(), 0.2F, 0.2F, 0.2F, 0.5F, 10, 20); } } @@ -71,13 +71,13 @@ public MyPufferfish getMyPet() { @Override public void updateVisuals() { - getDataWatcher().set(PUFF_WATCHER, getMyPet().getPuffState().ordinal()); + getEntityData().set(PUFF_WATCHER, getMyPet().getPuffState().ordinal()); } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(FROM_BUCKET_WATCHER, false); - getDataWatcher().register(PUFF_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(FROM_BUCKET_WATCHER, false); + getEntityData().define(PUFF_WATCHER, 0); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyRabbit.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyRabbit.java index b0b31a9a56..5ba0caa701 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyRabbit.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyRabbit.java @@ -20,39 +20,35 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; -import java.lang.reflect.Method; - -import org.bukkit.Bukkit; - import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyRabbit; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 0.7F) public class EntityMyRabbit extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyRabbit.class, DataWatcherRegistry.i); - private static final DataWatcherObject VARIANT_WATCHER = DataWatcher.a(EntityMyRabbit.class, DataWatcherRegistry.b); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyRabbit.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyRabbit.class, EntityDataSerializers.INT); int jumpDelay; - public EntityMyRabbit(World world, MyPet myPet) { + public EntityMyRabbit(Level world, MyPet myPet) { super(world, myPet); - this.jumpDelay = (this.Q.nextInt(20) + 10); + this.jumpDelay = (this.random.nextInt(20) + 10); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.rabbit.death"; } @@ -72,37 +68,37 @@ public void playPetStepSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (Configuration.MyPet.Rabbit.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } this.getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - public void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); // is baby - getDataWatcher().register(VARIANT_WATCHER, 0); // variant + public void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); // is baby + getEntityData().define(VARIANT_WATCHER, 0); // variant } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(VARIANT_WATCHER, (int) getMyPet().getVariant().getId()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(VARIANT_WATCHER, (int) getMyPet().getVariant().getId()); } @Override @@ -115,14 +111,14 @@ public void onLivingUpdate() { Bukkit.getConsoleSender().sendMessage("Normal: "+m.getName()+" "+m.getReturnType()); }*/ - //if (this.z && getNavigation().k() != null && jumpDelay-- <= 0) { //TODO Figure out k() and getPath() (Spigot and Paper) - if (this.z && jumpDelay-- <= 0) { - getControllerJump().jump(); - jumpDelay = (this.Q.nextInt(10) + 10); + //if (this.onGround && getNavigation().k() != null && jumpDelay-- <= 0) { //TODO Figure out k() and getPath() (Spigot and Paper) + if (this.onGround && jumpDelay-- <= 0) { + getJumpControl().jump(); + jumpDelay = (this.random.nextInt(10) + 10); if (getTarget() != null) { jumpDelay /= 3; } - this.t.broadcastEntityEffect(this, (byte) 1); + this.level.broadcastEntityEvent(this, (byte) 1); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyRavager.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyRavager.java index 1f1541b8f7..718aab35d1 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyRavager.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyRavager.java @@ -26,26 +26,26 @@ import de.Keyle.MyPet.api.entity.types.MyRavager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.skill.skills.RideImpl; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 1.95F, height = 2.2F) public class EntityMyRavager extends EntityMyPet { - protected static final DataWatcherObject RAID_WATCHER = DataWatcher.a(EntityMyRavager.class, DataWatcherRegistry.i); + protected static final EntityDataAccessor RAID_WATCHER = SynchedEntityData.defineId(EntityMyRavager.class, EntityDataSerializers.BOOLEAN); - public EntityMyRavager(World world, MyPet myPet) { + public EntityMyRavager(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.ravager.death"; } @@ -60,9 +60,9 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(RAID_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(RAID_WATCHER, false); } @@ -72,11 +72,11 @@ public void playPetStepSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) { if (myPet.getSkills().isActive(RideImpl.class) && canMove()) { getOwner().sendMessage("Unfortunately, Ravagers can not be ridden (Minecraft limitation)", 5000); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } return super.handlePlayerInteraction(entityhuman, enumhand, itemStack); diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySalmon.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySalmon.java index 607dae32cb..e1e235b5d3 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySalmon.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySalmon.java @@ -25,22 +25,22 @@ import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 0.4f) public class EntityMySalmon extends EntityMyPet { - private static final DataWatcherObject FROM_BUCKET_WATCHER = DataWatcher.a(EntityMySalmon.class, DataWatcherRegistry.i); + private static final EntityDataAccessor FROM_BUCKET_WATCHER = SynchedEntityData.defineId(EntityMySalmon.class, EntityDataSerializers.BOOLEAN); - public EntityMySalmon(World world, MyPet myPet) { + public EntityMySalmon(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.salmon.death"; } @@ -57,14 +57,14 @@ protected String getLivingSound() { @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (!isInWater() && this.Q.nextBoolean()) { + if (!isInWater() && this.random.nextBoolean()) { MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, 0.7, 0), ParticleCompat.WATER_SPLASH.get(), 0.2F, 0.2F, 0.2F, 0.5F, 10, 20); } } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(FROM_BUCKET_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(FROM_BUCKET_WATCHER, false); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySheep.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySheep.java index b54f735af8..314675bddf 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySheep.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySheep.java @@ -20,67 +20,65 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MySheep; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.movement.EatGrass; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.EnumColor; -import net.minecraft.world.item.ItemDye; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.DyeItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; -import org.bukkit.DyeColor; - -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; @EntitySize(width = 0.7F, height = 1.2349999f) public class EntityMySheep extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMySheep.class, DataWatcherRegistry.i); - private static final DataWatcherObject COLOR_WATCHER = DataWatcher.a(EntityMySheep.class, DataWatcherRegistry.a); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMySheep.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor COLOR_WATCHER = SynchedEntityData.defineId(EntityMySheep.class, EntityDataSerializers.BYTE); - private static final Map colorMap = new HashMap<>(); + private static final Map colorMap = new HashMap<>(); static { - colorMap.put(EnumColor.a, Blocks.be); - colorMap.put(EnumColor.b, Blocks.bf); - colorMap.put(EnumColor.c, Blocks.bg); - colorMap.put(EnumColor.d, Blocks.bh); - colorMap.put(EnumColor.e, Blocks.bi); - colorMap.put(EnumColor.f, Blocks.bj); - colorMap.put(EnumColor.g, Blocks.bk); - colorMap.put(EnumColor.h, Blocks.bl); - colorMap.put(EnumColor.i, Blocks.bm); - colorMap.put(EnumColor.j, Blocks.bn); - colorMap.put(EnumColor.k, Blocks.bo); - colorMap.put(EnumColor.l, Blocks.bp); - colorMap.put(EnumColor.m, Blocks.bq); - colorMap.put(EnumColor.n, Blocks.br); - colorMap.put(EnumColor.o, Blocks.bs); - colorMap.put(EnumColor.p, Blocks.bt); + colorMap.put(DyeColor.WHITE, Blocks.WHITE_WOOL); + colorMap.put(DyeColor.ORANGE, Blocks.ORANGE_WOOL); + colorMap.put(DyeColor.MAGENTA, Blocks.MAGENTA_WOOL); + colorMap.put(DyeColor.LIGHT_BLUE, Blocks.LIGHT_BLUE_WOOL); + colorMap.put(DyeColor.YELLOW, Blocks.YELLOW_WOOL); + colorMap.put(DyeColor.LIME, Blocks.LIME_WOOL); + colorMap.put(DyeColor.PINK, Blocks.PINK_WOOL); + colorMap.put(DyeColor.GRAY, Blocks.GRAY_WOOL); + colorMap.put(DyeColor.LIGHT_GRAY, Blocks.LIGHT_GRAY_WOOL); + colorMap.put(DyeColor.CYAN, Blocks.CYAN_WOOL); + colorMap.put(DyeColor.PURPLE, Blocks.PURPLE_WOOL); + colorMap.put(DyeColor.BLUE, Blocks.BLUE_WOOL); + colorMap.put(DyeColor.BROWN, Blocks.BROWN_WOOL); + colorMap.put(DyeColor.GREEN, Blocks.GREEN_WOOL); + colorMap.put(DyeColor.RED, Blocks.RED_WOOL); + colorMap.put(DyeColor.BLACK, Blocks.BLACK_WOOL); } - public EntityMySheep(World world, MyPet myPet) { + public EntityMySheep(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.sheep.death"; } @@ -95,74 +93,74 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() instanceof ItemDye && ((ItemDye) itemStack.getItem()).d().ordinal() != getMyPet().getColor().ordinal() && !getMyPet().isSheared()) { - getMyPet().setColor(DyeColor.values()[((ItemDye) itemStack.getItem()).d().ordinal()]); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack.getItem() instanceof DyeItem && ((DyeItem) itemStack.getItem()).getDyeColor().ordinal() != getMyPet().getColor().ordinal() && !getMyPet().isSheared()) { + getMyPet().setColor(org.bukkit.DyeColor.values()[((DyeItem) itemStack.getItem()).getDyeColor().ordinal()]); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && Configuration.MyPet.Sheep.CAN_BE_SHEARED && !getMyPet().isSheared()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && Configuration.MyPet.Sheep.CAN_BE_SHEARED && !getMyPet().isSheared()) { getMyPet().setSheared(true); - int woolDropCount = 1 + this.Q.nextInt(3); + int woolDropCount = 1 + this.random.nextInt(3); for (int j = 0; j < woolDropCount; ++j) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), new ItemStack(colorMap.get(EnumColor.values()[getMyPet().getColor().ordinal()]))); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), new ItemStack(colorMap.get(DyeColor.values()[getMyPet().getColor().ordinal()]))); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } makeSound("entity.sheep.shear", 1.0F, 1.0F); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } }); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Sheep.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(COLOR_WATCHER, (byte) 0); // color/sheared + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(COLOR_WATCHER, (byte) 0); // color/sheared } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); byte data = (byte) (getMyPet().isSheared() ? 16 : 0); - this.getDataWatcher().set(COLOR_WATCHER, (byte) (data & 0xF0 | getMyPet().getColor().ordinal() & 0xF)); + this.getEntityData().set(COLOR_WATCHER, (byte) (data & 0xF0 | getMyPet().getColor().ordinal() & 0xF)); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySilverfish.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySilverfish.java index ebc08a0b06..90ce54725d 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySilverfish.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySilverfish.java @@ -23,17 +23,17 @@ import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.4F, height = 0.1F) public class EntityMySilverfish extends EntityMyPet { - public EntityMySilverfish(World world, MyPet myPet) { + public EntityMySilverfish(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.silverfish.death"; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySkeleton.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySkeleton.java index c5bb869b2b..f8b1a417ab 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySkeleton.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySkeleton.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EntitySize; @@ -28,35 +35,28 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPet.PetState; import de.Keyle.MyPet.api.entity.types.MySkeleton; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMySkeleton extends EntityMyPet { - public EntityMySkeleton(World world, MyPet myPet) { + public EntityMySkeleton(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { if (getMyPet().isStray()) { return "entity.stray.death"; } else if (getMyPet().isWither()) { @@ -86,34 +86,34 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -121,27 +121,27 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override @@ -172,17 +172,17 @@ public MySkeleton getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySkeletonHorse.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySkeletonHorse.java index 912dabd421..b120002147 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySkeletonHorse.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySkeletonHorse.java @@ -20,47 +20,47 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MySkeletonHorse; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.BlockPosition; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.sounds.SoundEffects; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.core.BlockPos; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.IJumpable; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.PlayerRideableJumping; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SoundEffectType; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Optional; -import java.util.UUID; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; @EntitySize(width = 1.4F, height = 1.6F) -public class EntityMySkeletonHorse extends EntityMyPet implements IJumpable { +public class EntityMySkeletonHorse extends EntityMyPet implements PlayerRideableJumping { - protected static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMySkeletonHorse.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SADDLE_CHEST_WATCHER = DataWatcher.a(EntityMySkeletonHorse.class, DataWatcherRegistry.a); - protected static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMySkeletonHorse.class, DataWatcherRegistry.o); + protected static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMySkeletonHorse.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SADDLE_CHEST_WATCHER = SynchedEntityData.defineId(EntityMySkeletonHorse.class, EntityDataSerializers.BYTE); + protected static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMySkeletonHorse.class, EntityDataSerializers.OPTIONAL_UUID); int soundCounter = 0; int rearCounter = -1; - public EntityMySkeletonHorse(World world, MyPet myPet) { + public EntityMySkeletonHorse(Level world, MyPet myPet) { super(world, myPet); } @@ -73,11 +73,11 @@ public EntityMySkeletonHorse(World world, MyPet myPet) { * 128 mouth open */ protected void applyVisual(int value, boolean flag) { - int i = getDataWatcher().get(SADDLE_CHEST_WATCHER); + int i = getEntityData().get(SADDLE_CHEST_WATCHER); if (flag) { - this.getDataWatcher().set(SADDLE_CHEST_WATCHER, (byte) (i | value)); + this.getEntityData().set(SADDLE_CHEST_WATCHER, (byte) (i | value)); } else { - this.getDataWatcher().set(SADDLE_CHEST_WATCHER, (byte) (i & (~value))); + this.getEntityData().set(SADDLE_CHEST_WATCHER, (byte) (i & (~value))); } } @@ -97,7 +97,7 @@ public boolean attack(Entity entity) { } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.skeleton_horse.death"; } @@ -113,39 +113,39 @@ protected String getLivingSound() { @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.lL && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { if (getMyPet().hasSaddle()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setSaddle(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -153,32 +153,32 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.SkeletonHorse.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SADDLE_CHEST_WATCHER, (byte) 0); - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SADDLE_CHEST_WATCHER, (byte) 0); + getEntityData().define(OWNER_WATCHER, Optional.empty()); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); applyVisual(4, getMyPet().hasSaddle()); } @@ -202,25 +202,25 @@ public void onLivingUpdate() { } @Override - public void playStepSound(BlockPosition blockposition, IBlockData blockdata) { + public void playStepSound(BlockPos blockposition, BlockState blockdata) { if (!blockdata.getMaterial().isLiquid()) { - IBlockData blockdataUp = this.t.getType(blockposition.up()); - SoundEffectType soundeffecttype = blockdata.getStepSound(); - if (blockdataUp.getBlock() == Blocks.cK) { - soundeffecttype = blockdata.getStepSound(); + BlockState blockdataUp = this.level.getBlockState(blockposition.up()); + SoundType soundeffecttype = blockdata.getSoundType(); + if (blockdataUp.getBlock() == Blocks.SNOW) { + soundeffecttype = blockdata.getSoundType(); } if (this.isVehicle()) { ++this.soundCounter; if (this.soundCounter > 5 && this.soundCounter % 3 == 0) { - this.playSound(SoundEffects.iB, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_GALLOP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } else if (this.soundCounter <= 5) { - this.playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } } else if (!blockdata.getMaterial().isLiquid()) { this.soundCounter += 1; - playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } else { - playSound(SoundEffects.iG, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } } } @@ -231,22 +231,22 @@ public MySkeletonHorse getMyPet() { } @Override - public void a(int i) { - // I don't know. + public void onPlayerJump(int i) { + // I don't know. <- this was here before the remap } /* Jump power methods */ @Override - public boolean a() { + public boolean canJump() { return true; } @Override - public void b(int i) { + public void handleStartJump(int i) { this.jumpPower = i; } @Override - public void b() { + public void handleStopJump() { } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySlime.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySlime.java index fe5647e356..faee19996f 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySlime.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySlime.java @@ -25,26 +25,26 @@ import de.Keyle.MyPet.api.entity.types.MySlime; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.ai.attack.MeleeAttack; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.entity.EntityPose; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.Pose; +import net.minecraft.world.level.Level; @EntitySize(width = 0.51F, height = 0.51F) public class EntityMySlime extends EntityMyPet { - private static final DataWatcherObject SIZE_WATCHER = DataWatcher.a(EntityMySlime.class, DataWatcherRegistry.b); + private static final EntityDataAccessor SIZE_WATCHER = SynchedEntityData.defineId(EntityMySlime.class, EntityDataSerializers.INT); int jumpDelay; - public EntityMySlime(World world, MyPet myPet) { + public EntityMySlime(Level world, MyPet myPet) { super(world, myPet); - this.jumpDelay = (this.Q.nextInt(20) + 10); + this.jumpDelay = (this.random.nextInt(20) + 10); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.slime.death"; } @@ -60,41 +60,41 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(SIZE_WATCHER, 1); //size + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(SIZE_WATCHER, 1); //size } @Override public void updateVisuals() { int size = Math.max(1, getMyPet().getSize()); - getDataWatcher().set(SIZE_WATCHER, size); - this.updateSize(); + getEntityData().set(SIZE_WATCHER, size); + this.refreshDimensions(); if (petPathfinderSelector != null && petPathfinderSelector.hasGoal("MeleeAttack")) { petPathfinderSelector.replaceGoal("MeleeAttack", new MeleeAttack(this, 0.1F, 3 + (getMyPet().getSize() * 0.51), 20)); } } @Override - public net.minecraft.world.entity.EntitySize a(EntityPose entitypose) { + public net.minecraft.world.entity.EntityDimensions getDimensions(Pose entitypose) { EntitySize es = this.getClass().getAnnotation(EntitySize.class); if (es != null) { int size = Math.max(1, getMyPet().getSize()); float width = es.width(); float height = Float.isNaN(es.height()) ? width : es.height(); - return new net.minecraft.world.entity.EntitySize(width * size, height * size, false); + return new net.minecraft.world.entity.EntityDimensions(width * size, height * size, false); } - return super.a(entitypose); + return super.getDimensions(entitypose); } @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (this.z && jumpDelay-- <= 0) { - getControllerJump().jump(); - jumpDelay = (this.Q.nextInt(20) + 50); - makeSound("entity.slime.jump", 1.0F, ((this.Q.nextFloat() - this.Q.nextFloat()) * 0.2F + 1.0F) / 0.8F); + if (this.onGround && jumpDelay-- <= 0) { + getJumpControl().jump(); + jumpDelay = (this.random.nextInt(20) + 50); + makeSound("entity.slime.jump", 1.0F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySnowman.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySnowman.java index 77d0ab00f8..fc50b7073f 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySnowman.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySnowman.java @@ -20,88 +20,87 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; + import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MySnowman; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import java.lang.reflect.InvocationTargetException; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; - @EntitySize(width = 0.7F, height = 1.7F) public class EntityMySnowman extends EntityMyPet { - private static final DataWatcherObject SHEARED_WATCHER = DataWatcher.a(EntityMySnowman.class, DataWatcherRegistry.a); + private static final EntityDataAccessor SHEARED_WATCHER = SynchedEntityData.defineId(EntityMySnowman.class, EntityDataSerializers.BYTE); - public EntityMySnowman(World world, MyPet myPet) { + public EntityMySnowman(Level world, MyPet myPet) { super(world, myPet); } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Item.getItemOf(Blocks.cS) && getMyPet().isSheared() && entityhuman.isSneaking()) { + if (itemStack.getItem() == Item.byBlock(Blocks.PUMPKIN) && getMyPet().isSheared() && entityhuman.isShiftKeyDown()) { getMyPet().setSheared(false); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && !getMyPet().isSheared() && entityhuman.isSneaking()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && !getMyPet().isSheared() && entityhuman.isShiftKeyDown()) { getMyPet().setSheared(true); makeSound("entity.sheep.shear", 1.0F, 1.0F); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } }); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override public void updateVisuals() { - getDataWatcher().set(SHEARED_WATCHER, (byte) (getMyPet().isSheared() ? 0 : 16)); + getEntityData().set(SHEARED_WATCHER, (byte) (getMyPet().isSheared() ? 0 : 16)); } @Override - protected void initDatawatcher() { - super.initDatawatcher(); + protected void defineSynchedData() { + super.defineSynchedData(); - getDataWatcher().register(SHEARED_WATCHER, (byte) 16); + getEntityData().define(SHEARED_WATCHER, (byte) 16); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.snow_golem.death"; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySpider.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySpider.java index f5abb83f4e..0a5a1e6f3e 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySpider.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySpider.java @@ -23,17 +23,17 @@ import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 1.4F, height = 0.9F) public class EntityMySpider extends EntityMyPet { - public EntityMySpider(World world, MyPet myPet) { + public EntityMySpider(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.spider.death"; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySquid.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySquid.java index 3bf0a83a71..96dbe34927 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySquid.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMySquid.java @@ -25,17 +25,17 @@ import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 0.475f) public class EntityMySquid extends EntityMyPet { - public EntityMySquid(World world, MyPet myPet) { + public EntityMySquid(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.squid.death"; } @@ -52,7 +52,7 @@ protected String getLivingSound() { @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (!isInWater() && this.Q.nextBoolean()) { + if (!isInWater() && this.random.nextBoolean()) { MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, 0.7, 0), ParticleCompat.WATER_SPLASH.get(), 0.2F, 0.2F, 0.2F, 0.5F, 10, 20); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyStray.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyStray.java index 02705688cc..828db1bf70 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyStray.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyStray.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EntitySize; @@ -28,35 +35,28 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPet.PetState; import de.Keyle.MyPet.api.entity.types.MyStray; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyStray extends EntityMyPet { - public EntityMyStray(World world, MyPet myPet) { + public EntityMyStray(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.stray.death"; } @@ -71,34 +71,34 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -106,28 +106,28 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override @@ -152,17 +152,17 @@ public MyStray getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyStrider.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyStrider.java index 7b0f55b198..61ee724c8d 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyStrider.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyStrider.java @@ -20,41 +20,41 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyStrider; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.9F, height = 1.7F) public class EntityMyStrider extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyStrider.class, DataWatcherRegistry.i); - private static final DataWatcherObject BOOST_TICKS_WATCHER = DataWatcher.a(EntityMyStrider.class, DataWatcherRegistry.b); - private static final DataWatcherObject HAS_RIDER_WATCHER = DataWatcher.a(EntityMyStrider.class, DataWatcherRegistry.i); - private static final DataWatcherObject SADDLE_WATCHER = DataWatcher.a(EntityMyStrider.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyStrider.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor BOOST_TICKS_WATCHER = SynchedEntityData.defineId(EntityMyStrider.class, EntityDataSerializers.INT); + private static final EntityDataAccessor HAS_RIDER_WATCHER = SynchedEntityData.defineId(EntityMyStrider.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor SADDLE_WATCHER = SynchedEntityData.defineId(EntityMyStrider.class, EntityDataSerializers.BOOLEAN); - public EntityMyStrider(World world, MyPet myPet) { + public EntityMyStrider(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.strider.death"; } @@ -69,37 +69,37 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(final Player entityhuman, InteractionHand enumhand, final ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.lL && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { + if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setSaddle(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -107,34 +107,34 @@ public EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhum } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Strider.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(BOOST_TICKS_WATCHER, 0); - getDataWatcher().register(HAS_RIDER_WATCHER, false); - getDataWatcher().register(SADDLE_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(BOOST_TICKS_WATCHER, 0); + getEntityData().define(HAS_RIDER_WATCHER, false); + getEntityData().define(SADDLE_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); - this.getDataWatcher().set(SADDLE_WATCHER, getMyPet().hasSaddle()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(SADDLE_WATCHER, getMyPet().hasSaddle()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTraderLlama.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTraderLlama.java index dd561a64d9..1755bd2aea 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTraderLlama.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTraderLlama.java @@ -20,50 +20,50 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyTraderLlama; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.tags.TagsItem; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.tags.ItemTags; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BlockCarpet; import net.minecraft.world.level.block.Blocks; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Optional; -import java.util.UUID; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.block.WoolCarpetBlock; @EntitySize(width = 0.9F, height = 1.87F) public class EntityMyTraderLlama extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyTraderLlama.class, DataWatcherRegistry.i); - private static final DataWatcherObject SADDLE_CHEST_WATCHER = DataWatcher.a(EntityMyTraderLlama.class, DataWatcherRegistry.a); - private static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyTraderLlama.class, DataWatcherRegistry.o); - private static final DataWatcherObject CHEST_WATCHER = DataWatcher.a(EntityMyTraderLlama.class, DataWatcherRegistry.i); - private static final DataWatcherObject STRENGTH_WATCHER = DataWatcher.a(EntityMyTraderLlama.class, DataWatcherRegistry.b); - private static final DataWatcherObject COLOR_WATCHER = DataWatcher.a(EntityMyTraderLlama.class, DataWatcherRegistry.b); - private static final DataWatcherObject VARIANT_WATCHER = DataWatcher.a(EntityMyTraderLlama.class, DataWatcherRegistry.b); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor SADDLE_CHEST_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.OPTIONAL_UUID); + private static final EntityDataAccessor CHEST_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor STRENGTH_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT); + private static final EntityDataAccessor COLOR_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT); + private static final EntityDataAccessor VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyTraderLlama.class, EntityDataSerializers.INT); - public EntityMyTraderLlama(World world, MyPet myPet) { + public EntityMyTraderLlama(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.llama.death"; } @@ -79,55 +79,55 @@ protected String getLivingSound() { @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (itemStack != null && canUseItem()) { - if (TagsItem.g.isTagged(itemStack.getItem()) && !getMyPet().hasDecor() && getOwner().getPlayer().isSneaking() && canEquip()) { + if (ItemTags.CARPETS.contains(itemStack.getItem()) && !getMyPet().hasDecor() && getOwner().getPlayer().isSneaking() && canEquip()) { getMyPet().setDecor(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Blocks.bX.getItem() && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && !getMyPet().isBaby() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Blocks.CHEST.asItem() && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && !getMyPet().isBaby() && canEquip()) { getMyPet().setChest(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { if (getMyPet().hasChest()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } if (getMyPet().hasDecor()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getDecor())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getDecor())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setChest(null); getMyPet().setDecor(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -135,46 +135,46 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Llama.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SADDLE_CHEST_WATCHER, (byte) 0); // saddle & chest - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); // owner - getDataWatcher().register(CHEST_WATCHER, true); - getDataWatcher().register(STRENGTH_WATCHER, 0); - getDataWatcher().register(COLOR_WATCHER, 0); - getDataWatcher().register(VARIANT_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SADDLE_CHEST_WATCHER, (byte) 0); // saddle & chest + getEntityData().define(OWNER_WATCHER, Optional.empty()); // owner + getEntityData().define(CHEST_WATCHER, true); + getEntityData().define(STRENGTH_WATCHER, 0); + getEntityData().define(COLOR_WATCHER, 0); + getEntityData().define(VARIANT_WATCHER, 0); } @Override public void updateVisuals() { - this.getDataWatcher().set(CHEST_WATCHER, getMyPet().hasChest()); - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); if (getMyPet().hasDecor()) { ItemStack is = CraftItemStack.asNMSCopy(getMyPet().getDecor()); - Block block = Block.asBlock(is.getItem()); - int color = block instanceof BlockCarpet ? ((BlockCarpet) block).c().getColorIndex() : 0; - this.getDataWatcher().set(COLOR_WATCHER, color); + Block block = Block.byItem(is.getItem()); + int color = block instanceof WoolCarpetBlock ? ((WoolCarpetBlock) block).getColor().getId() : 0; + this.getEntityData().set(COLOR_WATCHER, color); } else { - this.getDataWatcher().set(COLOR_WATCHER, -1); + this.getEntityData().set(COLOR_WATCHER, -1); } - this.getDataWatcher().set(VARIANT_WATCHER, getMyPet().getVariant()); + this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTropicalFish.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTropicalFish.java index a13f1946ae..537729d497 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTropicalFish.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTropicalFish.java @@ -26,23 +26,23 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyTropicalFish; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.5F, height = 0.4f) public class EntityMyTropicalFish extends EntityMyPet { - private static final DataWatcherObject FROM_BUCKET_WATCHER = DataWatcher.a(EntityMyTropicalFish.class, DataWatcherRegistry.i); - private static final DataWatcherObject VARIANT_WATCHER = DataWatcher.a(EntityMyTropicalFish.class, DataWatcherRegistry.b); + private static final EntityDataAccessor FROM_BUCKET_WATCHER = SynchedEntityData.defineId(EntityMyTropicalFish.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor VARIANT_WATCHER = SynchedEntityData.defineId(EntityMyTropicalFish.class, EntityDataSerializers.INT); - public EntityMyTropicalFish(World world, MyPet myPet) { + public EntityMyTropicalFish(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.tropical_fish.death"; } @@ -59,7 +59,7 @@ protected String getLivingSound() { @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (!isInWater() && this.Q.nextBoolean()) { + if (!isInWater() && this.random.nextBoolean()) { MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, 0.7, 0), ParticleCompat.WATER_SPLASH.get(), 0.2F, 0.2F, 0.2F, 0.5F, 10, 20); } } @@ -71,13 +71,13 @@ public MyTropicalFish getMyPet() { @Override public void updateVisuals() { - getDataWatcher().set(VARIANT_WATCHER, getMyPet().getVariant()); + getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant()); } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(FROM_BUCKET_WATCHER, false); - getDataWatcher().register(VARIANT_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(FROM_BUCKET_WATCHER, false); + getEntityData().define(VARIANT_WATCHER, 0); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTurtle.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTurtle.java index ba2c130f02..2a2ce3065d 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTurtle.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyTurtle.java @@ -25,33 +25,33 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyTurtle; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.BlockPosition; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.core.BlockPos; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 1.2F, height = 0.4F) public class EntityMyTurtle extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyTurtle.class, DataWatcherRegistry.i); - private static final DataWatcherObject HOME_WATCHER = DataWatcher.a(EntityMyTurtle.class, DataWatcherRegistry.l); - private static final DataWatcherObject HAS_EGG_WATCHER = DataWatcher.a(EntityMyTurtle.class, DataWatcherRegistry.i); - private static final DataWatcherObject UNUSED_WATCHER_1 = DataWatcher.a(EntityMyTurtle.class, DataWatcherRegistry.i); - private static final DataWatcherObject TRAVEL_POS_WATCHER = DataWatcher.a(EntityMyTurtle.class, DataWatcherRegistry.l); - private static final DataWatcherObject UNUSED_WATCHER_2 = DataWatcher.a(EntityMyTurtle.class, DataWatcherRegistry.i); - private static final DataWatcherObject UNUSED_WATCHER_3 = DataWatcher.a(EntityMyTurtle.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyTurtle.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor HOME_WATCHER = SynchedEntityData.defineId(EntityMyTurtle.class, EntityDataSerializers.BLOCK_POS); + private static final EntityDataAccessor HAS_EGG_WATCHER = SynchedEntityData.defineId(EntityMyTurtle.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor UNUSED_WATCHER_1 = SynchedEntityData.defineId(EntityMyTurtle.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor TRAVEL_POS_WATCHER = SynchedEntityData.defineId(EntityMyTurtle.class, EntityDataSerializers.BLOCK_POS); + private static final EntityDataAccessor UNUSED_WATCHER_2 = SynchedEntityData.defineId(EntityMyTurtle.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor UNUSED_WATCHER_3 = SynchedEntityData.defineId(EntityMyTurtle.class, EntityDataSerializers.BOOLEAN); - public EntityMyTurtle(World world, MyPet myPet) { + public EntityMyTurtle(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.turtle.death" + (isBaby() ? "_baby" : ""); } @@ -66,41 +66,41 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (Configuration.MyPet.Cow.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(HOME_WATCHER, BlockPosition.b); - getDataWatcher().register(HAS_EGG_WATCHER, false); - getDataWatcher().register(TRAVEL_POS_WATCHER, BlockPosition.b); - getDataWatcher().register(UNUSED_WATCHER_2, false); - getDataWatcher().register(UNUSED_WATCHER_3, false); - getDataWatcher().register(UNUSED_WATCHER_1, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(HOME_WATCHER, BlockPos.ZERO); + getEntityData().define(HAS_EGG_WATCHER, false); + getEntityData().define(TRAVEL_POS_WATCHER, BlockPos.ZERO); + getEntityData().define(UNUSED_WATCHER_2, false); + getEntityData().define(UNUSED_WATCHER_3, false); + getEntityData().define(UNUSED_WATCHER_1, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVex.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVex.java index 67ac76aca5..06268c1ac6 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVex.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVex.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -29,38 +36,31 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyVex; import de.Keyle.MyPet.api.skill.skills.Behavior; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.skill.skills.BehaviorImpl; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.4F, height = 0.8F) public class EntityMyVex extends EntityMyPet { - protected static final DataWatcherObject CHARGING_WATCHER = DataWatcher.a(EntityMyVex.class, DataWatcherRegistry.a); + protected static final EntityDataAccessor CHARGING_WATCHER = SynchedEntityData.defineId(EntityMyVex.class, EntityDataSerializers.BYTE); protected boolean isAggressive = false; - public EntityMyVex(World world, MyPet myPet) { + public EntityMyVex(Level world, MyPet myPet) { super(world, myPet); } @@ -68,7 +68,7 @@ public EntityMyVex(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.vex.death"; } @@ -95,34 +95,34 @@ protected String getLivingSound() { * false: no reaction on rightclick */ @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -130,40 +130,40 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); if (slot == EquipmentSlot.MainHand) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(CHARGING_WATCHER, (byte) 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(CHARGING_WATCHER, (byte) 0); } @Override public void updateVisuals() { - getDataWatcher().set(CHARGING_WATCHER, (byte) (getMyPet().isGlowing() || isAggressive ? 1 : 0)); + getEntityData().set(CHARGING_WATCHER, (byte) (getMyPet().isGlowing() || isAggressive ? 1 : 0)); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { @@ -178,26 +178,26 @@ public MyVex getMyPet() { } public void setPetEquipment(ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.a, itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.MAINHAND, itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } @Override public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Vex.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } } @@ -224,9 +224,9 @@ protected void doMyPetTick() { * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Vex.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVillager.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVillager.java index 2fce7c78d5..7a0da6d3a6 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVillager.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVillager.java @@ -20,39 +20,41 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import com.comphenix.protocol.wrappers.MinecraftKey; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyVillager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.IRegistry; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.core.Registry; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.npc.VillagerData; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.entity.npc.VillagerType; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyVillager extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyVillager.class, DataWatcherRegistry.i); - private static final DataWatcherObject UNUSED_WATCHER = DataWatcher.a(EntityMyVillager.class, DataWatcherRegistry.b); - private static final DataWatcherObject PROFESSION_WATCHER = DataWatcher.a(EntityMyVillager.class, DataWatcherRegistry.q); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyVillager.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor UNUSED_WATCHER = SynchedEntityData.defineId(EntityMyVillager.class, EntityDataSerializers.INT); + private static final EntityDataAccessor PROFESSION_WATCHER = SynchedEntityData.defineId(EntityMyVillager.class, EntityDataSerializers.VILLAGER_DATA); - public EntityMyVillager(World world, MyPet myPet) { + public EntityMyVillager(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.villager.death"; } @@ -67,43 +69,43 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (Configuration.MyPet.Villager.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); if (MyPetApi.getCompatUtil().isCompatible("1.14.1")) { - getDataWatcher().register(UNUSED_WATCHER, 0); + getEntityData().define(UNUSED_WATCHER, 0); } - getDataWatcher().register(PROFESSION_WATCHER, new VillagerData(VillagerType.c, VillagerProfession.a, 1)); + getEntityData().define(PROFESSION_WATCHER, new VillagerData(VillagerType.PLAINS, VillagerProfession.NONE, 1)); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); String professionKey = MyVillager.Profession.values()[getMyPet().getProfession()].getKey(); - VillagerProfession profession = IRegistry.ap.get(new MinecraftKey(professionKey)); - VillagerType type = IRegistry.ao.get(new MinecraftKey(getMyPet().getType().getKey())); - this.getDataWatcher().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getVillagerLevel())); + VillagerProfession profession = Registry.VILLAGER_PROFESSION.get(new ResourceLocation(professionKey)); + VillagerType type = Registry.VILLAGER_TYPE.get(new ResourceLocation(getMyPet().getType().getKey())); //TODO + this.getEntityData().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getVillagerLevel())); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVindicator.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVindicator.java index 8fa75a4f12..e8fbaa72ff 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVindicator.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyVindicator.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EntitySize; @@ -29,32 +36,26 @@ import de.Keyle.MyPet.api.entity.types.MyVindicator; import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.95F) public class EntityMyVindicator extends EntityMyPet { - protected static final DataWatcherObject RAID_WATCHER = DataWatcher.a(EntityMyVindicator.class, DataWatcherRegistry.i); + protected static final EntityDataAccessor RAID_WATCHER = SynchedEntityData.defineId(EntityMyVindicator.class, EntityDataSerializers.BOOLEAN); - public EntityMyVindicator(World world, MyPet myPet) { + public EntityMyVindicator(Level world, MyPet myPet) { super(world, myPet); } @@ -62,7 +63,7 @@ public EntityMyVindicator(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.vindicator.death"; } @@ -89,32 +90,32 @@ protected String getLivingSound() { * false: no reaction on rightclick */ @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { @@ -124,35 +125,35 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); if (slot == EquipmentSlot.MainHand) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(RAID_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(RAID_WATCHER, false); } @Override @@ -170,17 +171,17 @@ public MyVindicator getMyPet() { } public void setPetEquipment(ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.a, itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.MAINHAND, itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWanderingTrader.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWanderingTrader.java index 221003f38e..75c6ba821b 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWanderingTrader.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWanderingTrader.java @@ -25,22 +25,22 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyWanderingTrader; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyWanderingTrader extends EntityMyPet { - private static final DataWatcherObject UNUSED_WATCHER = DataWatcher.a(EntityMyWanderingTrader.class, DataWatcherRegistry.b); + private static final EntityDataAccessor UNUSED_WATCHER = SynchedEntityData.defineId(EntityMyWanderingTrader.class, EntityDataSerializers.INT); - public EntityMyWanderingTrader(World world, MyPet myPet) { + public EntityMyWanderingTrader(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.villager.death"; } @@ -55,10 +55,10 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); + protected void defineSynchedData() { + super.defineSynchedData(); if (MyPetApi.getCompatUtil().isCompatible("1.14.1")) { - getDataWatcher().register(UNUSED_WATCHER, 0); + getEntityData().define(UNUSED_WATCHER, 0); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWitch.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWitch.java index 04c10c44bc..d535368f3c 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWitch.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWitch.java @@ -23,17 +23,17 @@ import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.62F) public class EntityMyWitch extends EntityMyPet { - public EntityMyWitch(World world, MyPet myPet) { + public EntityMyWitch(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.witch.death"; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWither.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWither.java index c910f4df79..d8c826cc81 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWither.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWither.java @@ -25,25 +25,25 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyWither; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.level.World; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.level.Level; @EntitySize(width = 1.9F, height = 3.5F) public class EntityMyWither extends EntityMyPet { - private static final DataWatcherObject TARGET_WATCHER = DataWatcher.a(EntityMyWither.class, DataWatcherRegistry.b); - private static final DataWatcherObject UNUSED_WATCHER_1 = DataWatcher.a(EntityMyWither.class, DataWatcherRegistry.b); - private static final DataWatcherObject UNUSED_WATCHER_2 = DataWatcher.a(EntityMyWither.class, DataWatcherRegistry.b); - private static final DataWatcherObject INVULNERABILITY_WATCHER = DataWatcher.a(EntityMyWither.class, DataWatcherRegistry.b); + private static final EntityDataAccessor TARGET_WATCHER = SynchedEntityData.defineId(EntityMyWither.class, EntityDataSerializers.INT); + private static final EntityDataAccessor UNUSED_WATCHER_1 = SynchedEntityData.defineId(EntityMyWither.class, EntityDataSerializers.INT); + private static final EntityDataAccessor UNUSED_WATCHER_2 = SynchedEntityData.defineId(EntityMyWither.class, EntityDataSerializers.INT); + private static final EntityDataAccessor INVULNERABILITY_WATCHER = SynchedEntityData.defineId(EntityMyWither.class, EntityDataSerializers.INT); - public EntityMyWither(World world, MyPet myPet) { + public EntityMyWither(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.wither.death"; } @@ -58,36 +58,36 @@ protected String getLivingSound() { } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(TARGET_WATCHER, 0); - getDataWatcher().register(UNUSED_WATCHER_1, 0); - getDataWatcher().register(UNUSED_WATCHER_2, 0); - getDataWatcher().register(INVULNERABILITY_WATCHER, 0); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(TARGET_WATCHER, 0); + getEntityData().define(UNUSED_WATCHER_1, 0); + getEntityData().define(UNUSED_WATCHER_2, 0); + getEntityData().define(INVULNERABILITY_WATCHER, 0); } @Override public void onLivingUpdate() { super.onLivingUpdate(); if (Configuration.MyPet.Wither.CAN_GLIDE) { - if (!this.z && this.getMot().getY() < 0.0D) { - this.setMot(getMot().d(1, 0.6D, 1)); + if (!this.onGround && this.getDeltaMovement().y() < 0.0D) { + this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1)); } } } @Override public void updateVisuals() { - getDataWatcher().set(INVULNERABILITY_WATCHER, getMyPet().isBaby() ? 600 : 0); + getEntityData().set(INVULNERABILITY_WATCHER, getMyPet().isBaby() ? 600 : 0); } /** * -> disable falldamage */ @Override - public int d(float f, float f1) { + public int calculateFallDamage(float f, float f1) { if (!Configuration.MyPet.Wither.CAN_GLIDE) { - super.e(f, f1); + super.calculateFallDamage(f, f1); } return 0; } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWitherSkeleton.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWitherSkeleton.java index a3786fd002..a561a8b9c0 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWitherSkeleton.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWitherSkeleton.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EntitySize; @@ -28,35 +35,28 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPet.PetState; import de.Keyle.MyPet.api.entity.types.MyWitherSkeleton; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyWitherSkeleton extends EntityMyPet { - public EntityMyWitherSkeleton(World world, MyPet myPet) { + public EntityMyWitherSkeleton(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.wither_skeleton.death"; } @@ -71,34 +71,34 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -106,28 +106,28 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override @@ -152,17 +152,17 @@ public MyWitherSkeleton getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWolf.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWolf.java index 0c6dac12e8..bb55c535cf 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWolf.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyWolf.java @@ -20,58 +20,59 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.DyeColor; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyWolf; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.particles.Particles; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.util.MathHelper; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.ai.attributes.GenericAttributes; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.ItemDye; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.util.Mth; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.DyeItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.DyeColor; - -import java.util.Optional; -import java.util.UUID; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 0.64f) public class EntityMyWolf extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyWolf.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SIT_WATCHER = DataWatcher.a(EntityMyWolf.class, DataWatcherRegistry.a); - protected static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyWolf.class, DataWatcherRegistry.o); - private static final DataWatcherObject TAIL_WATCHER = DataWatcher.a(EntityMyWolf.class, DataWatcherRegistry.c); - private static final DataWatcherObject UNUSED_WATCHER = DataWatcher.a(EntityMyWolf.class, DataWatcherRegistry.i); - private static final DataWatcherObject COLLAR_COLOR_WATCHER = DataWatcher.a(EntityMyWolf.class, DataWatcherRegistry.b); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyWolf.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SIT_WATCHER = SynchedEntityData.defineId(EntityMyWolf.class, EntityDataSerializers.BYTE); + protected static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyWolf.class, EntityDataSerializers.OPTIONAL_UUID); + private static final EntityDataAccessor TAIL_WATCHER = SynchedEntityData.defineId(EntityMyWolf.class, EntityDataSerializers.FLOAT); + private static final EntityDataAccessor UNUSED_WATCHER = SynchedEntityData.defineId(EntityMyWolf.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor COLLAR_COLOR_WATCHER = SynchedEntityData.defineId(EntityMyWolf.class, EntityDataSerializers.INT); protected boolean shaking; protected boolean isWet; protected float shakeCounter; - public EntityMyWolf(World world, MyPet myPet) { + public EntityMyWolf(Level world, MyPet myPet) { super(world, myPet); } public void applySitting(boolean sitting) { - int i = this.getDataWatcher().get(SIT_WATCHER); + int i = this.getEntityData().get(SIT_WATCHER); if (sitting) { - this.getDataWatcher().set(SIT_WATCHER, (byte) (i | 0x1)); + this.getEntityData().set(SIT_WATCHER, (byte) (i | 0x1)); } else { - this.getDataWatcher().set(SIT_WATCHER, (byte) (i & 0xFFFFFFFE)); + this.getEntityData().set(SIT_WATCHER, (byte) (i & 0xFFFFFFFE)); } } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.wolf.death"; } @@ -82,93 +83,93 @@ protected String getHurtSound() { @Override protected String getLivingSound() { - return this.Q.nextInt(5) == 0 ? (getHealth() * 100 / getMaxHealth() <= 25 ? "entity.wolf.whine" : "entity.wolf.pant") : "entity.wolf.ambient"; + return this.random.nextInt(5) == 0 ? (getHealth() * 100 / getMaxHealth() <= 25 ? "entity.wolf.whine" : "entity.wolf.pant") : "entity.wolf.ambient"; } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman)) { - if (itemStack != null && itemStack.getItem() != Items.a) { + if (itemStack != null && itemStack.getItem() != Items.AIR) { if (canUseItem()) { - if (itemStack.getItem() instanceof ItemDye && ((ItemDye) itemStack.getItem()).d().ordinal() != getMyPet().getCollarColor().ordinal()) { + if (itemStack.getItem() instanceof DyeItem && ((DyeItem) itemStack.getItem()).getDyeColor().ordinal() != getMyPet().getCollarColor().ordinal()) { if (getOwner().getPlayer().isSneaking()) { - getMyPet().setCollarColor(DyeColor.values()[((ItemDye) itemStack.getItem()).d().ordinal()]); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + getMyPet().setCollarColor(DyeColor.values()[((DyeItem) itemStack.getItem()).getDyeColor().ordinal()]); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else { - this.getDataWatcher().set(COLLAR_COLOR_WATCHER, 0); + this.getEntityData().set(COLLAR_COLOR_WATCHER, 0); updateVisuals(); } } else if (Configuration.MyPet.Wolf.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SIT_WATCHER, (byte) 0); - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); - getDataWatcher().register(TAIL_WATCHER, 30F); - getDataWatcher().register(UNUSED_WATCHER, false); // not used - getDataWatcher().register(COLLAR_COLOR_WATCHER, 14); + protected void defineSynchedData() { + super.defineSynchedData(); + + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SIT_WATCHER, (byte) 0); + getEntityData().define(OWNER_WATCHER, Optional.empty()); + getEntityData().define(TAIL_WATCHER, 30F); + getEntityData().define(UNUSED_WATCHER, false); // not used + getEntityData().define(COLLAR_COLOR_WATCHER, 14); } @Override protected void initAttributes() { - getAttributeInstance(GenericAttributes.a).setValue(20.0D); + getAttribute(Attributes.MAX_HEALTH).setBaseValue(20.0D); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); - byte b0 = this.getDataWatcher().get(SIT_WATCHER); + byte b0 = this.getEntityData().get(SIT_WATCHER); if (getMyPet().isTamed()) { - this.getDataWatcher().set(SIT_WATCHER, (byte) (b0 | 0x4)); + this.getEntityData().set(SIT_WATCHER, (byte) (b0 | 0x4)); } else { - this.getDataWatcher().set(SIT_WATCHER, (byte) (b0 & 0xFFFFFFFB)); + this.getEntityData().set(SIT_WATCHER, (byte) (b0 & 0xFFFFFFFB)); } - b0 = this.getDataWatcher().get(SIT_WATCHER); + b0 = this.getEntityData().get(SIT_WATCHER); if (getMyPet().isAngry()) { - this.getDataWatcher().set(SIT_WATCHER, (byte) (b0 | 0x2)); + this.getEntityData().set(SIT_WATCHER, (byte) (b0 | 0x2)); } else { - this.getDataWatcher().set(SIT_WATCHER, (byte) (b0 & 0xFFFFFFFD)); + this.getEntityData().set(SIT_WATCHER, (byte) (b0 & 0xFFFFFFFD)); } - this.getDataWatcher().set(COLLAR_COLOR_WATCHER, getMyPet().getCollarColor().ordinal()); + this.getEntityData().set(COLLAR_COLOR_WATCHER, getMyPet().getCollarColor().ordinal()); } @Override public void onLivingUpdate() { super.onLivingUpdate(); - if (this.isWet && !this.shaking && this.z) { + if (this.isWet && !this.shaking && this.onGround) { this.shaking = true; this.shakeCounter = 0.0F; - this.t.broadcastEntityEffect(this, (byte) 8); + this.level.broadcastEntityEvent(this, (byte) 8); } if (isInWater()) // -> is in water @@ -178,7 +179,7 @@ public void onLivingUpdate() { this.shakeCounter = 0.0F; } else if ((this.isWet || this.shaking) && this.shaking) { if (this.shakeCounter == 0.0F) { - makeSound("entity.wolf.shake", 1.0F, (this.Q.nextFloat() - this.Q.nextFloat()) * 0.2F + 1.0F); + makeSound("entity.wolf.shake", 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); } this.shakeCounter += 0.05F; @@ -189,19 +190,19 @@ public void onLivingUpdate() { } if (this.shakeCounter > 0.4F) { - int i = (int) (MathHelper.sin((this.shakeCounter - 0.4F) * 3.141593F) * 7.0F); + int i = (int) (Mth.sin((this.shakeCounter - 0.4F) * 3.141593F) * 7.0F); for (; i >= 0; i--) { - float offsetX = (this.Q.nextFloat() * 2.0F - 1.0F) * this.getWidth() * 0.5F; - float offsetZ = (this.Q.nextFloat() * 2.0F - 1.0F) * this.getWidth() * 0.5F; + float offsetX = (this.random.nextFloat() * 2.0F - 1.0F) * this.getBbWidth() * 0.5F; + float offsetZ = (this.random.nextFloat() * 2.0F - 1.0F) * this.getBbWidth() * 0.5F; - this.t.addParticle(Particles.ac, this.locX() + offsetX, this.locY() + 0.8F, this.locZ() + offsetZ, this.getMot().getX(), this.getMot().getY(), this.getMot().getZ()); + this.level.addParticle(ParticleTypes.SPLASH, this.getX() + offsetX, this.getY() + 0.8F, this.getZ() + offsetZ, this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()); } } } float tailHeight = 30F * (getHealth() / getMaxHealth()); - if (this.getDataWatcher().get(TAIL_WATCHER) != tailHeight) { - this.getDataWatcher().set(TAIL_WATCHER, tailHeight); // update tail height + if (this.getEntityData().get(TAIL_WATCHER) != tailHeight) { + this.getEntityData().set(TAIL_WATCHER, tailHeight); // update tail height } } @@ -215,7 +216,7 @@ public void setHealth(float i) { super.setHealth(i); float tailHeight = 30F * (i / getMaxHealth()); - this.getDataWatcher().set(TAIL_WATCHER, tailHeight); + this.getEntityData().set(TAIL_WATCHER, tailHeight); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZoglin.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZoglin.java index 1a9c8cdd5f..4d32fdf9c0 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZoglin.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZoglin.java @@ -25,26 +25,26 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyZoglin; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @EntitySize(width = 1.3965F, height = 1.4F) public class EntityMyZoglin extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyZoglin.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyZoglin.class, EntityDataSerializers.BOOLEAN); - public EntityMyZoglin(World world, MyPet myPet) { + public EntityMyZoglin(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.zoglin.death"; } @@ -59,35 +59,35 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(final Player entityhuman, InteractionHand enumhand, final ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (Configuration.MyPet.Zoglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); } @Override diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombie.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombie.java index 008e56a800..a7a68a6b68 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombie.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombie.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -28,38 +35,31 @@ import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyZombie; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyZombie extends EntityMyPet { - private static final DataWatcherObject BABY_WATCHER = DataWatcher.a(EntityMyZombie.class, DataWatcherRegistry.i); - private static final DataWatcherObject TYPE_WATCHER = DataWatcher.a(EntityMyZombie.class, DataWatcherRegistry.b); - private static final DataWatcherObject DROWN_CONVERTING = DataWatcher.a(EntityMyZombie.class, DataWatcherRegistry.i); - private static final DataWatcherObject UNUSED_WATCHER_2 = DataWatcher.a(EntityMyZombie.class, DataWatcherRegistry.i); + private static final EntityDataAccessor BABY_WATCHER = SynchedEntityData.defineId(EntityMyZombie.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor TYPE_WATCHER = SynchedEntityData.defineId(EntityMyZombie.class, EntityDataSerializers.INT); + private static final EntityDataAccessor DROWN_CONVERTING = SynchedEntityData.defineId(EntityMyZombie.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor UNUSED_WATCHER_2 = SynchedEntityData.defineId(EntityMyZombie.class, EntityDataSerializers.BOOLEAN); - public EntityMyZombie(World world, MyPet myPet) { + public EntityMyZombie(Level world, MyPet myPet) { super(world, myPet); } @@ -67,7 +67,7 @@ public EntityMyZombie(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.zombie.death"; } @@ -94,34 +94,34 @@ protected String getLivingSound() { * false: no reaction on rightclick */ @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -129,49 +129,49 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Zombie.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(BABY_WATCHER, false); - getDataWatcher().register(TYPE_WATCHER, 0); - getDataWatcher().register(DROWN_CONVERTING, false); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(BABY_WATCHER, false); + getEntityData().define(TYPE_WATCHER, 0); + getEntityData().define(DROWN_CONVERTING, false); } @Override public void updateVisuals() { - getDataWatcher().set(BABY_WATCHER, getMyPet().isBaby()); + getEntityData().set(BABY_WATCHER, getMyPet().isBaby()); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { @@ -193,17 +193,17 @@ public MyZombie getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombieHorse.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombieHorse.java index fd2b061b82..3bffc2f60d 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombieHorse.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombieHorse.java @@ -20,47 +20,47 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; +import java.util.UUID; + +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyZombieHorse; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.BlockPosition; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.sounds.SoundEffects; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; +import net.minecraft.core.BlockPos; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.IJumpable; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.PlayerRideableJumping; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SoundEffectType; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Optional; -import java.util.UUID; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; @EntitySize(width = 1.4F, height = 1.6F) -public class EntityMyZombieHorse extends EntityMyPet implements IJumpable { +public class EntityMyZombieHorse extends EntityMyPet implements PlayerRideableJumping { - protected static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyZombieHorse.class, DataWatcherRegistry.i); - protected static final DataWatcherObject SADDLE_CHEST_WATCHER = DataWatcher.a(EntityMyZombieHorse.class, DataWatcherRegistry.a); - protected static final DataWatcherObject> OWNER_WATCHER = DataWatcher.a(EntityMyZombieHorse.class, DataWatcherRegistry.o); + protected static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyZombieHorse.class, EntityDataSerializers.BOOLEAN); + protected static final EntityDataAccessor SADDLE_CHEST_WATCHER = SynchedEntityData.defineId(EntityMyZombieHorse.class, EntityDataSerializers.BYTE); + protected static final EntityDataAccessor> OWNER_WATCHER = SynchedEntityData.defineId(EntityMyZombieHorse.class, EntityDataSerializers.OPTIONAL_UUID); int soundCounter = 0; int rearCounter = -1; - public EntityMyZombieHorse(World world, MyPet myPet) { + public EntityMyZombieHorse(Level world, MyPet myPet) { super(world, myPet); } @@ -73,11 +73,11 @@ public EntityMyZombieHorse(World world, MyPet myPet) { * 128 mouth open */ protected void applyVisual(int value, boolean flag) { - int i = this.getDataWatcher().get(SADDLE_CHEST_WATCHER); + int i = this.getEntityData().get(SADDLE_CHEST_WATCHER); if (flag) { - this.getDataWatcher().set(SADDLE_CHEST_WATCHER, (byte) (i | value)); + this.getEntityData().set(SADDLE_CHEST_WATCHER, (byte) (i | value)); } else { - this.getDataWatcher().set(SADDLE_CHEST_WATCHER, (byte) (i & (~value))); + this.getEntityData().set(SADDLE_CHEST_WATCHER, (byte) (i & (~value))); } } @@ -97,7 +97,7 @@ public boolean attack(Entity entity) { } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.zombie_horse.death"; } @@ -113,39 +113,39 @@ protected String getLivingSound() { @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.lL && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) { getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; - } else if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + return InteractionResult.CONSUME; + } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { if (getMyPet().hasSaddle()) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle())); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } makeSound("entity.sheep.shear", 1.0F, 1.0F); getMyPet().setSaddle(null); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -153,32 +153,32 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.ZombieHorse.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); - getDataWatcher().register(SADDLE_CHEST_WATCHER, (byte) 0); - getDataWatcher().register(OWNER_WATCHER, Optional.empty()); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); + getEntityData().define(SADDLE_CHEST_WATCHER, (byte) 0); + getEntityData().define(OWNER_WATCHER, Optional.empty()); } @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); applyVisual(4, getMyPet().hasSaddle()); } @@ -202,25 +202,25 @@ public void onLivingUpdate() { } @Override - public void playStepSound(BlockPosition blockposition, IBlockData blockdata) { + public void playStepSound(BlockPos blockposition, BlockState blockdata) { if (!blockdata.getMaterial().isLiquid()) { - IBlockData blockdataUp = this.t.getType(blockposition.up()); - SoundEffectType soundeffecttype = blockdata.getStepSound(); - if (blockdataUp.getBlock() == Blocks.cK) { - soundeffecttype = blockdata.getStepSound(); + BlockState blockdataUp = this.level.getBlockState(blockposition.up()); + SoundType soundeffecttype = blockdata.getSoundType(); + if (blockdataUp.getBlock() == Blocks.SNOW) { + soundeffecttype = blockdata.getSoundType(); } if (this.isVehicle()) { ++this.soundCounter; if (this.soundCounter > 5 && this.soundCounter % 3 == 0) { - this.playSound(SoundEffects.iB, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_GALLOP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } else if (this.soundCounter <= 5) { - this.playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + this.playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } } else if (!blockdata.getMaterial().isLiquid()) { this.soundCounter += 1; - playSound(SoundEffects.iH, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } else { - playSound(SoundEffects.iG, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); + playSound(SoundEvents.HORSE_STEP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch()); } } } @@ -231,22 +231,22 @@ public MyZombieHorse getMyPet() { } @Override - public void a(int i) { - // I don't know. + public void onPlayerJump(int i) { + // I don't know. <- this was here before the remap } /* Jump power methods */ @Override - public boolean a() { + public boolean canJump() { return true; } @Override - public void b(int i) { + public void handleStartJump(int i) { this.jumpPower = i; } @Override - public void b() { + public void handleStopJump() { } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombieVillager.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombieVillager.java index 53b5154b2b..5f5fe8a1df 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombieVillager.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombieVillager.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -29,44 +36,37 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyVillager; import de.Keyle.MyPet.api.entity.types.MyZombieVillager; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.core.IRegistry; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; +import net.minecraft.core.Registry; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.npc.VillagerData; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.entity.npc.VillagerType; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyZombieVillager extends EntityMyPet { - private static final DataWatcherObject BABY_WATCHER = DataWatcher.a(EntityMyZombieVillager.class, DataWatcherRegistry.i); - private static final DataWatcherObject TYPE_WATCHER = DataWatcher.a(EntityMyZombieVillager.class, DataWatcherRegistry.b); - private static final DataWatcherObject DROWN_CONVERTING = DataWatcher.a(EntityMyZombieVillager.class, DataWatcherRegistry.i); - private static final DataWatcherObject SHIVER_WATCHER = DataWatcher.a(EntityMyZombieVillager.class, DataWatcherRegistry.i); - private static final DataWatcherObject PROFESSION_WATCHER = DataWatcher.a(EntityMyZombieVillager.class, DataWatcherRegistry.q); + private static final EntityDataAccessor BABY_WATCHER = SynchedEntityData.defineId(EntityMyZombieVillager.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor TYPE_WATCHER = SynchedEntityData.defineId(EntityMyZombieVillager.class, EntityDataSerializers.INT); + private static final EntityDataAccessor DROWN_CONVERTING = SynchedEntityData.defineId(EntityMyZombieVillager.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor SHIVER_WATCHER = SynchedEntityData.defineId(EntityMyZombieVillager.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor PROFESSION_WATCHER = SynchedEntityData.defineId(EntityMyZombieVillager.class, EntityDataSerializers.VILLAGER_DATA); - public EntityMyZombieVillager(World world, MyPet myPet) { + public EntityMyZombieVillager(Level world, MyPet myPet) { super(world, myPet); } @@ -74,7 +74,7 @@ public EntityMyZombieVillager(World world, MyPet myPet) { * Returns the sound that is played when the MyPet dies */ @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.zombie.death"; } @@ -101,34 +101,34 @@ protected String getLivingSound() { * false: no reaction on rightclick */ @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -136,56 +136,56 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.Zombie.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(BABY_WATCHER, false); - getDataWatcher().register(TYPE_WATCHER, 0); - getDataWatcher().register(DROWN_CONVERTING, false); - getDataWatcher().register(SHIVER_WATCHER, false); - - getDataWatcher().register(PROFESSION_WATCHER, new VillagerData(VillagerType.c, VillagerProfession.a, 1)); + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(BABY_WATCHER, false); + getEntityData().define(TYPE_WATCHER, 0); + getEntityData().define(DROWN_CONVERTING, false); + getEntityData().define(SHIVER_WATCHER, false); + + getEntityData().define(PROFESSION_WATCHER, new VillagerData(VillagerType.PLAINS, VillagerProfession.NONE, 1)); } @Override public void updateVisuals() { - getDataWatcher().set(BABY_WATCHER, getMyPet().isBaby()); + getEntityData().set(BABY_WATCHER, getMyPet().isBaby()); String professionKey = MyVillager.Profession.values()[getMyPet().getProfession()].getKey(); - VillagerProfession profession = IRegistry.ap.get(new MinecraftKey(professionKey)); - VillagerType type = IRegistry.ao.get(new MinecraftKey(getMyPet().getType().getKey())); - getDataWatcher().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getTradingLevel())); + VillagerProfession profession = Registry.VILLAGER_PROFESSION.get(new ResourceLocation(professionKey)); + VillagerType type = Registry.VILLAGER_TYPE.get(new ResourceLocation(getMyPet().getType().getKey())); //TODO + getEntityData().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getTradingLevel())); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == MyPet.PetState.Here) { @@ -207,17 +207,17 @@ public MyZombieVillager getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombifiedPiglin.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombifiedPiglin.java index 6c6af926c2..d6c1b5e06f 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombifiedPiglin.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyZombifiedPiglin.java @@ -20,7 +20,14 @@ package de.Keyle.MyPet.compat.v1_17_R1.entity.types; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; + import com.mojang.datafixers.util.Pair; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; @@ -29,40 +36,33 @@ import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPet.PetState; import de.Keyle.MyPet.api.entity.types.MyZombifiedPiglin; +import de.Keyle.MyPet.compat.v1_17_R1.CompatManager; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; -import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.EnumHand; -import net.minecraft.world.EnumInteractionResult; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; - -import static de.Keyle.MyPet.compat.v1_17_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak; +import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 1.9F) public class EntityMyZombifiedPiglin extends EntityMyPet { - private static final DataWatcherObject AGE_WATCHER = DataWatcher.a(EntityMyZombifiedPiglin.class, DataWatcherRegistry.i); + private static final EntityDataAccessor AGE_WATCHER = SynchedEntityData.defineId(EntityMyZombifiedPiglin.class, EntityDataSerializers.BOOLEAN); - public EntityMyZombifiedPiglin(World world, MyPet myPet) { + public EntityMyZombifiedPiglin(Level world, MyPet myPet) { super(world, myPet); } @Override - protected String getDeathSound() { + protected String getMyPetDeathSound() { return "entity.zombified_piglin.death"; } @@ -77,34 +77,34 @@ protected String getLivingSound() { } @Override - public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) { - if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == EnumInteractionResult.b) { - return EnumInteractionResult.b; + public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == InteractionResult.CONSUME) { + return InteractionResult.CONSUME; } if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { - if (itemStack.getItem() == Items.pq && getOwner().getPlayer().isSneaking() && canEquip()) { + if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); getMyPet().setEquipment(slot, null); hadEquipment = true; } } if (hadEquipment) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { try { - itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand)); + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand)); } catch (Error e) { // TODO REMOVE - itemStack.damage(1, entityhuman, (entityhuman1) -> { + itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { try { - ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); + CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand); } catch (IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -112,42 +112,42 @@ public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, En } } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) { - EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.getEquipmentSlotForItem(itemStack).getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag()); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); - if (itemInSlot != null && itemInSlot.getItem() != Items.a && itemInSlot != ItemStack.b && !entityhuman.getAbilities().d) { - EntityItem entityitem = new EntityItem(this.t, this.locX(), this.locY() + 1, this.locZ(), itemInSlot); - entityitem.ap = 10; - entityitem.setMot(entityitem.getMot().add(0, this.Q.nextFloat() * 0.05F, 0)); - this.t.addEntity(entityitem); + if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot); + entityitem.pickupDelay = 10; + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0)); + this.level.addFreshEntity(entityitem); } getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack)); - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } else if (Configuration.MyPet.ZombifiedPiglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { - if (itemStack != ItemStack.b && !entityhuman.getAbilities().d) { - itemStack.subtract(1); + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); if (itemStack.getCount() <= 0) { - entityhuman.getInventory().setItem(entityhuman.getInventory().k, ItemStack.b); + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); } } getMyPet().setBaby(false); - return EnumInteractionResult.b; + return InteractionResult.CONSUME; } } - return EnumInteractionResult.d; + return InteractionResult.PASS; } @Override - protected void initDatawatcher() { - super.initDatawatcher(); - getDataWatcher().register(AGE_WATCHER, false); // is baby + protected void defineSynchedData() { + super.defineSynchedData(); + getEntityData().define(AGE_WATCHER, false); // is baby } /** @@ -161,7 +161,7 @@ public float getSoundSpeed() { @Override public void updateVisuals() { - this.getDataWatcher().set(AGE_WATCHER, getMyPet().isBaby()); + this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby()); Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> { if (getMyPet().getStatus() == PetState.Here) { @@ -178,17 +178,17 @@ public MyZombifiedPiglin getMyPet() { } public void setPetEquipment(EquipmentSlot slot, ItemStack itemStack) { - ((WorldServer) this.t).getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutEntityEquipment(getId(), Arrays.asList(new Pair<>(EnumItemSlot.values()[slot.get19Slot()], itemStack)))); + ((ServerLevel) this.level).getChunkProvider().broadcastAndSend(this, new ClientboundSetEquipmentPacket(getId(), Arrays.asList(new Pair<>(net.minecraft.world.entity.EquipmentSlot.values()[slot.get19Slot()], itemStack)))); } @Override - public ItemStack getEquipment(EnumItemSlot vanillaSlot) { + public ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot vanillaSlot) { if (Util.findClassInStackTrace(Thread.currentThread().getStackTrace(), "net.minecraft.server.level.EntityTrackerEntry", 2)) { - EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getSlotFlag()); + EquipmentSlot slot = EquipmentSlot.getSlotById(vanillaSlot.getFilterFlag()); if (getMyPet().getEquipment(slot) != null) { return CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); } } - return super.getEquipment(vanillaSlot); + return super.getItemBySlot(vanillaSlot); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/services/EntityConverterService.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/services/EntityConverterService.java index a91b4a230f..a31d5260ee 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/services/EntityConverterService.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/services/EntityConverterService.java @@ -20,37 +20,99 @@ package de.Keyle.MyPet.compat.v1_17_R1.services; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftTropicalFish; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftVillager; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftVillagerZombie; +import org.bukkit.entity.AbstractHorse; +import org.bukkit.entity.Ageable; +import org.bukkit.entity.Bee; +import org.bukkit.entity.Cat; +import org.bukkit.entity.ChestedHorse; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.Enderman; +import org.bukkit.entity.Fox; +import org.bukkit.entity.Horse; +import org.bukkit.entity.IronGolem; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Llama; +import org.bukkit.entity.MagmaCube; +import org.bukkit.entity.MushroomCow; +import org.bukkit.entity.Panda; +import org.bukkit.entity.Parrot; +import org.bukkit.entity.Phantom; +import org.bukkit.entity.Pig; +import org.bukkit.entity.PufferFish; +import org.bukkit.entity.Rabbit; +import org.bukkit.entity.Sheep; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.SkeletonHorse; +import org.bukkit.entity.Slime; +import org.bukkit.entity.TropicalFish; +import org.bukkit.entity.Villager; +import org.bukkit.entity.WanderingTrader; +import org.bukkit.entity.Wolf; +import org.bukkit.entity.Zombie; +import org.bukkit.entity.ZombieHorse; +import org.bukkit.entity.ZombieVillager; +import org.bukkit.inventory.HorseInventory; +import org.bukkit.inventory.ItemStack; + import com.google.common.collect.Sets; import com.mojang.serialization.Dynamic; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.Util; import de.Keyle.MyPet.api.entity.EquipmentSlot; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPetBaby; -import de.Keyle.MyPet.api.entity.types.*; +import de.Keyle.MyPet.api.entity.types.MyBee; +import de.Keyle.MyPet.api.entity.types.MyCat; +import de.Keyle.MyPet.api.entity.types.MyCreeper; +import de.Keyle.MyPet.api.entity.types.MyEnderman; +import de.Keyle.MyPet.api.entity.types.MyHorse; +import de.Keyle.MyPet.api.entity.types.MyIronGolem; +import de.Keyle.MyPet.api.entity.types.MyLlama; +import de.Keyle.MyPet.api.entity.types.MyMagmaCube; +import de.Keyle.MyPet.api.entity.types.MyMooshroom; +import de.Keyle.MyPet.api.entity.types.MyPanda; +import de.Keyle.MyPet.api.entity.types.MyParrot; +import de.Keyle.MyPet.api.entity.types.MyPhantom; +import de.Keyle.MyPet.api.entity.types.MyPig; +import de.Keyle.MyPet.api.entity.types.MyPufferfish; +import de.Keyle.MyPet.api.entity.types.MyRabbit; +import de.Keyle.MyPet.api.entity.types.MySheep; +import de.Keyle.MyPet.api.entity.types.MySkeleton; +import de.Keyle.MyPet.api.entity.types.MySkeletonHorse; +import de.Keyle.MyPet.api.entity.types.MySlime; +import de.Keyle.MyPet.api.entity.types.MyTropicalFish; +import de.Keyle.MyPet.api.entity.types.MyVillager; +import de.Keyle.MyPet.api.entity.types.MyWanderingTrader; +import de.Keyle.MyPet.api.entity.types.MyWitherSkeleton; +import de.Keyle.MyPet.api.entity.types.MyZombieHorse; +import de.Keyle.MyPet.api.entity.types.MyZombieVillager; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.api.util.ReflectionUtil; import de.Keyle.MyPet.compat.v1_17_R1.util.inventory.ItemStackNBTConverter; -import de.keyle.knbt.*; -import net.minecraft.core.IRegistry; -import net.minecraft.nbt.DynamicOpsNBT; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.entity.ai.gossip.Reputation; -import net.minecraft.world.entity.monster.EntityZombieVillager; -import net.minecraft.world.entity.npc.EntityVillager; -import net.minecraft.world.item.trading.MerchantRecipeList; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftTropicalFish; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftVillager; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftVillagerZombie; -import org.bukkit.entity.*; -import org.bukkit.inventory.HorseInventory; -import org.bukkit.inventory.ItemStack; - -import java.util.*; +import de.keyle.knbt.TagByte; +import de.keyle.knbt.TagCompound; +import de.keyle.knbt.TagInt; +import de.keyle.knbt.TagList; +import de.keyle.knbt.TagLong; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.gossip.GossipContainer; +import net.minecraft.world.item.trading.MerchantOffers; @Compat("v1_17_R1") public class EntityConverterService extends de.Keyle.MyPet.api.util.service.types.EntityConverterService { @@ -188,21 +250,21 @@ public void convertEntity(MyPet myPet, LivingEntity normalEntity) { if (villagerPet.hasOriginalData()) { TagCompound villagerTag = villagerPet.getOriginalData(); - EntityVillager entityVillager = ((CraftVillager) villagerEntity).getHandle(); + net.minecraft.world.entity.npc.Villager entityVillager = ((CraftVillager) villagerEntity).getHandle(); try { if (villagerTag.containsKey("Offers")) { TagCompound offersTag = villagerTag.get("Offers"); - NBTTagCompound vanillaNBT = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(offersTag); - entityVillager.b(new MerchantRecipeList(vanillaNBT)); + CompoundTag vanillaNBT = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(offersTag); + entityVillager.setOffers(new MerchantOffers(vanillaNBT)); } if (villagerTag.containsKey("Inventory")) { TagList inventoryTag = villagerTag.get("Inventory"); - NBTTagList vanillaNBT = (NBTTagList) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag); + ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag); for (int i = 0; i < vanillaNBT.size(); ++i) { - net.minecraft.world.item.ItemStack itemstack = net.minecraft.world.item.ItemStack.a(vanillaNBT.getCompound(i)); + net.minecraft.world.item.ItemStack itemstack = net.minecraft.world.item.ItemStack.of(vanillaNBT.getCompound(i)); if (!itemstack.isEmpty()) { - entityVillager.getInventory().a(itemstack); + entityVillager.getInventory().addItem(itemstack); } } } @@ -212,12 +274,12 @@ public void convertEntity(MyPet myPet, LivingEntity normalEntity) { } if (villagerTag.containsKey("Gossips")) { TagList inventoryTag = villagerTag.get("Gossips"); - NBTTagList vanillaNBT = (NBTTagList) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag); - ((Reputation) ReflectionUtil.getFieldValue(EntityVillager.class, entityVillager, "by")) - .a(new Dynamic<>(DynamicOpsNBT.a, vanillaNBT)); + ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag); + ((GossipContainer) ReflectionUtil.getFieldValue(net.minecraft.world.entity.npc.Villager.class, entityVillager, "by")) + .update(new Dynamic<>(NbtOps.INSTANCE, vanillaNBT)); } if (villagerTag.containsKey("LastRestock")) { - long lastRestock = villagerTag.getAs("LastRestock", TagLong.class).getLongData(); + long lastRestock = villagerTag.getAs("LastRestock", TagLong.class).getLongData(); ReflectionUtil.setFieldValue("bC", entityVillager, lastRestock); } if (villagerTag.containsKey("LastGossipDecay")) { @@ -234,18 +296,18 @@ public void convertEntity(MyPet myPet, LivingEntity normalEntity) { } if (villagerTag.containsKey("Xp")) { int xp = villagerTag.getAs("Xp", TagInt.class).getIntData(); - entityVillager.setExperience(xp); + entityVillager.setVillagerXp(xp); } } } else if (myPet instanceof MySlime) { ((Slime) normalEntity).setSize(((MySlime) myPet).getSize()); } else if (myPet instanceof MyZombieVillager) { Villager.Profession profession = Villager.Profession.values()[((MyZombieVillager) myPet).getProfession()]; - EntityZombieVillager nmsEntity = ((CraftVillagerZombie) normalEntity).getHandle(); + net.minecraft.world.entity.monster.ZombieVillager nmsEntity = ((CraftVillagerZombie) normalEntity).getHandle(); nmsEntity.setVillagerData(nmsEntity.getVillagerData() - .withType(IRegistry.ao.get(new MinecraftKey(((MyZombieVillager) myPet).getType().name().toLowerCase(Locale.ROOT)))) - .withLevel(((MyZombieVillager) myPet).getTradingLevel()) - .withProfession(IRegistry.ap.get(new MinecraftKey(profession.name().toLowerCase(Locale.ROOT))))); + .setType(Registry.VILLAGER_TYPE.get(new ResourceLocation(((MyZombieVillager) myPet).getType().name().toLowerCase(Locale.ROOT)))) + .setLevel(((MyZombieVillager) myPet).getTradingLevel()) + .setProfession(Registry.VILLAGER_PROFESSION.get(new ResourceLocation(profession.name().toLowerCase(Locale.ROOT))))); } else if (myPet instanceof MyWitherSkeleton) { normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD)); } else if (myPet instanceof MySkeleton) { diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetArrow.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetArrow.java index 3013a9f895..cffe9a0f5a 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetArrow.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetArrow.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftArrow; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntityArrow; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftArrow; +import net.minecraft.world.entity.projectile.Arrow; @Compat("v1_17_R1") public class CraftMyPetArrow extends CraftArrow implements CraftMyPetProjectile { - public CraftMyPetArrow(CraftServer server, EntityArrow entity) { + public CraftMyPetArrow(CraftServer server, Arrow entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetDragonFireball.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetDragonFireball.java index 5786ab4a3f..39a2a1f79f 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetDragonFireball.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetDragonFireball.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftDragonFireball; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntityDragonFireball; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftDragonFireball; +import net.minecraft.world.entity.projectile.DragonFireball; @Compat("v1_17_R1") public class CraftMyPetDragonFireball extends CraftDragonFireball implements CraftMyPetProjectile { - public CraftMyPetDragonFireball(CraftServer server, EntityDragonFireball entity) { + public CraftMyPetDragonFireball(CraftServer server, DragonFireball entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetEgg.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetEgg.java index 28d0014275..057e324cdf 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetEgg.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetEgg.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEgg; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntityEgg; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEgg; +import net.minecraft.world.entity.projectile.ThrownEgg; @Compat("v1_17_R1") public class CraftMyPetEgg extends CraftEgg implements CraftMyPetProjectile { - public CraftMyPetEgg(CraftServer server, EntityEgg entity) { + public CraftMyPetEgg(CraftServer server, ThrownEgg entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetEnderPearl.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetEnderPearl.java index 04c6ec0e5a..09cbda8c72 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetEnderPearl.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetEnderPearl.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEnderPearl; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntityEnderPearl; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEnderPearl; +import net.minecraft.world.entity.projectile.ThrownEnderpearl; @Compat("v1_17_R1") public class CraftMyPetEnderPearl extends CraftEnderPearl implements CraftMyPetProjectile { - public CraftMyPetEnderPearl(CraftServer server, EntityEnderPearl entity) { + public CraftMyPetEnderPearl(CraftServer server, ThrownEnderpearl entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetLargeFireball.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetLargeFireball.java index af0231373d..9b38f05c0b 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetLargeFireball.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetLargeFireball.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLargeFireball; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntityLargeFireball; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLargeFireball; +import net.minecraft.world.entity.projectile.LargeFireball; @Compat("v1_17_R1") public class CraftMyPetLargeFireball extends CraftLargeFireball implements CraftMyPetProjectile { - public CraftMyPetLargeFireball(CraftServer server, EntityLargeFireball entity) { + public CraftMyPetLargeFireball(CraftServer server, LargeFireball entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetLlamaSpit.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetLlamaSpit.java index c592f9541a..128355804e 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetLlamaSpit.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetLlamaSpit.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLlamaSpit; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntityLlamaSpit; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLlamaSpit; +import net.minecraft.world.entity.projectile.LlamaSpit; @Compat("v1_17_R1") public class CraftMyPetLlamaSpit extends CraftLlamaSpit implements CraftMyPetProjectile { - public CraftMyPetLlamaSpit(CraftServer server, EntityLlamaSpit entity) { + public CraftMyPetLlamaSpit(CraftServer server, LlamaSpit entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetSmallFireball.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetSmallFireball.java index 26dce4deed..954ac9b2b0 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetSmallFireball.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetSmallFireball.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftSmallFireball; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntitySmallFireball; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftSmallFireball; +import net.minecraft.world.entity.projectile.SmallFireball; @Compat("v1_17_R1") public class CraftMyPetSmallFireball extends CraftSmallFireball implements CraftMyPetProjectile { - public CraftMyPetSmallFireball(CraftServer server, EntitySmallFireball entity) { + public CraftMyPetSmallFireball(CraftServer server, SmallFireball entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetSnowball.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetSnowball.java index ef57c3d707..69a922b209 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetSnowball.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetSnowball.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftSnowball; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntitySnowball; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftSnowball; +import net.minecraft.world.entity.projectile.Snowball; @Compat("v1_17_R1") public class CraftMyPetSnowball extends CraftSnowball implements CraftMyPetProjectile { - public CraftMyPetSnowball(CraftServer server, EntitySnowball entity) { + public CraftMyPetSnowball(CraftServer server, Snowball entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetTrident.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetTrident.java index e59d4af9b4..6544d62fe4 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetTrident.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetTrident.java @@ -20,22 +20,23 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; -import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; -import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; -import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; -import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; -import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntityThrownTrident; import org.bukkit.craftbukkit.v1_17_R1.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftTrident; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; +import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; +import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; +import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; +import de.Keyle.MyPet.api.util.Compat; +import net.minecraft.world.entity.projectile.ThrownTrident; + @Compat("v1_17_R1") public class CraftMyPetTrident extends CraftTrident implements CraftMyPetProjectile { - public CraftMyPetTrident(CraftServer server, EntityThrownTrident entity) { + public CraftMyPetTrident(CraftServer server, ThrownTrident entity) { super(server, entity); } @@ -67,11 +68,11 @@ public void setPersistent(boolean b) { @NotNull @Override public ItemStack getItem() { - return CraftItemStack.asBukkitCopy(getHandle().aq); + return CraftItemStack.asBukkitCopy(getHandle().tridentItem); } @Override public void setItem(@NotNull ItemStack itemStack) { - getHandle().aq = CraftItemStack.asNMSCopy(itemStack); + getHandle().tridentItem = CraftItemStack.asNMSCopy(itemStack); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetWitherSkull.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetWitherSkull.java index 2faea15dab..d72f65879b 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetWitherSkull.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/bukkit/CraftMyPetWitherSkull.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftWitherSkull; + import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetMinecraftEntity; import de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile; import de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile; import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.world.entity.projectile.EntityWitherSkull; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftWitherSkull; +import net.minecraft.world.entity.projectile.WitherSkull; @Compat("v1_17_R1") public class CraftMyPetWitherSkull extends CraftWitherSkull implements CraftMyPetProjectile { - public CraftMyPetWitherSkull(CraftServer server, EntityWitherSkull entity) { + public CraftMyPetWitherSkull(CraftServer server, WitherSkull entity) { super(server, entity); } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetArrow.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetArrow.java index 1a8e9c8301..e112a24f1e 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetArrow.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetArrow.java @@ -24,55 +24,55 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetArrow; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.projectile.EntityTippedArrow; +import net.minecraft.world.entity.projectile.Arrow; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @Compat("v1_17_R1") -public class MyPetArrow extends EntityTippedArrow implements EntityMyPetProjectile { +public class MyPetArrow extends Arrow implements EntityMyPetProjectile { protected CraftMyPetArrow bukkitEntity = null; - public MyPetArrow(World world, EntityMyPet entityMyPet) { + public MyPetArrow(Level world, EntityMyPet entityMyPet) { super(world, entityMyPet); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } @Override public CraftMyPetArrow getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetArrow(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetArrow(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbttagcompound) { + public void addAdditionalSaveData(CompoundTag nbttagcompound) { } @Override - protected ItemStack getItemStack() { - return new ItemStack(Items.mh); + protected ItemStack getPickupItem() { + return new ItemStack(Items.ARROW); } @Override - public void loadData(NBTTagCompound nbttagcompound) { + public void readAdditionalSaveData(CompoundTag nbttagcompound) { } @Override public void tick() { try { super.tick(); - if (this.b) { - die(); + if (this.inGround) { + discard(); } } catch (Exception e) { e.printStackTrace(); @@ -80,7 +80,7 @@ public void tick() { } @Override - public boolean damageEntity(DamageSource damagesource, float f) { + public boolean hurt(DamageSource damagesource, float f) { return false; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetDragonFireball.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetDragonFireball.java index a8b527642e..0585581729 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetDragonFireball.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetDragonFireball.java @@ -24,30 +24,30 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetDragonFireball; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.projectile.EntityDragonFireball; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.MovingObjectPosition; -import net.minecraft.world.phys.MovingObjectPositionEntity; -import net.royawesome.jlibnoise.MathHelper; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.DragonFireball; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; @Compat("v1_17_R1") -public class MyPetDragonFireball extends EntityDragonFireball implements EntityMyPetProjectile { +public class MyPetDragonFireball extends DragonFireball implements EntityMyPetProjectile { protected float damage = 0; protected int deathCounter = 100; protected CraftMyPetDragonFireball bukkitEntity = null; - public MyPetDragonFireball(World world, EntityMyPet entityliving, double d0, double d1, double d2) { + public MyPetDragonFireball(Level world, EntityMyPet entityliving, double d0, double d1, double d2) { super(world, entityliving, d0, d1, d2); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } public void setDamage(float damage) { @@ -56,41 +56,41 @@ public void setDamage(float damage) { @Override public void setDirection(double d0, double d1, double d2) { - d0 += this.Q.nextGaussian() * 0.2D; - d1 += this.Q.nextGaussian() * 0.2D; - d2 += this.Q.nextGaussian() * 0.2D; - double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2); - this.b = (d0 / d3 * 0.1D); - this.c = (d1 / d3 * 0.1D); - this.d = (d2 / d3 * 0.1D); + d0 += this.random.nextGaussian() * 0.2D; + d1 += this.random.nextGaussian() * 0.2D; + d2 += this.random.nextGaussian() * 0.2D; + double d3 = Mth.sqrt((float) (d0 * d0 + d1 * d1 + d2 * d2)); + this.xPower = (d0 / d3 * 0.1D); + this.yPower = (d1 / d3 * 0.1D); + this.zPower = (d2 / d3 * 0.1D); } @Override public CraftMyPetDragonFireball getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetDragonFireball(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetDragonFireball(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - protected void a(MovingObjectPosition movingObjectPosition) { - if (movingObjectPosition.getType() == MovingObjectPosition.EnumMovingObjectType.c) { - Entity entity = ((MovingObjectPositionEntity) movingObjectPosition).getEntity(); - if (entity instanceof EntityLiving) { - entity.damageEntity(DamageSource.projectile(this, getShooter()), damage); + protected void onHit(HitResult movingObjectPosition) { + if (movingObjectPosition.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) movingObjectPosition).getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(DamageSource.thrown(this, getShooter()), damage); } } - die(); + discard(); } @Override @@ -98,7 +98,7 @@ public void tick() { try { super.tick(); if (deathCounter-- <= 0) { - die(); + discard(); } } catch (Exception e) { e.printStackTrace(); diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetEgg.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetEgg.java index 4944fd0132..52f09ed867 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetEgg.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetEgg.java @@ -24,32 +24,32 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetEgg; -import net.minecraft.core.particles.ParticleParamItem; -import net.minecraft.core.particles.Particles; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.particles.ItemParticleOption; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.projectile.EntityEgg; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.ThrownEgg; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.MovingObjectPosition; -import net.minecraft.world.phys.MovingObjectPositionEntity; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; @Compat("v1_17_R1") -public class MyPetEgg extends EntityEgg implements EntityMyPetProjectile { +public class MyPetEgg extends ThrownEgg implements EntityMyPetProjectile { protected float damage = 0; protected CraftMyPetEgg bukkitEntity = null; - public MyPetEgg(World world, EntityMyPet entityLiving) { + public MyPetEgg(Level world, EntityMyPet entityLiving) { super(world, entityLiving); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } public void setDamage(float damage) { @@ -59,35 +59,35 @@ public void setDamage(float damage) { @Override public CraftMyPetEgg getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetEgg(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetEgg(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - protected void a(MovingObjectPosition movingObjectPosition) { - if (movingObjectPosition.getType() == MovingObjectPosition.EnumMovingObjectType.c) { - Entity entity = ((MovingObjectPositionEntity) movingObjectPosition).getEntity(); - if (entity instanceof EntityLiving) { - entity.damageEntity(DamageSource.projectile(this, getShooter()), damage); + protected void onHit(HitResult movingObjectPosition) { + if (movingObjectPosition.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) movingObjectPosition).getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(DamageSource.thrown(this, getShooter()), damage); } } for (int i = 0; i < 8; ++i) { - this.t.addParticle(new ParticleParamItem(Particles.K, new ItemStack(Items.oo)), this.locX(), this.locY(), this.locZ(), ((double) this.Q.nextFloat() - 0.5D) * 0.08D, ((double) this.Q.nextFloat() - 0.5D) * 0.08D, ((double) this.Q.nextFloat() - 0.5D) * 0.08D); + this.level.addParticle(new ItemParticleOption(ParticleTypes.ITEM, new ItemStack(Items.LEATHER_BOOTS)), this.getX(), this.getY(), this.getZ(), ((double) this.random.nextFloat() - 0.5D) * 0.08D, ((double) this.random.nextFloat() - 0.5D) * 0.08D, ((double) this.random.nextFloat() - 0.5D) * 0.08D); } - die(); + discard(); } @Override - public boolean damageEntity(DamageSource damagesource, float f) { + public boolean hurt(DamageSource damagesource, float f) { return false; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetEnderPearl.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetEnderPearl.java index d3a153096c..fd60c41509 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetEnderPearl.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetEnderPearl.java @@ -24,29 +24,29 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetEnderPearl; -import net.minecraft.core.particles.Particles; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.projectile.EntityEnderPearl; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.MovingObjectPosition; -import net.minecraft.world.phys.MovingObjectPositionEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.ThrownEnderpearl; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; @Compat("v1_17_R1") -public class MyPetEnderPearl extends EntityEnderPearl implements EntityMyPetProjectile { +public class MyPetEnderPearl extends ThrownEnderpearl implements EntityMyPetProjectile { protected float damage = 0; protected CraftMyPetEnderPearl bukkitEntity = null; - public MyPetEnderPearl(World world, EntityMyPet entityLiving) { + public MyPetEnderPearl(Level world, EntityMyPet entityLiving) { super(world, entityLiving); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } public void setDamage(float damage) { @@ -56,35 +56,35 @@ public void setDamage(float damage) { @Override public CraftMyPetEnderPearl getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetEnderPearl(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetEnderPearl(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - protected void a(MovingObjectPosition movingObjectPosition) { - if (movingObjectPosition.getType() == MovingObjectPosition.EnumMovingObjectType.c) { - Entity entity = ((MovingObjectPositionEntity) movingObjectPosition).getEntity(); - if (entity instanceof EntityLiving) { - entity.damageEntity(DamageSource.projectile(this, getShooter()), damage); + protected void onHit(HitResult movingObjectPosition) { + if (movingObjectPosition.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) movingObjectPosition).getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(DamageSource.thrown(this, getShooter()), damage); } } for (int i = 0; i < 32; ++i) { - this.t.addParticle(Particles.T, this.locX(), this.locY() + this.Q.nextDouble() * 2.0D, this.locZ(), this.Q.nextGaussian(), 0.0D, this.Q.nextGaussian()); + this.level.addParticle(ParticleTypes.PORTAL, this.getX(), this.getY() + this.random.nextDouble() * 2.0D, this.getZ(), this.random.nextGaussian(), 0.0D, this.random.nextGaussian()); } - die(); + discard(); } @Override - public boolean damageEntity(DamageSource damagesource, float f) { + public boolean hurt(DamageSource damagesource, float f) { return false; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetLargeFireball.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetLargeFireball.java index dc95d2e10c..dc70fa1316 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetLargeFireball.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetLargeFireball.java @@ -24,30 +24,30 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetLargeFireball; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.projectile.EntityLargeFireball; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.MovingObjectPosition; -import net.minecraft.world.phys.MovingObjectPositionEntity; -import net.royawesome.jlibnoise.MathHelper; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.LargeFireball; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; @Compat("v1_17_R1") -public class MyPetLargeFireball extends EntityLargeFireball implements EntityMyPetProjectile { +public class MyPetLargeFireball extends LargeFireball implements EntityMyPetProjectile { protected float damage = 0; protected int deathCounter = 100; protected CraftMyPetLargeFireball bukkitEntity = null; - public MyPetLargeFireball(World world, EntityMyPet entityliving, double d0, double d1, double d2) { - super(world, entityliving, d0, d1, d2, 1); // TODO: 2021/06/28 temp value (i) - 2021/08/19 is this done? Where is i here? + public MyPetLargeFireball(Level world, EntityMyPet entityliving, double d0, double d1, double d2) { + super(world, entityliving, d0, d1, d2, 1); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } public void setDamage(float damage) { @@ -56,40 +56,40 @@ public void setDamage(float damage) { @Override public void setDirection(double d0, double d1, double d2) { - d0 += this.Q.nextGaussian() * 0.2D; - d1 += this.Q.nextGaussian() * 0.2D; - d2 += this.Q.nextGaussian() * 0.2D; - double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2); - this.b = (d0 / d3 * 0.1D); - this.c = (d1 / d3 * 0.1D); - this.d = (d2 / d3 * 0.1D); + d0 += this.random.nextGaussian() * 0.2D; + d1 += this.random.nextGaussian() * 0.2D; + d2 += this.random.nextGaussian() * 0.2D; + double d3 = Mth.sqrt((float)(d0 * d0 + d1 * d1 + d2 * d2)); + this.xPower = (d0 / d3 * 0.1D); + this.yPower = (d1 / d3 * 0.1D); + this.zPower = (d2 / d3 * 0.1D); } @Override public CraftMyPetLargeFireball getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetLargeFireball(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetLargeFireball(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - protected void a(MovingObjectPosition movingObjectPosition) { - if (movingObjectPosition.getType() == MovingObjectPosition.EnumMovingObjectType.c) { - Entity entity = ((MovingObjectPositionEntity) movingObjectPosition).getEntity(); - if (entity instanceof EntityLiving) { - entity.damageEntity(DamageSource.fireball(this, getShooter()), damage); + protected void onHit(HitResult movingObjectPosition) { + if (movingObjectPosition.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) movingObjectPosition).getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(DamageSource.fireball(this, getShooter()), damage); } } - die(); + discard(); } @Override @@ -97,7 +97,7 @@ public void tick() { try { super.tick(); if (deathCounter-- <= 0) { - die(); + discard(); } } catch (Exception e) { e.printStackTrace(); @@ -105,7 +105,7 @@ public void tick() { } @Override - public boolean damageEntity(DamageSource damagesource, float f) { + public boolean hurt(DamageSource damagesource, float f) { return false; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetLlamaSpit.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetLlamaSpit.java index 80ae95fa88..850ff07e86 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetLlamaSpit.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetLlamaSpit.java @@ -26,67 +26,67 @@ import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetLlamaSpit; import lombok.Getter; import lombok.Setter; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.MathHelper; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.projectile.EntityLlamaSpit; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.MovingObjectPosition; -import net.minecraft.world.phys.MovingObjectPositionEntity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.LlamaSpit; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; @Compat("v1_17_R1") -public class MyPetLlamaSpit extends EntityLlamaSpit implements EntityMyPetProjectile { +public class MyPetLlamaSpit extends LlamaSpit implements EntityMyPetProjectile { @Setter @Getter protected float damage = 0; protected CraftMyPetLlamaSpit bukkitEntity = null; - public MyPetLlamaSpit(World world, EntityMyPet entityMyPet) { - super(EntityTypes.W, world); - this.setShooter(entityMyPet); - this.setPosition(entityMyPet.locX() - (double) (entityMyPet.getWidth() + 1.0F) * 0.5D * (double) MathHelper.sin(entityMyPet.aE * 0.017453292F), - entityMyPet.locY() + (double) entityMyPet.getHeadHeight() - 0.10000000149011612D, - entityMyPet.locZ() + (double) (entityMyPet.getWidth() + 1.0F) * 0.5D * (double) MathHelper.cos(entityMyPet.aE * 0.017453292F)); + public MyPetLlamaSpit(Level world, EntityMyPet entityMyPet) { + super(EntityType.LLAMA_SPIT, world); + this.setOwner(entityMyPet); + this.setPos(entityMyPet.getX() - (double) (entityMyPet.getBbWidth() + 1.0F) * 0.5D * (double) Mth.sin(entityMyPet.EXTRA_RENDER_CULLING_SIZE_WITH_BIG_HAT * 0.017453292F), + entityMyPet.getY() + (double) entityMyPet.getEyeHeight() - 0.10000000149011612D, + entityMyPet.getZ() + (double) (entityMyPet.getBbWidth() + 1.0F) * 0.5D * (double) Mth.cos(entityMyPet.EXTRA_RENDER_CULLING_SIZE_WITH_BIG_HAT * 0.017453292F)); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } @Override public CraftMyPetLlamaSpit getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetLlamaSpit(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetLlamaSpit(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public boolean damageEntity(DamageSource damagesource, float f) { + public boolean hurt(DamageSource damagesource, float f) { return false; } @Override - public void a(MovingObjectPosition movingObjectPosition) { - if (movingObjectPosition.getType() == MovingObjectPosition.EnumMovingObjectType.c) { - Entity entity = ((MovingObjectPositionEntity) movingObjectPosition).getEntity(); - if (entity instanceof EntityLiving) { - entity.damageEntity(DamageSource.a(this, getShooter()), damage); + public void onHit(HitResult movingObjectPosition) { + if (movingObjectPosition.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) movingObjectPosition).getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(DamageSource.indirectMobAttack(this, getShooter()), damage); } } - this.die(); + this.discard(); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetSmallFireball.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetSmallFireball.java index 4b05902a83..d646f3c597 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetSmallFireball.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetSmallFireball.java @@ -24,30 +24,30 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetSmallFireball; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.projectile.EntitySmallFireball; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.MovingObjectPosition; -import net.minecraft.world.phys.MovingObjectPositionEntity; -import net.royawesome.jlibnoise.MathHelper; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.SmallFireball; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; @Compat("v1_17_R1") -public class MyPetSmallFireball extends EntitySmallFireball implements EntityMyPetProjectile { +public class MyPetSmallFireball extends SmallFireball implements EntityMyPetProjectile { protected float damage = 0; protected int deathCounter = 100; protected CraftMyPetSmallFireball bukkitEntity = null; - public MyPetSmallFireball(World world, EntityMyPet entityliving, double d0, double d1, double d2) { + public MyPetSmallFireball(Level world, EntityMyPet entityliving, double d0, double d1, double d2) { super(world, entityliving, d0, d1, d2); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } public void setDamage(float damage) { @@ -56,40 +56,40 @@ public void setDamage(float damage) { @Override public void setDirection(double d0, double d1, double d2) { - d0 += this.Q.nextGaussian() * 0.2D; - d1 += this.Q.nextGaussian() * 0.2D; - d2 += this.Q.nextGaussian() * 0.2D; - double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2); - this.b = (d0 / d3 * 0.1D); - this.c = (d1 / d3 * 0.1D); - this.d = (d2 / d3 * 0.1D); + d0 += this.random.nextGaussian() * 0.2D; + d1 += this.random.nextGaussian() * 0.2D; + d2 += this.random.nextGaussian() * 0.2D; + double d3 = Mth.sqrt((float)(d0 * d0 + d1 * d1 + d2 * d2)); + this.xPower = (d0 / d3 * 0.1D); //TODO + this.yPower = (d1 / d3 * 0.1D); + this.zPower = (d2 / d3 * 0.1D); } @Override public CraftMyPetSmallFireball getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetSmallFireball(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetSmallFireball(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - protected void a(MovingObjectPosition movingObjectPosition) { - if (movingObjectPosition.getType() == MovingObjectPosition.EnumMovingObjectType.c) { - Entity entity = ((MovingObjectPositionEntity) movingObjectPosition).getEntity(); - if (entity instanceof EntityLiving) { - entity.damageEntity(DamageSource.fireball(this, getShooter()), damage); + protected void onHit(HitResult movingObjectPosition) { + if (movingObjectPosition.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) movingObjectPosition).getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(DamageSource.fireball(this, getShooter()), damage); } } - die(); + discard(); } @Override @@ -97,7 +97,7 @@ public void tick() { try { super.tick(); if (deathCounter-- <= 0) { - die(); + discard(); } } catch (Exception e) { e.printStackTrace(); @@ -105,7 +105,7 @@ public void tick() { } @Override - public boolean damageEntity(DamageSource damagesource, float f) { + public boolean hurt(DamageSource damagesource, float f) { return false; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetSnowball.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetSnowball.java index d82534ad22..ef3544bfd9 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetSnowball.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetSnowball.java @@ -24,29 +24,29 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetSnowball; -import net.minecraft.core.particles.Particles; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.projectile.EntitySnowball; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.MovingObjectPosition; -import net.minecraft.world.phys.MovingObjectPositionEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.Snowball; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; @Compat("v1_17_R1") -public class MyPetSnowball extends EntitySnowball implements EntityMyPetProjectile { +public class MyPetSnowball extends Snowball implements EntityMyPetProjectile { protected float damage = 0; protected CraftMyPetSnowball bukkitEntity = null; - public MyPetSnowball(World world, EntityMyPet entityLiving) { + public MyPetSnowball(Level world, EntityMyPet entityLiving) { super(world, entityLiving); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } public void setDamage(float damage) { @@ -56,35 +56,35 @@ public void setDamage(float damage) { @Override public CraftMyPetSnowball getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetSnowball(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetSnowball(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - protected void a(MovingObjectPosition movingObjectPosition) { - if (movingObjectPosition.getType() == MovingObjectPosition.EnumMovingObjectType.c) { - Entity entity = ((MovingObjectPositionEntity) movingObjectPosition).getEntity(); - if (entity instanceof EntityLiving) { - entity.damageEntity(DamageSource.projectile(this, getShooter()), damage); + protected void onHit(HitResult movingObjectPosition) { + if (movingObjectPosition.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) movingObjectPosition).getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(DamageSource.thrown(this, getShooter()), damage); } } for (int i = 0; i < 8; i++) { - this.t.addParticle(Particles.N, this.locX(), this.locY(), this.locZ(), 0.0D, 0.0D, 0.0D); + this.level.addParticle(ParticleTypes.ITEM_SNOWBALL, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D); } - die(); + discard(); } @Override - public boolean damageEntity(DamageSource damagesource, float f) { + public boolean hurt(DamageSource damagesource, float f) { return false; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetTrident.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetTrident.java index 919454e690..5632e6e2e0 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetTrident.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetTrident.java @@ -24,49 +24,49 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetTrident; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.projectile.EntityThrownTrident; +import net.minecraft.world.entity.projectile.ThrownTrident; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.World; +import net.minecraft.world.level.Level; @Compat("v1_17_R1") -public class MyPetTrident extends EntityThrownTrident implements EntityMyPetProjectile { +public class MyPetTrident extends ThrownTrident implements EntityMyPetProjectile { protected CraftMyPetTrident bukkitEntity = null; - public MyPetTrident(World world, EntityMyPet entityMyPet) { - super(world, entityMyPet, new ItemStack(Items.sO)); + public MyPetTrident(Level world, EntityMyPet entityMyPet) { + super(world, entityMyPet, new ItemStack(Items.TRIDENT)); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } @Override public CraftMyPetTrident getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetTrident(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetTrident(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override public void tick() { try { super.tick(); - if (this.b) { - die(); + if (this.inGround) { //TODO + discard(); } } catch (Exception e) { e.printStackTrace(); @@ -74,7 +74,7 @@ public void tick() { } @Override - public boolean damageEntity(DamageSource damagesource, float f) { + public boolean hurt(DamageSource damagesource, float f) { return false; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetWitherSkull.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetWitherSkull.java index e2f363834f..ac28683337 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetWitherSkull.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/skill/skills/ranged/nms/MyPetWitherSkull.java @@ -24,30 +24,30 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet; import de.Keyle.MyPet.compat.v1_17_R1.skill.skills.ranged.bukkit.CraftMyPetWitherSkull; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.projectile.EntityWitherSkull; -import net.minecraft.world.level.World; -import net.minecraft.world.phys.MovingObjectPosition; -import net.minecraft.world.phys.MovingObjectPositionEntity; -import net.royawesome.jlibnoise.MathHelper; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.WitherSkull; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; @Compat("v1_17_R1") -public class MyPetWitherSkull extends EntityWitherSkull implements EntityMyPetProjectile { +public class MyPetWitherSkull extends WitherSkull implements EntityMyPetProjectile { protected float damage = 0; protected int deathCounter = 100; protected CraftMyPetWitherSkull bukkitEntity = null; - public MyPetWitherSkull(World world, EntityMyPet entityliving, double d0, double d1, double d2) { + public MyPetWitherSkull(Level world, EntityMyPet entityliving, double d0, double d1, double d2) { super(world, entityliving, d0, d1, d2); } @Override public EntityMyPet getShooter() { - return (EntityMyPet) super.getShooter(); + return (EntityMyPet) super.getOwner(); } public void setDamage(float damage) { @@ -56,40 +56,40 @@ public void setDamage(float damage) { @Override public void setDirection(double d0, double d1, double d2) { - d0 += this.Q.nextGaussian() * 0.2D; - d1 += this.Q.nextGaussian() * 0.2D; - d2 += this.Q.nextGaussian() * 0.2D; - double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2); - this.b = (d0 / d3 * 0.1D); - this.c = (d1 / d3 * 0.1D); - this.d = (d2 / d3 * 0.1D); + d0 += this.random.nextGaussian() * 0.2D; + d1 += this.random.nextGaussian() * 0.2D; + d2 += this.random.nextGaussian() * 0.2D; + double d3 = Mth.sqrt((float)(d0 * d0 + d1 * d1 + d2 * d2)); + this.xPower = (d0 / d3 * 0.1D); //TODO + this.yPower = (d1 / d3 * 0.1D); + this.zPower = (d2 / d3 * 0.1D); } @Override public CraftMyPetWitherSkull getBukkitEntity() { if (this.bukkitEntity == null) { - this.bukkitEntity = new CraftMyPetWitherSkull(this.t.getCraftServer(), this); + this.bukkitEntity = new CraftMyPetWitherSkull(this.level.getCraftServer(), this); } return this.bukkitEntity; } @Override - public void saveData(NBTTagCompound nbtTagCompound) { + public void addAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - public void loadData(NBTTagCompound nbtTagCompound) { + public void readAdditionalSaveData(CompoundTag nbtTagCompound) { } @Override - protected void a(MovingObjectPosition movingObjectPosition) { - if (movingObjectPosition.getType() == MovingObjectPosition.EnumMovingObjectType.c) { - Entity entity = ((MovingObjectPositionEntity) movingObjectPosition).getEntity(); - if (entity instanceof EntityLiving) { - entity.damageEntity(DamageSource.projectile(this, getShooter()), damage); + protected void onHit(HitResult movingObjectPosition) { + if (movingObjectPosition.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) movingObjectPosition).getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(DamageSource.thrown(this, getShooter()), damage); } } - die(); + discard(); } @Override @@ -97,7 +97,7 @@ public void tick() { try { super.tick(); if (deathCounter-- <= 0) { - die(); + discard(); } } catch (Exception e) { e.printStackTrace(); diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/ConfigItem.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/ConfigItem.java index 688b9c2bb3..d3340c8fcb 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/ConfigItem.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/ConfigItem.java @@ -20,19 +20,20 @@ package de.Keyle.MyPet.compat.v1_17_R1.util; +import org.bukkit.ChatColor; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; + import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.api.util.inventory.material.MaterialHolder; import de.Keyle.MyPet.compat.v1_17_R1.util.inventory.ItemStackComparator; -import net.minecraft.core.IRegistry; -import net.minecraft.nbt.MojangsonParser; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.resources.MinecraftKey; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.TagParser; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; -import org.bukkit.ChatColor; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; @Compat("v1_17_R1") public class ConfigItem extends de.Keyle.MyPet.api.util.ConfigItem { @@ -58,12 +59,12 @@ public boolean compare(Object o) { @Override public void load(MaterialHolder material, String data) { - MinecraftKey key = new MinecraftKey(material.getId()); - Item item = IRegistry.Z.get(key); + ResourceLocation key = new ResourceLocation(material.getId()); + Item item = Registry.ITEM.get(key); //TODO AIR now? if (item == null) { - Block block = IRegistry.W.get(key); - item = block.getItem(); + Block block = Registry.BLOCK.get(key); + item = block.asItem(); } if (item == null) { return; @@ -72,14 +73,14 @@ public void load(MaterialHolder material, String data) { net.minecraft.world.item.ItemStack is = new net.minecraft.world.item.ItemStack(item, 1); if (data != null) { - NBTTagCompound tag = null; + CompoundTag tag = null; String nbtString = data.trim(); if (nbtString.startsWith("{") && nbtString.endsWith("}")) { try { - tag = MojangsonParser.parse(nbtString); + tag = TagParser.parseTag(nbtString); } catch (Exception e) { MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.UNDERLINE + e.getLocalizedMessage() + ChatColor.RESET + " caused by:"); - MyPetApi.getLogger().warning(item.getName() + " " + nbtString); + MyPetApi.getLogger().warning(item.getDescriptionId() + " " + nbtString); } if (tag != null) { is.setTag(tag); diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/iconmenu/IconMenuInventory.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/iconmenu/IconMenuInventory.java index c62ed79e2c..2dac34ce06 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/iconmenu/IconMenuInventory.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/iconmenu/IconMenuInventory.java @@ -20,6 +20,19 @@ package de.Keyle.MyPet.compat.v1_17_R1.util.iconmenu; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + import de.Keyle.MyPet.api.gui.IconMenu; import de.Keyle.MyPet.api.gui.IconMenuItem; import de.Keyle.MyPet.api.util.Compat; @@ -30,23 +43,11 @@ import de.keyle.knbt.TagList; import de.keyle.knbt.TagShort; import de.keyle.knbt.TagString; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; @Compat("v1_17_R1") public class IconMenuInventory implements de.Keyle.MyPet.api.gui.IconMenuInventory { @@ -56,7 +57,7 @@ public class IconMenuInventory implements de.Keyle.MyPet.api.gui.IconMenuInvento static { try { Class craftMetaItemClass = Class.forName("org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaItem"); - applyToItemMethod = ReflectionUtil.getMethod(craftMetaItemClass, "applyToItem", NBTTagCompound.class); + applyToItemMethod = ReflectionUtil.getMethod(craftMetaItemClass, "applyToItem", CompoundTag.class); } catch (ClassNotFoundException e) { e.printStackTrace(); } @@ -93,7 +94,7 @@ public void update(IconMenu menu) { ItemStack item = createItemStack(menuItem); minecraftInventory.setItem(slot, item); } else { - minecraftInventory.setItem(slot, ItemStack.b); + minecraftInventory.setItem(slot, ItemStack.EMPTY); } } } @@ -132,7 +133,7 @@ protected ItemStack createItemStack(IconMenuItem icon) { //TODO Check if this wo is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.STONE)); } if (is.getTag() == null) { - is.setTag(new NBTTagCompound()); + is.setTag(new CompoundTag()); } if (icon.getBukkitMeta() != null) { @@ -151,51 +152,51 @@ protected ItemStack createItemStack(IconMenuItem icon) { //TODO Check if this wo TagList enchList = new TagList(); enchList.addTag(enchTag); - is.getTag().set("Enchantments", ItemStackNBTConverter.compoundToVanillaCompound(enchList)); + is.getTag().put("Enchantments", ItemStackNBTConverter.compoundToVanillaCompound(enchList)); } else { is.getTag().remove("Enchantments"); } // hide item attributes like attack damage - is.getTag().setInt("HideFlags", 63); + is.getTag().putInt("HideFlags", 63); // Prepare display tag - NBTTagCompound display; - if (is.getTag().hasKey("display")) { + CompoundTag display; + if (is.getTag().contains("display")) { display = is.getTag().getCompound("display"); } else { - display = new NBTTagCompound(); - is.getTag().set("display", display); + display = new CompoundTag(); + is.getTag().put("display", display); } // set Title if (!icon.getTitle().equals("")) { - display.setString("Name", "{\"text\":\"" + icon.getTitle() + "\"}"); + display.putString("Name", "{\"text\":\"" + icon.getTitle() + "\"}"); } if (icon.getLore().size() > 0) { // set Lore - NBTTagList loreTag = new NBTTagList(); - display.set("Lore", loreTag); + ListTag loreTag = new ListTag(); + display.put("Lore", loreTag); for (String loreLine : icon.getLore()) { - IChatBaseComponent cm = CraftChatMessage.fromStringOrNull(loreLine); - loreTag.add(NBTTagString.a(IChatBaseComponent.ChatSerializer.a(cm))); + Component cm = CraftChatMessage.fromStringOrNull(loreLine); + loreTag.add(StringTag.valueOf(Component.Serializer.toJson(cm))); } } if (icon.hasMeta()) { TagCompound tag = new TagCompound(); icon.getMeta().applyTo(tag); - NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag); - for (String key : vanillaTag.getKeys()) { - is.getTag().set(key, vanillaTag.get(key)); + CompoundTag vanillaTag = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(tag); + for (String key : vanillaTag.getAllKeys()) { + is.getTag().put(key, vanillaTag.get(key)); } } if (icon.getTags() != null) { - NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags()); - for (String key : vanillaTag.getKeys()) { - is.getTag().set(key, vanillaTag.get(key)); + CompoundTag vanillaTag = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags()); + for (String key : vanillaTag.getAllKeys()) { + is.getTag().put(key, vanillaTag.get(key)); } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/CustomInventory.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/CustomInventory.java index 6972c0af43..0728acefe5 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/CustomInventory.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/CustomInventory.java @@ -20,23 +20,10 @@ package de.Keyle.MyPet.compat.v1_17_R1.util.inventory; -import de.Keyle.MyPet.MyPetApi; -import de.Keyle.MyPet.api.Util; -import de.Keyle.MyPet.api.util.Compat; -import de.keyle.knbt.TagByte; -import de.keyle.knbt.TagCompound; -import de.keyle.knbt.TagList; -import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.ChatComponentText; -import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.IInventory; -import net.minecraft.world.entity.item.EntityItem; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.inventory.Container; -import net.minecraft.world.inventory.Containers; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.World; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -55,16 +42,28 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; +import de.Keyle.MyPet.MyPetApi; +import de.Keyle.MyPet.api.Util; +import de.Keyle.MyPet.api.util.Compat; +import de.keyle.knbt.TagByte; +import de.keyle.knbt.TagCompound; +import de.keyle.knbt.TagList; +import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; @Compat("v1_17_R1") -public class CustomInventory implements IInventory, Listener, de.Keyle.MyPet.api.util.inventory.CustomInventory { +public class CustomInventory implements Container, Listener, de.Keyle.MyPet.api.util.inventory.CustomInventory { private String inventoryName = ""; - private final NonNullList items = NonNullList.a(64, ItemStack.b); + private final NonNullList items = NonNullList.withSize(64, ItemStack.EMPTY); private int size = 0; private int stackSize = 64; private final List transaction = new ArrayList<>(); @@ -79,9 +78,9 @@ public CustomInventory(int size, String name) { setSize(size); setName(name); } - + @Override - public int getSize() { + public int getContainerSize() { return this.size; } @@ -91,7 +90,7 @@ public void setSize(int size) { size *= 9; this.size = Util.clamp(size, 9, 54); for (int i = items.size(); i < this.size; i++) { - items.set(i, ItemStack.b); + items.set(i, ItemStack.EMPTY); } } @@ -113,7 +112,7 @@ public ItemStack getItem(int i) { if (i < size) { return items.get(i); } - return ItemStack.b; + return ItemStack.EMPTY; } @Override @@ -123,7 +122,7 @@ public void setItem(int i, ItemStack itemStack) { } else { items.add(i, itemStack); } - update(); + setChanged(); } @Override @@ -133,7 +132,7 @@ public int addItem(org.bukkit.inventory.ItemStack itemAdd) { } itemAdd = itemAdd.clone(); - for (int i = 0; i < this.getSize(); i++) { + for (int i = 0; i < this.getContainerSize(); i++) { CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i)); if (ItemStackComparator.compareItem(itemAdd, craftItem)) { @@ -150,8 +149,8 @@ public int addItem(org.bukkit.inventory.ItemStack itemAdd) { } } if (itemAdd.getAmount() > 0) { - for (int i = 0; i < this.getSize(); i++) { - if (getItem(i) == ItemStack.b) { + for (int i = 0; i < this.getContainerSize(); i++) { + if (getItem(i) == ItemStack.EMPTY) { if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) { setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone())); itemAdd.setAmount(0); @@ -190,41 +189,41 @@ public String getName() { @Override public void dropContentAt(Location loc) { - World world = ((CraftWorld) loc.getWorld()).getHandle(); - for (int i = 0; i < this.getSize(); i++) { - ItemStack is = this.splitWithoutUpdate(i); + Level world = ((CraftWorld) loc.getWorld()).getHandle(); + for (int i = 0; i < this.getContainerSize(); i++) { + ItemStack is = this.removeItemNoUpdate(i); if (is != null && !is.isEmpty()) { - is = is.cloneItemStack(); - EntityItem itemEntity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), is); - itemEntity.ap = 20; - world.addEntity(itemEntity); + is = is.copy(); + ItemEntity itemEntity = new ItemEntity(world, loc.getX(), loc.getY(), loc.getZ(), is); + itemEntity.pickupDelay = 20; + world.addFreshEntity(itemEntity); } } } @Override - public ItemStack splitStack(int slot, int subtract) { - if (slot < size && items.get(slot) != ItemStack.b) { + public ItemStack removeItem(int slot, int subtract) { + if (slot < size && items.get(slot) != ItemStack.EMPTY) { if (items.get(slot).getCount() <= subtract) { ItemStack itemStack = items.get(slot); - items.set(slot, ItemStack.b); + items.set(slot, ItemStack.EMPTY); return itemStack; } else { - ItemStack splittedStack = items.get(slot).cloneAndSubtract(subtract); + ItemStack splittedStack = items.get(slot).split(subtract); if (items.get(slot).getCount() == 0) { - items.set(slot, ItemStack.b); + items.set(slot, ItemStack.EMPTY); } return splittedStack; } } - return ItemStack.b; + return ItemStack.EMPTY; } @Override public List getContents() { List itemStack = new LinkedList<>(); - for (int i = 0; i < getSize(); i++) { + for (int i = 0; i < getContainerSize(); i++) { itemStack.add(i, items.get(i)); } return itemStack; @@ -235,7 +234,7 @@ public TagCompound save(TagCompound compound) { List itemList = new ArrayList<>(); for (int i = 0; i < this.items.size(); i++) { ItemStack itemStack = this.items.get(i); - if (itemStack != ItemStack.b) { + if (itemStack != ItemStack.EMPTY) { TagCompound item = ItemStackNBTConverter.itemStackToCompound(itemStack); item.getCompoundData().put("Slot", new TagByte((byte) i)); itemList.add(item); @@ -258,7 +257,7 @@ public void load(TagCompound nbtTagCompound) { } @Override - public boolean a(EntityHuman entityHuman) { + public boolean stillValid(net.minecraft.world.entity.player.Player entityHuman) { return true; } @@ -272,11 +271,11 @@ public void onClose(CraftHumanEntity who) { this.transaction.remove(who); if (items.size() > this.size) { for (int counterOutside = items.size() - 1; counterOutside >= this.size; counterOutside--) { - if (items.get(counterOutside) != ItemStack.b) { + if (items.get(counterOutside) != ItemStack.EMPTY) { for (int counterInside = 0; counterInside < size; counterInside++) { - if (items.get(counterInside) == ItemStack.b) { + if (items.get(counterInside) == ItemStack.EMPTY) { items.set(counterInside, items.get(counterOutside)); - items.set(counterOutside, ItemStack.b); + items.set(counterOutside, ItemStack.EMPTY); } } } @@ -302,30 +301,30 @@ public void close() { @Override public void open(Player player) { - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - Container container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter()); + ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter()); container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container); if (container != null) { - Containers customSize = Containers.a; - switch (this.getSize()) { + MenuType customSize = MenuType.GENERIC_9x1; + switch (this.getContainerSize()) { case 18: - customSize = Containers.b; + customSize = MenuType.GENERIC_9x2; break; case 27: - customSize = Containers.c; + customSize = MenuType.GENERIC_9x3; break; case 36: - customSize = Containers.d; + customSize = MenuType.GENERIC_9x4; break; case 45: - customSize = Containers.e; + customSize = MenuType.GENERIC_9x5; break; case 54: - customSize = Containers.f; + customSize = MenuType.GENERIC_9x6; break; } - entityPlayer.b.sendPacket(new PacketPlayOutOpenWindow(container.j, customSize, new ChatComponentText(this.getName()))); - entityPlayer.bV = container; + entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName()))); + entityPlayer.containerMenu = container; entityPlayer.initMenu(container); } } @@ -356,22 +355,22 @@ public Location getLocation() { } @Override - public ItemStack splitWithoutUpdate(int i) { - if (items.get(i) != ItemStack.b) { + public ItemStack removeItemNoUpdate(int i) { + if (items.get(i) != ItemStack.EMPTY) { ItemStack itemstack = items.get(i); - items.set(i, ItemStack.b); + items.set(i, ItemStack.EMPTY); return itemstack; } - return ItemStack.b; + return ItemStack.EMPTY; } @Override - public void update() { + public void setChanged() { } @Override - public void clear() { + public void clearContent() { } public boolean isNotEmpty() { diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/ItemStackComparator.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/ItemStackComparator.java index f7c926c071..f3f0cc2c57 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/ItemStackComparator.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/ItemStackComparator.java @@ -20,11 +20,12 @@ package de.Keyle.MyPet.compat.v1_17_R1.util.inventory; -import de.Keyle.MyPet.api.util.Compat; -import net.minecraft.nbt.NBTTagCompound; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; +import de.Keyle.MyPet.api.util.Compat; +import net.minecraft.nbt.CompoundTag; + @Compat("v1_17_R1") public class ItemStackComparator { @@ -47,8 +48,8 @@ public static boolean compareTagData(ItemStack i1, ItemStack i2) { return false; } if (i1.hasItemMeta() && i2.hasItemMeta()) { - NBTTagCompound tag1 = CraftItemStack.asNMSCopy(i1).getTag(); - NBTTagCompound tag2 = CraftItemStack.asNMSCopy(i2).getTag(); + CompoundTag tag1 = CraftItemStack.asNMSCopy(i1).getTag(); + CompoundTag tag2 = CraftItemStack.asNMSCopy(i2).getTag(); if (tag1 != null) { if (tag1.equals(tag2)) { diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/ItemStackNBTConverter.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/ItemStackNBTConverter.java index d1b6cdcada..36a497d3bd 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/ItemStackNBTConverter.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/util/inventory/ItemStackNBTConverter.java @@ -23,6 +23,7 @@ import de.Keyle.MyPet.api.util.Compat; import de.Keyle.MyPet.api.util.ReflectionUtil; import de.keyle.knbt.*; +import de.keyle.knbt.TagType; import net.minecraft.nbt.*; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; @@ -35,55 +36,55 @@ @Compat("v1_17_R1") public class ItemStackNBTConverter { - private static final Field TAG_LIST_LIST = ReflectionUtil.getField(NBTTagList.class, "list"); + private static final Field TAG_LIST_LIST = ReflectionUtil.getField(ListTag.class, "list"); public static TagCompound itemStackToCompound(org.bukkit.inventory.ItemStack itemStack) { return itemStackToCompound(CraftItemStack.asNMSCopy(itemStack)); } public static TagCompound itemStackToCompound(ItemStack itemStack) { - NBTTagCompound tagCompound = new NBTTagCompound(); + CompoundTag tagCompound = new CompoundTag(); itemStack.save(tagCompound); return (TagCompound) vanillaCompoundToCompound(tagCompound); } public static ItemStack compoundToItemStack(TagCompound compound) { - NBTTagCompound tagCompound = (NBTTagCompound) compoundToVanillaCompound(compound); - return ItemStack.a(tagCompound); + CompoundTag tagCompound = (CompoundTag) compoundToVanillaCompound(compound); + return ItemStack.of(tagCompound); } - public static NBTBase compoundToVanillaCompound(TagBase tag) { + public static Tag compoundToVanillaCompound(TagBase tag) { switch (TagType.getTypeById(tag.getTagTypeId())) { case Int: - return NBTTagInt.a(((TagInt) tag).getIntData()); + return IntTag.valueOf(((TagInt) tag).getIntData()); case Short: - return NBTTagShort.a(((TagShort) tag).getShortData()); + return ShortTag.valueOf(((TagShort) tag).getShortData()); case String: - return NBTTagString.a(((TagString) tag).getStringData()); + return StringTag.valueOf(((TagString) tag).getStringData()); case Byte: - return NBTTagByte.a(((TagByte) tag).getByteData()); + return ByteTag.valueOf(((TagByte) tag).getByteData()); case Byte_Array: - return new NBTTagByteArray(((TagByteArray) tag).getByteArrayData()); + return new ByteArrayTag(((TagByteArray) tag).getByteArrayData()); case Double: - return NBTTagDouble.a(((TagDouble) tag).getDoubleData()); + return DoubleTag.valueOf(((TagDouble) tag).getDoubleData()); case Float: - return NBTTagFloat.a(((TagFloat) tag).getFloatData()); + return FloatTag.valueOf(((TagFloat) tag).getFloatData()); case Int_Array: - return new NBTTagIntArray(((TagIntArray) tag).getIntArrayData()); + return new IntArrayTag(((TagIntArray) tag).getIntArrayData()); case Long: - return NBTTagLong.a(((TagLong) tag).getLongData()); + return LongTag.valueOf(((TagLong) tag).getLongData()); case List: TagList TagList = (TagList) tag; - NBTTagList tagList = new NBTTagList(); + ListTag tagList = new ListTag(); for (TagBase tagInList : TagList.getReadOnlyList()) { tagList.add(compoundToVanillaCompound(tagInList)); } return tagList; case Compound: TagCompound TagCompound = (TagCompound) tag; - NBTTagCompound tagCompound = new NBTTagCompound(); + CompoundTag tagCompound = new CompoundTag(); for (String name : TagCompound.getCompoundData().keySet()) { - tagCompound.set(name, compoundToVanillaCompound(TagCompound.getCompoundData().get(name))); + tagCompound.put(name, compoundToVanillaCompound(TagCompound.getCompoundData().get(name))); } return tagCompound; case End: @@ -92,31 +93,31 @@ public static NBTBase compoundToVanillaCompound(TagBase tag) { throw new IllegalArgumentException("Not a valid tag type"); } - public static TagBase vanillaCompoundToCompound(NBTBase vanillaTag) { - switch (vanillaTag.getTypeId()) { + public static TagBase vanillaCompoundToCompound(Tag vanillaTag) { + switch (vanillaTag.getId()) { case 1: - return new TagByte(((NBTTagByte) vanillaTag).asByte()); + return new TagByte(((ByteTag) vanillaTag).getAsByte()); case 2: - return new TagShort(((NBTTagShort) vanillaTag).asShort()); + return new TagShort(((ShortTag) vanillaTag).getAsShort()); case 3: - return new TagInt(((NBTTagInt) vanillaTag).asInt()); + return new TagInt(((IntTag) vanillaTag).getAsInt()); case 4: - return new TagLong(((NBTTagLong) vanillaTag).asLong()); + return new TagLong(((LongTag) vanillaTag).getAsLong()); case 5: - return new TagFloat(((NBTTagFloat) vanillaTag).asFloat()); + return new TagFloat(((FloatTag) vanillaTag).getAsFloat()); case 6: - return new TagDouble(((NBTTagDouble) vanillaTag).asDouble()); + return new TagDouble(((DoubleTag) vanillaTag).getAsDouble()); case 7: - return new TagByteArray(((NBTTagByteArray) vanillaTag).getBytes()); + return new TagByteArray(((ByteArrayTag) vanillaTag).getAsByteArray()); case 8: - return new TagString(vanillaTag.asString()); + return new TagString(vanillaTag.getAsString()); case 9: - NBTTagList tagList = (NBTTagList) vanillaTag; + ListTag tagList = (ListTag) vanillaTag; List compoundList = new ArrayList(); try { ArrayList list = (ArrayList) TAG_LIST_LIST.get(tagList); for (Object aList : list) { - compoundList.add(vanillaCompoundToCompound((NBTBase) aList)); + compoundList.add(vanillaCompoundToCompound((Tag) aList)); } } catch (IllegalAccessException e) { e.printStackTrace(); @@ -125,14 +126,14 @@ public static TagBase vanillaCompoundToCompound(NBTBase vanillaTag) { return new TagList(compoundList); case 10: TagCompound compound = new TagCompound(); - NBTTagCompound tagCompound = ((NBTTagCompound) vanillaTag); - Set keys = tagCompound.getKeys(); + CompoundTag tagCompound = ((CompoundTag) vanillaTag); + Set keys = tagCompound.getAllKeys(); for (String tagName : keys) { compound.getCompoundData().put(tagName, vanillaCompoundToCompound(tagCompound.get(tagName))); } return compound; case 11: - return new TagIntArray(((NBTTagIntArray) vanillaTag).getInts()); + return new TagIntArray(((TagIntArray) vanillaTag).getIntArrayData()); } return null; } diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/CraftMyPet.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/CraftMyPet.java index 0a91722049..b8a82f8816 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/CraftMyPet.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/CraftMyPet.java @@ -153,7 +153,7 @@ public void forgetTarget() { } public void setTarget(LivingEntity target, TargetPriority priority) { - getHandle().setTarget(target, priority); + getHandle().setMyPetTarget(target, priority); } @Override diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/EntityMyPet.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/EntityMyPet.java index a193f3537d..315e880da9 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/EntityMyPet.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/EntityMyPet.java @@ -190,7 +190,8 @@ public TargetPriority getTargetPriority() { return targetPriority; } - public LivingEntity getTarget() { + @Override + public LivingEntity getMyPetTarget() { if (target != null) { if (target.isAlive()) { return (LivingEntity) target.getBukkitEntity(); @@ -200,7 +201,8 @@ public LivingEntity getTarget() { return null; } - public void setTarget(LivingEntity entity, TargetPriority priority) { + @Override + public void setMyPetTarget(LivingEntity entity, TargetPriority priority) { if (entity == null || entity.isDead() || entity instanceof ArmorStand || !(entity instanceof CraftLivingEntity)) { forgetTarget(); return; diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/attack/MeleeAttack.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/attack/MeleeAttack.java index 90e70f3114..a7a406927e 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/attack/MeleeAttack.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/attack/MeleeAttack.java @@ -61,7 +61,7 @@ public boolean shouldStart() { if (!this.petEntity.hasTarget()) { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (targetEntity instanceof EntityArmorStand) { return false; @@ -95,7 +95,7 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!this.petEntity.hasTarget() || !this.petEntity.canMove()) { return true; - } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getTarget()) { + } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getMyPetTarget()) { return true; } if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.f(targetEntity.locX, targetEntity.getBoundingBox().b, targetEntity.locZ) >= 20) { diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/attack/RangedAttack.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/attack/RangedAttack.java index cccf19da5f..8e08b2f4c0 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/attack/RangedAttack.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/attack/RangedAttack.java @@ -63,7 +63,7 @@ public boolean shouldStart() { return false; } - EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getMyPetTarget()).getHandle(); if (target instanceof EntityArmorStand) { return false; @@ -102,7 +102,7 @@ public boolean shouldFinish() { if (!entityMyPet.hasTarget() || myPet.getRangedDamage() <= 0 || !entityMyPet.canMove()) { return true; } - if (this.target.getBukkitEntity() != this.entityMyPet.getTarget()) { + if (this.target.getBukkitEntity() != this.entityMyPet.getMyPetTarget()) { return true; } double meleeDamage = myPet.getDamage(); diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/EatGrass.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/EatGrass.java index e2ad1ca57d..940e3c6f4a 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/EatGrass.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/EatGrass.java @@ -53,7 +53,7 @@ public boolean shouldStart() { return false; } else if (entityMySheep.getRandom().nextInt(1000) != 0) { return false; - } else if (this.entityMySheep.getTarget() != null && !this.entityMySheep.getTarget().isDead()) { + } else if (this.entityMySheep.getMyPetTarget() != null && !this.entityMySheep.getMyPetTarget().isDead()) { return false; } int blockLocX = MathHelper.floor(this.entityMySheep.locX); diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/FollowOwner.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/FollowOwner.java index b8111f9be7..029a08ab71 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/FollowOwner.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/FollowOwner.java @@ -59,7 +59,7 @@ public boolean shouldStart() { } if (!this.petEntity.canMove()) { return false; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } else if (this.petEntity.getOwner() == null) { return false; @@ -81,7 +81,7 @@ public boolean shouldFinish() { return true; } else if (!this.petEntity.canMove()) { return true; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return true; } return false; diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/LookAtPlayer.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/LookAtPlayer.java index a016712f69..d8c01c94d5 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/LookAtPlayer.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/LookAtPlayer.java @@ -50,7 +50,7 @@ public boolean shouldStart() { if (this.petEntity.getRandom().nextFloat() >= this.lookAtPlayerChance) { return false; } - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.passenger != null) { diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/RandomLookaround.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/RandomLookaround.java index 343472761d..881eb352c5 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/RandomLookaround.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/RandomLookaround.java @@ -37,7 +37,7 @@ public RandomLookaround(EntityMyPet petEntity) { @Override public boolean shouldStart() { - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.passenger != null) { diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/Sprint.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/Sprint.java index 532009e94e..f3ef7ba4fd 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/Sprint.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/movement/Sprint.java @@ -58,7 +58,7 @@ public boolean shouldStart() { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!targetEntity.isAlive()) { return false; diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorAggressiveTarget.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorAggressiveTarget.java index e863693eef..3b0ee20d1f 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorAggressiveTarget.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorAggressiveTarget.java @@ -107,11 +107,11 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!petEntity.canMove()) { return true; - } else if (petEntity.getTarget() == null) { + } else if (petEntity.getMyPetTarget() == null) { return true; } - EntityLiving target = ((CraftLivingEntity) petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -133,7 +133,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); } @Override diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorDuelTarget.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorDuelTarget.java index 77aff794c2..c73b3cc2b6 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorDuelTarget.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorDuelTarget.java @@ -99,7 +99,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); Behavior behaviorSkill = myPet.getSkills().get(Behavior.class); if (behaviorSkill.getBehavior() != BehaviorMode.Duel) { @@ -118,7 +118,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget(this.target.getBukkitEntity(), TargetPriority.Duel); + petEntity.setMyPetTarget(this.target.getBukkitEntity(), TargetPriority.Duel); setDuelOpponent(this.target); if (target.getTargetSelector().hasGoal("DuelTarget")) { BehaviorDuelTarget duelGoal = (BehaviorDuelTarget) target.getTargetSelector().getGoal("DuelTarget"); diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorFarmTarget.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorFarmTarget.java index 64e7276c81..ea6769d56d 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorFarmTarget.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/BehaviorFarmTarget.java @@ -87,7 +87,7 @@ public boolean shouldFinish() { if (!this.petEntity.hasTarget()) { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -109,7 +109,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); } @Override diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/ControlTarget.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/ControlTarget.java index f10ebc7c93..dc8779518d 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/ControlTarget.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/ControlTarget.java @@ -129,7 +129,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -143,7 +143,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); } @Override diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/HurtByTarget.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/HurtByTarget.java index 9795381a12..9cff3b369b 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/HurtByTarget.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/HurtByTarget.java @@ -98,7 +98,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -112,7 +112,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); } @Override diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/OwnerHurtByTarget.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/OwnerHurtByTarget.java index dbbc0f2063..6ee2d2108f 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/OwnerHurtByTarget.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/ai/target/OwnerHurtByTarget.java @@ -125,7 +125,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -139,7 +139,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); + petEntity.setMyPetTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); } @Override diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMyMagmaCube.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMyMagmaCube.java index e15f400446..226b5ab0b4 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMyMagmaCube.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMyMagmaCube.java @@ -60,7 +60,7 @@ public void onLivingUpdate() { if (this.onGround && jumpDelay-- <= 0) { getControllerJump().a(); jumpDelay = (this.random.nextInt(20) + 10); - if (getTarget() != null) { + if (getMyPetTarget() != null) { jumpDelay /= 3; } makeSound(getDeathSound(), 1.0F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F); diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMyRabbit.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMyRabbit.java index ba222dcd31..a2458453d6 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMyRabbit.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMyRabbit.java @@ -101,7 +101,7 @@ public void onLivingUpdate() { if (this.onGround && getNavigation().j() != null && jumpDelay-- <= 0) { getControllerJump().a(); jumpDelay = (this.random.nextInt(10) + 10); - if (getTarget() != null) { + if (getMyPetTarget() != null) { jumpDelay /= 3; } this.world.broadcastEntityEffect(this, (byte) 1); diff --git a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMySlime.java b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMySlime.java index 69118bc5dc..05f4f877de 100644 --- a/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMySlime.java +++ b/modules/v1_8_R3/src/main/java/de/Keyle/MyPet/compat/v1_8_R3/entity/types/EntityMySlime.java @@ -75,7 +75,7 @@ public void onLivingUpdate() { if (this.onGround && jumpDelay-- <= 0) { getControllerJump().a(); jumpDelay = (this.random.nextInt(20) + 10); - if (getTarget() != null) { + if (getMyPetTarget() != null) { jumpDelay /= 3; } makeSound(getDeathSound(), 1.0F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F); diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/CraftMyPet.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/CraftMyPet.java index e148e4da75..c0a468c739 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/CraftMyPet.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/CraftMyPet.java @@ -130,7 +130,7 @@ public void forgetTarget() { } public void setTarget(LivingEntity target, TargetPriority priority) { - getHandle().setTarget(target, priority); + getHandle().setMyPetTarget(target, priority); } @Override diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/EntityMyPet.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/EntityMyPet.java index d321b28f15..d173740dee 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/EntityMyPet.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/EntityMyPet.java @@ -197,8 +197,9 @@ public boolean hasTarget() { public TargetPriority getTargetPriority() { return targetPriority; } - - public LivingEntity getTarget() { + + @Override + public LivingEntity getMyPetTarget() { if (target != null) { if (target.isAlive()) { return (LivingEntity) target.getBukkitEntity(); @@ -208,7 +209,8 @@ public LivingEntity getTarget() { return null; } - public void setTarget(LivingEntity entity, TargetPriority priority) { + @Override + public void setMyPetTarget(LivingEntity entity, TargetPriority priority) { if (entity == null || entity.isDead() || entity instanceof ArmorStand || !(entity instanceof CraftLivingEntity)) { forgetTarget(); return; diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/attack/MeleeAttack.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/attack/MeleeAttack.java index 576157ffa4..2692607091 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/attack/MeleeAttack.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/attack/MeleeAttack.java @@ -58,7 +58,7 @@ public boolean shouldStart() { if (!this.petEntity.hasTarget()) { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (targetEntity instanceof EntityArmorStand) { return false; @@ -92,7 +92,7 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!this.petEntity.hasTarget() || !this.petEntity.canMove()) { return true; - } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getTarget()) { + } else if (this.targetEntity.getBukkitEntity() != this.petEntity.getMyPetTarget()) { return true; } if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.f(targetEntity.locX, targetEntity.getBoundingBox().b, targetEntity.locZ) >= 20) { diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/attack/RangedAttack.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/attack/RangedAttack.java index 362c4e0100..915f67d842 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/attack/RangedAttack.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/attack/RangedAttack.java @@ -63,7 +63,7 @@ public boolean shouldStart() { return false; } - EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.entityMyPet.getMyPetTarget()).getHandle(); if (target instanceof EntityArmorStand) { return false; @@ -102,7 +102,7 @@ public boolean shouldFinish() { if (!entityMyPet.hasTarget() || myPet.getRangedDamage() <= 0 || !entityMyPet.canMove()) { return true; } - if (this.target.getBukkitEntity() != entityMyPet.getTarget()) { + if (this.target.getBukkitEntity() != entityMyPet.getMyPetTarget()) { return true; } double meleeDamage = myPet.getDamage(); diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/EatGrass.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/EatGrass.java index 6c806f01fb..da522dc461 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/EatGrass.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/EatGrass.java @@ -53,7 +53,7 @@ public boolean shouldStart() { return false; } else if (entityMySheep.getRandom().nextInt(1000) != 0) { return false; - } else if (this.entityMySheep.getTarget() != null && !this.entityMySheep.getTarget().isDead()) { + } else if (this.entityMySheep.getMyPetTarget() != null && !this.entityMySheep.getMyPetTarget().isDead()) { return false; } int blockLocX = MathHelper.floor(this.entityMySheep.locX); diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/FollowOwner.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/FollowOwner.java index fa50ceb8ab..040ea70603 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/FollowOwner.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/FollowOwner.java @@ -59,7 +59,7 @@ public boolean shouldStart() { } if (!this.petEntity.canMove()) { return false; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } else if (this.petEntity.getOwner() == null) { return false; @@ -81,7 +81,7 @@ public boolean shouldFinish() { return true; } else if (!this.petEntity.canMove()) { return true; - } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + } else if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return true; } return false; diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/LookAtPlayer.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/LookAtPlayer.java index 7b4a1842c0..3cd0ee1beb 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/LookAtPlayer.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/LookAtPlayer.java @@ -50,7 +50,7 @@ public boolean shouldStart() { if (this.petEntity.getRandom().nextFloat() >= this.lookAtPlayerChance) { return false; } - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/RandomLookaround.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/RandomLookaround.java index 46b0cb6203..ab2f337fb3 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/RandomLookaround.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/RandomLookaround.java @@ -37,7 +37,7 @@ public RandomLookaround(EntityMyPet petEntity) { @Override public boolean shouldStart() { - if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { + if (this.petEntity.getMyPetTarget() != null && !this.petEntity.getMyPetTarget().isDead()) { return false; } if (this.petEntity.isVehicle()) { diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/Sprint.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/Sprint.java index 7e7bdf2740..bb8d7c75b2 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/Sprint.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/movement/Sprint.java @@ -58,7 +58,7 @@ public boolean shouldStart() { return false; } - EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!targetEntity.isAlive()) { return false; diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorAggressiveTarget.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorAggressiveTarget.java index 9131b5ac51..0a958a1f55 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorAggressiveTarget.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorAggressiveTarget.java @@ -107,11 +107,11 @@ public boolean shouldStart() { public boolean shouldFinish() { if (!petEntity.canMove()) { return true; - } else if (petEntity.getTarget() == null) { + } else if (petEntity.getMyPetTarget() == null) { return true; } - EntityLiving target = ((CraftLivingEntity) petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -133,7 +133,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Aggressive); } @Override diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorDuelTarget.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorDuelTarget.java index c12a4682e6..03b48acd73 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorDuelTarget.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorDuelTarget.java @@ -99,7 +99,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); Behavior behaviorSkill = myPet.getSkills().get(Behavior.class); if (behaviorSkill.getBehavior() != BehaviorMode.Duel) { @@ -118,7 +118,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget(this.target.getBukkitEntity(), TargetPriority.Duel); + petEntity.setMyPetTarget(this.target.getBukkitEntity(), TargetPriority.Duel); setDuelOpponent(this.target); if (target.getTargetSelector().hasGoal("DuelTarget")) { BehaviorDuelTarget duelGoal = (BehaviorDuelTarget) target.getTargetSelector().getGoal("DuelTarget"); diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorFarmTarget.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorFarmTarget.java index a4322dbeb5..6ca279b0ef 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorFarmTarget.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/BehaviorFarmTarget.java @@ -87,7 +87,7 @@ public boolean shouldFinish() { if (!this.petEntity.hasTarget()) { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (!target.isAlive()) { return true; @@ -109,7 +109,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Farm); } @Override diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/ControlTarget.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/ControlTarget.java index 9d24199a3b..ab2199dfc5 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/ControlTarget.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/ControlTarget.java @@ -129,7 +129,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -143,7 +143,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.Control); } @Override diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/HurtByTarget.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/HurtByTarget.java index 2a18ecf4e7..061a2c4464 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/HurtByTarget.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/HurtByTarget.java @@ -98,7 +98,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -112,7 +112,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); + petEntity.setMyPetTarget((LivingEntity) this.target.getBukkitEntity(), TargetPriority.GetHurt); } @Override diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/OwnerHurtByTarget.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/OwnerHurtByTarget.java index 4137d009fd..66095dba65 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/OwnerHurtByTarget.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/ai/target/OwnerHurtByTarget.java @@ -125,7 +125,7 @@ public boolean shouldFinish() { return true; } - EntityLiving target = ((CraftLivingEntity) this.petEntity.getTarget()).getHandle(); + EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle(); if (target.world != petEntity.world) { return true; @@ -139,7 +139,7 @@ public boolean shouldFinish() { @Override public void start() { - petEntity.setTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); + petEntity.setMyPetTarget((LivingEntity) this.lastDamager.getBukkitEntity(), TargetPriority.OwnerGetsHurt); } @Override diff --git a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/types/EntityMyRabbit.java b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/types/EntityMyRabbit.java index 9ad243cb25..142f51186c 100644 --- a/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/types/EntityMyRabbit.java +++ b/modules/v1_9_R2/src/main/java/de/Keyle/MyPet/compat/v1_9_R2/entity/types/EntityMyRabbit.java @@ -97,7 +97,7 @@ public void onLivingUpdate() { if (this.onGround && getNavigation().k() != null && jumpDelay-- <= 0) { getControllerJump().a(); jumpDelay = (this.random.nextInt(10) + 10); - if (getTarget() != null) { + if (getMyPetTarget() != null) { jumpDelay /= 3; } this.world.broadcastEntityEffect(this, (byte) 1); diff --git a/pom.xml b/pom.xml index fb4115e83d..c91653f549 100644 --- a/pom.xml +++ b/pom.xml @@ -31,11 +31,11 @@ modules/API modules/Skills - modules/v1_16_R3 modules/v1_8_R3 modules/v1_9_R2 modules/v1_12_R1 modules/v1_16_R1 + modules/v1_16_R3 modules/v1_17_R1 modules/GUI modules/Plugin