From 6ae1170e128c984367e427fc227323594ef89624 Mon Sep 17 00:00:00 2001 From: Checkium Folf Date: Fri, 21 Feb 2020 23:12:03 +0000 Subject: [PATCH 1/4] New way of implementing foxes --- .gitignore | 2 +- .idea/misc.xml | 5 +- .idea/workspace.xml | 234 +++++-- pom.xml | 19 +- .../tamablefoxes/EntityTamableFox.java | 598 +++++++++++------- .../seanomik/tamablefoxes/TamableFoxes.java | 148 ----- .../java/net/seanomik/tamablefoxes/Utils.java | 52 -- .../command/CommandSpawnTamableFox.java | 4 - .../FoxPathfinderGoalFollowOwner.java | 2 +- .../FoxPathfinderGoalMeleeAttack.java | 2 +- .../FoxPathfinderGoalOwnerHurtByTarget.java | 2 +- .../FoxPathfinderGoalOwnerHurtTarget.java | 23 +- src/main/resources/config.yml | 2 +- src/main/resources/plugin.yml | 2 +- target/classes/config.yml | 4 +- target/classes/plugin.yml | 4 +- target/maven-archiver/pom.properties | 4 +- .../compile/default-compile/createdFiles.lst | 1 - .../compile/default-compile/inputFiles.lst | 26 +- 19 files changed, 617 insertions(+), 517 deletions(-) diff --git a/.gitignore b/.gitignore index 79b82c9..de0e2c8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ ### Intellij ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - +.idea .idea/** # User-specific stuff diff --git a/.idea/misc.xml b/.idea/misc.xml index 6fb7c97..28ed9dc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,6 +5,9 @@ + + - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0f2d175..ac27c62 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,24 @@ - + + + + + + + + + + + + + + @@ -14,6 +27,11 @@ + + + + + - - - - + + + + + + + + + + + + - + @@ -57,26 +83,26 @@ - - - - + + + + + + - + + - + + + + + + + + + + - - + + - + + + - - + + - + + + - - + + - + + + - - + + - + + + - - + + - - - + + + + + - - - + + + + + - - - + + + + + - + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + @@ -220,11 +334,28 @@ - + + + + + + + + + + + + + + + + + + @@ -234,4 +365,25 @@ + + + + + file://$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java + 219 + + + file://$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java + 220 + + + file://$PROJECT_DIR$/src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java + 110 + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 94a32af..2999840 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.seanomik tamablefoxes - 1.5.2-SNAPSHOT + 1.6.0-SNAPSHOT jar Tamablefoxes @@ -40,7 +40,7 @@ - D:\Code\java\spigotPlugins\_TEST_SERVER_1.15.2_\plugins\TamableFoxes-MC-v1.15.X-v${project.version}.jar + C:\Users\Checkium\Desktop\vps\smp\SMP\plugins\TamableFoxes-MC-v1.15.X-v${project.version}.jar false @@ -71,23 +71,18 @@ - + + org.spigotmc spigot system 1.15.2 - ${project.basedir}/../spigot-1.15.2.jar - --> - - com.github.WesJD.AnvilGUI - anvilgui - 478e0c1 + C:/Users/Checkium/Desktop/Servers/SMP/cache/patched_1.15.2.jar diff --git a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java index c8a5a47..7a97acf 100644 --- a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java +++ b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java @@ -2,57 +2,131 @@ package net.seanomik.tamablefoxes; import net.minecraft.server.v1_15_R1.*; import net.seanomik.tamablefoxes.io.Config; -import net.seanomik.tamablefoxes.io.LanguageConfig; import net.seanomik.tamablefoxes.versions.version_1_15.pathfinding.*; -import org.bukkit.NamespacedKey; -import org.bukkit.OfflinePlayer; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; +import org.apache.commons.lang.reflect.FieldUtils; +import org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_15_R1.persistence.CraftPersistentDataContainer; -import org.bukkit.entity.Item; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; -import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import javax.annotation.Nullable; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.*; public class EntityTamableFox extends EntityFox { - List untamedGoals = new ArrayList<>(); - private boolean tamed; - private boolean sitting; - private EntityLiving owner; - private UUID ownerUUID; + protected static final DataWatcherObject tamed; + protected static final DataWatcherObject> ownerUUID; + + static { + tamed = DataWatcher.a(EntityTamableFox.class, DataWatcherRegistry.a); + ownerUUID = DataWatcher.a(EntityTamableFox.class, DataWatcherRegistry.o); + } + + List untamedGoals; private FoxPathfinderGoalSit goalSit; public EntityTamableFox(EntityTypes entitytypes, World world) { super(entitytypes, world); - - clearPathFinderGoals(); - initPathfinderGoals(); + // clearPathFinderGoals(); + //initPathfinderGoals(); } - public static Object getPrivateField(String fieldName, Class clazz, Object object) { - Field field; - Object o = null; + @Override + public void initPathfinder() { try { - field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); - o = field.get(object); - } catch (NoSuchFieldException | IllegalAccessException e) { + this.goalSelector.a(0, getFoxInnerPathfinderGoal("g")); // FloatGoal + + this.goalSit = new FoxPathfinderGoalSit(this); + this.goalSelector.a(1, goalSit); + + this.goalSelector.a(2, getFoxInnerPathfinderGoal("b")); // FaceplantGoal + this.goalSelector.a(3, new FoxPathfinderGoalPanic(this, 2.2D)); // PanicGoal + this.goalSelector.a(4, getFoxInnerPathfinderGoal("e", Arrays.asList(1.0D), Arrays.asList(double.class))); // BreedGoal + + // Avoid human only if not tamed + this.goalSelector.a(5, new PathfinderGoalAvoidTarget(this, EntityHuman.class, 16.0F, 1.6D, 1.4D, (entityliving) -> !isTamed())); + + // Avoid wolf if it is not tamed + this.goalSelector.a(5, new PathfinderGoalAvoidTarget(this, EntityWolf.class, 8.0F, 1.6D, 1.4D, (entityliving) -> { + try { + Method eFMethod = EntityFox.class.getDeclaredMethod("eF"); + eFMethod.setAccessible(true); + boolean eF = (boolean) eFMethod.invoke(this); + eFMethod.setAccessible(false); + + return !((EntityWolf) entityliving).isTamed() && !eF; + } catch (Exception e) { + return !((EntityWolf) entityliving).isTamed(); + } + })); + + this.goalSelector.a(8, new FoxPathfinderGoalMeleeAttack(this, 1.2000000476837158D, true)); + this.goalSelector.a(9, new FoxPathfinderGoalFollowOwner(this, 1.3D, 10.0F, 2.0F, false)); + this.goalSelector.a(6, getFoxInnerPathfinderGoal("u")); // StalkPrey + this.goalSelector.a(7, new EntityFox.o()); // Pounce + + this.goalSelector.a(9, getFoxInnerPathfinderGoal("h", Arrays.asList(this, 1.25D), Arrays.asList(EntityFox.class, double.class))); // FollowParent + + this.goalSelector.a(11, new PathfinderGoalLeapAtTarget(this, 0.4F)); + this.goalSelector.a(12, new PathfinderGoalRandomStrollLand(this, 1.15D)); + + this.goalSelector.a(12, getFoxInnerPathfinderGoal("p")); // SearchForItems + this.goalSelector.a(13, getFoxInnerPathfinderGoal("j", Arrays.asList(this, EntityHuman.class, 24.0f), Arrays.asList(EntityInsentient.class, Class.class, float.class))); // LookAtPlayer + + this.targetSelector.a(1, new FoxPathfinderGoalOwnerHurtByTarget(this)); + this.targetSelector.a(2, new FoxPathfinderGoalOwnerHurtTarget(this)); + this.targetSelector.a(3, (new FoxPathfinderGoalHurtByTarget(this, new Class[0])).a(new Class[0])); + + // Wild animal attacking + Field bE = this.getClass().getSuperclass().getDeclaredField("bE"); + bE.setAccessible(true); + bE.set(this, new PathfinderGoalNearestAttackableTarget(this, EntityAnimal.class, 10, false, false, (entityliving) -> { + return (!isTamed() || (Config.doesTamedAttackWildAnimals() && isTamed())) && (entityliving instanceof EntityChicken || entityliving instanceof EntityRabbit); + })); + + Field bF = this.getClass().getSuperclass().getDeclaredField("bF"); + bF.setAccessible(true); + bF.set(this, new PathfinderGoalNearestAttackableTarget(this, EntityTurtle.class, 10, false, false, (entityLiving) -> { + return (!isTamed() || (Config.doesTamedAttackWildAnimals() && isTamed())) && EntityTurtle.bw.test((EntityLiving) entityLiving); + })); + + Field bG = this.getClass().getSuperclass().getDeclaredField("bG"); + bG.setAccessible(true); + bG.set(this, new PathfinderGoalNearestAttackableTarget(this, EntityFish.class, 20, false, false, (entityliving) -> { + return (!isTamed() || (Config.doesTamedAttackWildAnimals() && isTamed())) && entityliving instanceof EntityFishSchool; + })); + + + + untamedGoals = new ArrayList<>(); + + // Sleep + PathfinderGoal sleep = getFoxInnerPathfinderGoal("t"); + this.goalSelector.a(8, sleep); + untamedGoals.add(sleep); + + // PerchAndSearch (Random sitting?) + PathfinderGoal perchAndSearch = getFoxInnerPathfinderGoal("r"); + this.goalSelector.a(14, perchAndSearch); + untamedGoals.add(perchAndSearch); + + // EatBerries (Pick berry bushes) + PathfinderGoal eatBerries = new EntityFox.f(1.2000000476837158D, 12, 2); + this.goalSelector.a(11, eatBerries); + untamedGoals.add(eatBerries); // Maybe this should be configurable too? + + PathfinderGoal seekShelter = getFoxInnerPathfinderGoal("s", Arrays.asList(1.25D), Arrays.asList(double.class)); + this.goalSelector.a(7, seekShelter); // SeekShelter + untamedGoals.add(seekShelter); + + PathfinderGoal strollThroughVillage = getFoxInnerPathfinderGoal("q", Arrays.asList(32, 200), Arrays.asList(int.class, int.class)); + this.goalSelector.a(10, strollThroughVillage); // StrollThroughVillage + untamedGoals.add(strollThroughVillage); + + } catch (Exception e) { e.printStackTrace(); } - return o; - } - - private PathfinderGoal getFoxInnerPathfinderGoal(String innerName, List args, List> argTypes) { - return (PathfinderGoal) Utils.instantiatePrivateInnerClass(EntityFox.class, innerName, this, args, argTypes); - } - - private PathfinderGoal getFoxInnerPathfinderGoal(String innerName) { - return (PathfinderGoal) Utils.instantiatePrivateInnerClass(EntityFox.class, innerName, this, Arrays.asList(), Arrays.asList()); } @Override @@ -70,87 +144,284 @@ public class EntityTamableFox extends EntityFox { this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.30000001192092896D); - // Default value is 10, might want to make this configurable in the future - this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(24.0D); - - // Default value is 2, might want to make this configurable in the future - this.getAttributeMap().b(GenericAttributes.ATTACK_DAMAGE).setValue(3.0D); + if (!isTamed()) { + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(10.0D); + this.getAttributeMap().b(GenericAttributes.ATTACK_DAMAGE).setValue(2.0D); + } else { + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(24.0D); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(3.0D); + } } - private void initPathfinderGoals() { + public static Object getPrivateField(String fieldName, Class clazz, Object object) { + Field field; + Object o = null; try { - this.goalSelector.a(0, getFoxInnerPathfinderGoal("g")); // FloatGoal - - this.goalSit = new FoxPathfinderGoalSit(this); - this.goalSelector.a(1, goalSit); - - this.goalSelector.a(1, getFoxInnerPathfinderGoal("b")); // FaceplantGoal - this.goalSelector.a(2, new FoxPathfinderGoalPanic(this, 2.2D)); // PanicGoal - this.goalSelector.a(3, getFoxInnerPathfinderGoal("e", Arrays.asList(1.0D), Arrays.asList(double.class))); // BreedGoal - - // Avoid human only if not tamed - this.goalSelector.a(4, new PathfinderGoalAvoidTarget(this, EntityHuman.class, 16.0F, 1.6D, 1.4D, (entityliving) -> !tamed)); - - // Avoid wolf if it is not tamed - this.goalSelector.a(4, new PathfinderGoalAvoidTarget(this, EntityWolf.class, 8.0F, 1.6D, 1.4D, (entityliving) -> { - try { - Method eFMethod = EntityFox.class.getDeclaredMethod("eF"); - eFMethod.setAccessible(true); - boolean eF = (boolean) eFMethod.invoke(this); - eFMethod.setAccessible(false); - - return !((EntityWolf) entityliving).isTamed() && !eF; - } catch (Exception e) { - return !((EntityWolf) entityliving).isTamed(); - } - })); - - this.goalSelector.a(4, new FoxPathfinderGoalMeleeAttack(this, 1.2000000476837158D, true)); - this.goalSelector.a(5, new FoxPathfinderGoalFollowOwner(this, 1.3D, 10.0F, 2.0F, false)); - this.goalSelector.a(6, getFoxInnerPathfinderGoal("u")); // StalkPrey - this.goalSelector.a(7, new EntityFox.o()); // Pounce - - PathfinderGoal seekShelter = getFoxInnerPathfinderGoal("s", Arrays.asList(1.25D), Arrays.asList(double.class)); - this.goalSelector.a(7, seekShelter); // SeekShelter - untamedGoals.add(seekShelter); - - this.goalSelector.a(8, getFoxInnerPathfinderGoal("t")); // Sleep - this.goalSelector.a(9, getFoxInnerPathfinderGoal("h", Arrays.asList(this, 1.25D), Arrays.asList(EntityFox.class, double.class))); // FollowParent - - PathfinderGoal strollThroughVillage = getFoxInnerPathfinderGoal("q", Arrays.asList(32, 200), Arrays.asList(int.class, int.class)); - this.goalSelector.a(9, strollThroughVillage); // StrollThroughVillage - untamedGoals.add(strollThroughVillage); - - // EatBerries (Pick berry bushes) - PathfinderGoal eatBerries = new EntityFox.f(1.2000000476837158D, 12, 2); - this.goalSelector.a(10, eatBerries); - untamedGoals.add(eatBerries); // Maybe this should be configurable too? - - this.goalSelector.a(10, new PathfinderGoalLeapAtTarget(this, 0.4F)); - this.goalSelector.a(11, new PathfinderGoalRandomStrollLand(this, 1.15D)); - - this.goalSelector.a(11, getFoxInnerPathfinderGoal("p")); // SearchForItems - this.goalSelector.a(12, getFoxInnerPathfinderGoal("j", Arrays.asList(this, EntityHuman.class, 24.0f), Arrays.asList(EntityInsentient.class, Class.class, float.class))); // LookAtPlayer - - // PerchAndSearch (Random sitting?) - PathfinderGoal perchAndSearch = getFoxInnerPathfinderGoal("r"); - this.goalSelector.a(13, perchAndSearch); - untamedGoals.add(perchAndSearch); - - this.targetSelector.a(1, new FoxPathfinderGoalOwnerHurtByTarget(this)); - this.targetSelector.a(2, new FoxPathfinderGoalOwnerHurtTarget(this)); - this.targetSelector.a(3, (new FoxPathfinderGoalHurtByTarget(this, new Class[0])).a(new Class[0])); - - // Wild animal attacking - this.targetSelector.a(4, new PathfinderGoalNearestAttackableTarget(this, EntityLiving.class, 10, false, false, - entityLiving -> (!tamed || (Config.doesTamedAttackWildAnimals() && tamed)) && ( - entityLiving instanceof EntityChicken || - entityLiving instanceof EntityRabbit || - (entityLiving instanceof EntityTurtle && EntityTurtle.bw.test((EntityLiving) entityLiving)) || - entityLiving instanceof EntityFishSchool))); - } catch (Exception e) { + field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + o = field.get(object); + } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } + return o; + } + + protected void initDatawatcher() { + super.initDatawatcher(); + this.datawatcher.register(tamed, (byte) 0); + this.datawatcher.register(ownerUUID, Optional.empty()); + } + + // addAdditionalSaveData + public void b(NBTTagCompound compound) { + super.b(compound); + if (this.getOwnerUUID() == null) { + compound.setString("OwnerUUID", ""); + } else { + compound.setString("OwnerUUID", this.getOwnerUUID().toString()); + } + + compound.setBoolean("Sitting", this.isSitting()); + } + + // readAdditionalSaveData + public void a(NBTTagCompound compound) { + super.a(compound); + String ownerUuid; + if (compound.hasKeyOfType("OwnerUUID", 8)) { + ownerUuid = compound.getString("OwnerUUID"); + } else { + String var2 = compound.getString("Owner"); + ownerUuid = NameReferencingFileConverter.a(this.getMinecraftServer(), var2); + } + if (!ownerUuid.isEmpty()) { + try { + this.setOwnerUUID(UUID.fromString(ownerUuid)); + this.setTamed(true); + } catch (Throwable throwable) { + this.setTamed(false); + } + } + if (this.goalSit != null) { + this.goalSit.setSitting(compound.getBoolean("Sitting")); + } + this.setSitting(compound.getBoolean("Sitting")); + } + + public boolean isTamed() { + return ((Byte) this.datawatcher.get(tamed) & 4) != 0; + } + + public void setTamed(boolean tamed_) { + byte isTamed = this.datawatcher.get(tamed); + if (tamed_) { + this.datawatcher.set(tamed, (byte) (isTamed | 4)); + } else { + this.datawatcher.set(tamed, (byte) (isTamed & -5)); + } + this.reassessTameGoals(); + + if (tamed_) { + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(24.0D); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(3.0D); + this.setHealth(this.getMaxHealth()); + } else { + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(10.0D); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(2.0D); + } + } + + private void reassessTameGoals() { + if (!isTamed()) return; + for (PathfinderGoal untamedGoal : untamedGoals) { + this.goalSelector.a(untamedGoal); + } + } + + // deobf: mobInteract + public boolean a(EntityHuman entityhuman, EnumHand enumhand) { + ItemStack itemstack = entityhuman.b(enumhand); + Item item = itemstack.getItem(); + if (itemstack.getItem() instanceof ItemMonsterEgg) { + return super.a(entityhuman, enumhand); + } else { + if (this.isTamed()) { + if (item.isFood() && item.getFoodInfo().c() && this.getHealth() < this.getMaxHealth()) { + if (!entityhuman.abilities.canInstantlyBuild) { + itemstack.subtract(1); + } + this.heal((float)item.getFoodInfo().getNutrition(), EntityRegainHealthEvent.RegainReason.EATING); + return true; + } + + if (isOwnedBy(entityhuman)) { + boolean flag = super.a(entityhuman, enumhand); + if ((item == Items.AIR || !entityhuman.isSneaking()) && !flag || this.isBaby()) { + this.goalSit.setSitting(!this.isSitting()); + return flag; + } else if (entityhuman.isSneaking()) { + if (!this.getEquipment(EnumItemSlot.MAINHAND).isEmpty()) { + getBukkitEntity().getWorld().dropItem(getBukkitEntity().getLocation(), CraftItemStack.asBukkitCopy(this.getEquipment(EnumItemSlot.MAINHAND))); + this.setSlot(EnumItemSlot.MAINHAND, new ItemStack(Items.AIR)); + } + if (item != Items.AIR) { + ItemStack c = itemstack.cloneItemStack(); + c.setCount(1); + itemstack.subtract(1); + this.setSlot(EnumItemSlot.MAINHAND, c); + } + } + } + // TODO: take/give items + } else if (item == Items.SWEET_BERRIES) { + if (!entityhuman.abilities.canInstantlyBuild) { + itemstack.subtract(1); + } + if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { + this.tame(entityhuman); + this.navigation.o(); + this.setGoalTarget(null); + this.goalSit.setSitting(true); + getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.HEART, getBukkitEntity().getLocation(), 6, 0.5D, 0.5D, 0.5D); + } else { + getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); + } + return true; + } + + return super.a(entityhuman, enumhand); + } + } + + // deobf: isFood (used for breeding) + public boolean i(ItemStack itemstack) { + Item item = itemstack.getItem(); + return item.isFood() && item.getFoodInfo().c(); + } + + public EntityTamableFox createChild(EntityAgeable entityageable) { + EntityTamableFox entityFox = (EntityTamableFox) EntityTypes.FOX.a(this.world); + UUID uuid = this.getOwnerUUID(); + if (uuid != null) { + entityFox.setOwnerUUID(uuid); + entityFox.setTamed(true); + } + + return entityFox; + } + + public boolean mate(EntityAnimal entityanimal) { + if (entityanimal == this) { + return false; + } else if (!(entityanimal instanceof EntityTamableFox)) { + return false; + } else { + EntityTamableFox entitywolf = (EntityTamableFox)entityanimal; + return (!entitywolf.isSitting() && (this.isInLove() && entitywolf.isInLove())); + } + } + + @Nullable + public UUID getOwnerUUID() { + return (UUID) ((Optional) this.datawatcher.get(ownerUUID)).orElse(null); + } + + public void setOwnerUUID(@Nullable UUID ownerUuid) { + this.datawatcher.set(ownerUUID, Optional.ofNullable(ownerUuid)); + } + + public void tame(EntityHuman owner) { + this.setTamed(true); + this.setOwnerUUID(owner.getUniqueID()); + /* + * The following code appears to be for the taming advancement, will investigate how to change that in the future + if (owner instanceof EntityPlayer) { + CriterionTriggers.x.a((EntityPlayer)owner, this); + } + */ + } + + @Nullable + public EntityLiving getOwner() { + try { + UUID ownerUuid = this.getOwnerUUID(); + return ownerUuid == null ? null : this.world.b(ownerUuid); + } catch (IllegalArgumentException var2) { + return null; + } + } + + // deobf: canAttack + public boolean c(EntityLiving entity) { + return !this.isOwnedBy(entity) && super.c(entity); + } + + public boolean isOwnedBy(EntityLiving entity) { + return entity == this.getOwner(); + } + + /* + deobf: wantsToAttack (copied from EntityWolf) + This code being from EntityWolf also means that wolves will want to attack foxes + Our life would be so much easier if we could extend both EntityFox and EntityTameableAnimal + */ + public boolean a(EntityLiving entityliving, EntityLiving entityliving1) { + if (!(entityliving instanceof EntityCreeper) && !(entityliving instanceof EntityGhast)) { + if (entityliving instanceof EntityTamableFox) { + EntityTamableFox entityFox = (EntityTamableFox) entityliving; + return !entityFox.isTamed() || entityFox.getOwner() != entityliving1; + } else { + return (!(entityliving instanceof EntityHuman) + || !(entityliving1 instanceof EntityHuman) || + ((EntityHuman) entityliving1).a((EntityHuman) entityliving)) && ((!(entityliving instanceof EntityHorseAbstract) + || !((EntityHorseAbstract) entityliving).isTamed()) && (!(entityliving instanceof EntityTameableAnimal) + || !((EntityTameableAnimal) entityliving).isTamed())); + } + } else { + return false; + } + } + + public ScoreboardTeamBase getScoreboardTeam() { + if (this.isTamed()) { + EntityLiving var0 = this.getOwner(); + if (var0 != null) { + return var0.getScoreboardTeam(); + } + } + + return super.getScoreboardTeam(); + } + + // override isAlliedTo + public boolean r(Entity entity) { + if (this.isTamed()) { + EntityLiving entityOwner = this.getOwner(); + if (entity == entityOwner) { + return true; + } + if (entityOwner != null) { + return entityOwner.r(entity); + } + } + return super.r(entity); + } + + public void die(DamageSource damageSource) { + if (!this.world.isClientSide && this.world.getGameRules().getBoolean(GameRules.SHOW_DEATH_MESSAGES) && this.getOwner() instanceof EntityPlayer) { + this.getOwner().sendMessage(this.getCombatTracker().getDeathMessage()); + } + + super.die(damageSource); + } + + + private PathfinderGoal getFoxInnerPathfinderGoal(String innerName, List args, List> argTypes) { + return (PathfinderGoal) Utils.instantiatePrivateInnerClass(EntityFox.class, innerName, this, args, argTypes); + } + + private PathfinderGoal getFoxInnerPathfinderGoal(String innerName) { + return (PathfinderGoal) Utils.instantiatePrivateInnerClass(EntityFox.class, innerName, this, Arrays.asList(), Arrays.asList()); } private void clearPathFinderGoals() { @@ -170,113 +441,4 @@ public class EntityTamableFox extends EntityFox { targetEnumSet.clear(); } - public boolean isTamed() { - return tamed; - } - - public void setTamed(boolean tamed) { - this.tamed = tamed; - - // Remove goals that are not needed when named, or defeats the purpose of taming - untamedGoals.forEach(goal -> goalSelector.a(goal)); - } - - public EntityLiving getOwner() { - if (Objects.isNull(owner)) { - if (ownerUUID == null) return null; - OfflinePlayer opOwner = TamableFoxes.getPlugin().getServer().getOfflinePlayer(UUID.fromString(ownerUUID.toString())); - if (opOwner.isOnline()) this.owner = (EntityLiving) ((CraftEntity) opOwner).getHandle(); - } - return owner; - } - - public void setOwner(EntityLiving entityLiving) { - this.owner = entityLiving; - this.ownerUUID = entityLiving.getUniqueID(); - updateFoxVisual(); - } - - public void setOwnerUUID(UUID ownerUUID) { - this.ownerUUID = ownerUUID; - } - - public boolean isOtherFoxFamily(EntityLiving living) { - if (living instanceof EntityTamableFox) { - EntityTamableFox tamableFox = (EntityTamableFox) living; - - return (tamableFox.isTamed() && tamableFox.getOwner() != null && tamableFox.getOwner().getUniqueID() == this.getOwner().getUniqueID()); - } else { - return false; - } - } - - public void updateFoxVisual() { - new BukkitRunnable() { - @Override - public void run() { - goalSit.setSitting(sitting); - - if (tamed && owner != null && !hasCustomName() && Config.doesShowOwnerFoxName()) { - getBukkitEntity().setCustomName(LanguageConfig.getOwnerInFoxNameFormat().replaceAll("%player%", owner.getName())); - } - } - }.runTask(TamableFoxes.getPlugin()); - } - - public void setHardSitting(boolean hardSitting) { - super.setSitting(hardSitting); - this.sitting = hardSitting; - - if (super.isSleeping()) super.setSleeping(false); - - updateFoxVisual(); - } - - - public boolean toggleSitting() { - this.sitting = !this.sitting; - setHardSitting(sitting); - - return this.sitting; - } - - public ItemStack getMouthItem() { - return getEquipment(EnumItemSlot.MAINHAND); - } - - public void setMouthItem(ItemStack item) { - item.setCount(1); - setSlot(EnumItemSlot.MAINHAND, item); - saveNbt(); - } - - public void setMouthItem(org.bukkit.inventory.ItemStack item) { - ItemStack itemNMS = CraftItemStack.asNMSCopy(item); - setMouthItem(itemNMS); - } - - public org.bukkit.entity.Item dropMouthItem() { - Item droppedItem = getBukkitEntity().getWorld().dropItem(getBukkitEntity().getLocation(), CraftItemStack.asBukkitCopy(getMouthItem())); - setSlot(EnumItemSlot.MAINHAND, new net.minecraft.server.v1_15_R1.ItemStack(Items.AIR)); - - return droppedItem; - } - - public void saveNbt() { - NamespacedKey rootKey = new NamespacedKey(TamableFoxes.getPlugin(), "tamableFoxes"); - CraftPersistentDataContainer persistentDataContainer = getBukkitEntity().getPersistentDataContainer(); - PersistentDataContainer tamableFoxesData; - if (persistentDataContainer.has(rootKey, PersistentDataType.TAG_CONTAINER)) { - tamableFoxesData = persistentDataContainer.get(rootKey, PersistentDataType.TAG_CONTAINER); - } else { - tamableFoxesData = persistentDataContainer.getAdapterContext().newPersistentDataContainer(); - } - - NamespacedKey ownerKey = new NamespacedKey(TamableFoxes.getPlugin(), "owner"); - NamespacedKey sittingKey = new NamespacedKey(TamableFoxes.getPlugin(), "sitting"); - tamableFoxesData.set(ownerKey, PersistentDataType.STRING, getOwner() == null ? "none" : getOwner().getUniqueID().toString()); - tamableFoxesData.set(sittingKey, PersistentDataType.BYTE, (byte) (isSitting() ? 1 : 0)); - - persistentDataContainer.set(rootKey, PersistentDataType.TAG_CONTAINER, tamableFoxesData); - } } diff --git a/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java b/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java index 9fd64ca..7c0d600 100644 --- a/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java +++ b/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java @@ -4,7 +4,6 @@ import net.minecraft.server.v1_15_R1.*; import net.seanomik.tamablefoxes.versions.version_1_15.command.CommandSpawnTamableFox; import net.seanomik.tamablefoxes.io.Config; import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.wesjd.anvilgui.AnvilGUI; import org.bukkit.*; import org.bukkit.Material; import org.bukkit.Particle; @@ -41,7 +40,6 @@ import java.util.stream.Collectors; */ public final class TamableFoxes extends JavaPlugin implements Listener { private static TamableFoxes plugin; - public List spawnedFoxes = new ArrayList<>(); private boolean versionSupported = true; @@ -99,151 +97,8 @@ public final class TamableFoxes extends JavaPlugin implements Listener { @Override public void onDisable() { getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.YELLOW + LanguageConfig.getSavingFoxMessage()); - spawnedFoxes.forEach(EntityTamableFox::saveNbt); } - @EventHandler - public void onWorldSaveEvent(WorldSaveEvent event) { - spawnedFoxes.forEach(EntityTamableFox::saveNbt); - } - - @EventHandler - public void onChunkLoad(ChunkLoadEvent event) { - Bukkit.getScheduler().runTaskLaterAsynchronously(this, ()-> { - spawnedFoxes.addAll(Utils.loadFoxesInChunk(event.getChunk())); - }, 5L); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - - for (EntityTamableFox fox : getFoxesOf(player)) { - fox.setOwner((EntityLiving) ((CraftEntity) player).getHandle()); - } - } - - @EventHandler - public void onEntitySpawn(EntitySpawnEvent event) { - Entity entity = event.getEntity(); - - if (Utils.isTamableFox(entity)) { - EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) entity).getHandle(); - - spawnedFoxes.add(tamableFox); - } - } - - @EventHandler - public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) { - Entity entity = event.getRightClicked(); - Player player = event.getPlayer(); - - if (event.getHand() != EquipmentSlot.HAND) return; - - ItemStack itemHand = player.getInventory().getItemInMainHand(); - ItemMeta handMeta = itemHand.getItemMeta(); - - // Checks if the entity is EntityTamableFox and that the player is allowed to tame foxes - if (Utils.isTamableFox(entity)) { - EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) entity).getHandle(); - - // Check if its tamed but ignore it if the player is holding sweet berries for breeding or nametag for renaming - if (tamableFox.isTamed() && tamableFox.getOwner() != null && itemHand.getType() != Material.SWEET_BERRIES && itemHand.getType() != Material.NAME_TAG) { - if (tamableFox.getOwner().getUniqueID() == player.getUniqueId()) { - event.setCancelled(true); - if (player.isSneaking()) { - net.minecraft.server.v1_15_R1.ItemStack foxMouth = tamableFox.getEquipment(EnumItemSlot.MAINHAND); - if (!foxMouth.isEmpty()) tamableFox.dropMouthItem(); - if (itemHand.getType() != Material.AIR) { - tamableFox.setMouthItem(itemHand); - if (itemHand.getAmount() == 1) player.getInventory().removeItem(itemHand); - else itemHand.setAmount(itemHand.getAmount() - 1); - } - } else { - tamableFox.toggleSitting(); - } - } - } else if (itemHand.getType() == Material.CHICKEN && Config.canPlayerTameFox(player)) { - if (Math.random() < 0.33D) { // tamed - tamableFox.setTamed(true); - tamableFox.setOwner(((CraftPlayer) player).getHandle()); - - player.getWorld().spawnParticle(Particle.HEART, entity.getLocation(), 6, 0.5D, 0.5D, 0.5D); - - - player.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + LanguageConfig.getTamedMessage()); - - if (Config.askForNameAfterTaming()) { - player.sendMessage(ChatColor.RED + LanguageConfig.getTamingAskingName()); - new AnvilGUI.Builder() - .onComplete((plr, text) -> { // Called when the inventory output slot is clicked - if (!text.equals("")) { - tamableFox.getBukkitEntity().setCustomName(text); - tamableFox.setCustomNameVisible(true); - plr.sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(text)); - tamableFox.saveNbt(); - } - - return AnvilGUI.Response.close(); - }) - //.preventClose() // Prevents the inventory from being closed - .text("Fox name") // Sets the text the GUI should start with - .plugin(this) // Set the plugin instance - .open(player); // Opens the GUI for the player provided - } - } else { // Tame failed - player.getWorld().spawnParticle(Particle.SMOKE_NORMAL, entity.getLocation(), 10, 0.3D, 0.3D, 0.3D, 0.15D); - } - - if (!player.getGameMode().equals(GameMode.CREATIVE)) { - if (itemHand.getAmount() == 1) player.getInventory().removeItem(itemHand); - else itemHand.setAmount(itemHand.getAmount() - 1); - } - - event.setCancelled(true); - } - } - } - - @EventHandler - public void onPlayerBedEnterEvent(PlayerBedEnterEvent event) { - Player player = event.getPlayer(); - List foxesOf = getFoxesOf(player); - - for (EntityTamableFox tamableFox : foxesOf) { - if (player.getWorld().getTime() > 12541L && player.getWorld().getTime() < 23460L) { - tamableFox.setSleeping(true); - } - } - } - - @EventHandler - public void onPlayerBedLeaveEvent(PlayerBedLeaveEvent event) { - Player player = event.getPlayer(); - List foxesOf = getFoxesOf(player); - - for (EntityTamableFox tamableFox : foxesOf) { - tamableFox.setSleeping(false); - if (tamableFox.isSitting()) { - tamableFox.setSitting(true); - } - } - } - - @EventHandler - public void onEntityDeathEvent(EntityDeathEvent event) { - Entity entity = event.getEntity(); - if (!Utils.isTamableFox(entity)) return; // Is the entity a tamable fox? - // Remove the fox from storage - spawnedFoxes.remove(entity); - // Notify the owner - EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) entity).getHandle(); - if (tamableFox.getOwner() != null) { - Player owner = ((EntityPlayer) tamableFox.getOwner()).getBukkitEntity(); - owner.sendMessage(Utils.getPrefix() + ChatColor.RED + (tamableFox.hasCustomName() ? tamableFox.getBukkitEntity().getCustomName() : "Your fox") + " was killed!"); - } - } public EntityTamableFox spawnTamableFox(Location loc, EntityFox.Type type) { EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); @@ -252,9 +107,6 @@ public final class TamableFoxes extends JavaPlugin implements Listener { return tamableFox; } - public List getFoxesOf(Player player) { - return spawnedFoxes.stream().filter(fox -> fox.getOwner() != null && fox.getOwner().getUniqueID().equals(player.getUniqueId())).collect(Collectors.toList()); - } public static TamableFoxes getPlugin() { return plugin; diff --git a/src/main/java/net/seanomik/tamablefoxes/Utils.java b/src/main/java/net/seanomik/tamablefoxes/Utils.java index 2676ac9..145ff23 100644 --- a/src/main/java/net/seanomik/tamablefoxes/Utils.java +++ b/src/main/java/net/seanomik/tamablefoxes/Utils.java @@ -1,27 +1,12 @@ package net.seanomik.tamablefoxes; -import net.minecraft.server.v1_15_R1.EntityLiving; import org.bukkit.ChatColor; -import org.bukkit.Chunk; -import org.bukkit.NamespacedKey; -import org.bukkit.OfflinePlayer; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_15_R1.persistence.CraftPersistentDataContainer; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; import java.lang.reflect.Constructor; -import java.util.Arrays; import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; public class Utils { - public static boolean isTamableFox(org.bukkit.entity.Entity entity) { - return ((CraftEntity) entity).getHandle().getClass().getName().contains("TamableFox") || ((CraftEntity) entity).getHandle() instanceof EntityTamableFox; - } - public static String getPrefix() { return ChatColor.RED + "[Tamable Foxes] "; } @@ -64,41 +49,4 @@ public class Utils { } } - public static List loadFoxesInChunk(Chunk chunk) { - return Arrays.stream(chunk.getEntities()).filter(Utils::isTamableFox) - .map(entity -> (EntityTamableFox) ((CraftEntity) entity).getHandle()) - .peek(tamableFox -> { - NamespacedKey rootKey = new NamespacedKey(TamableFoxes.getPlugin(), "tamableFoxes"); - CraftPersistentDataContainer persistentDataContainer = tamableFox.getBukkitEntity().getPersistentDataContainer(); - if (persistentDataContainer.has(rootKey, PersistentDataType.TAG_CONTAINER)) { - PersistentDataContainer tamableFoxesData = persistentDataContainer.get(rootKey, PersistentDataType.TAG_CONTAINER); - NamespacedKey ownerKey = new NamespacedKey(TamableFoxes.getPlugin(), "owner"); - NamespacedKey sittingKey = new NamespacedKey(TamableFoxes.getPlugin(), "sitting"); - - String ownerUUIDString = tamableFoxesData.get(ownerKey, PersistentDataType.STRING); - boolean sitting = ((byte) 1) == tamableFoxesData.get(sittingKey, PersistentDataType.BYTE); - - boolean tamed = false; - if (!ownerUUIDString.equals("none")) { - tamed = true; - OfflinePlayer owner = TamableFoxes.getPlugin().getServer().getOfflinePlayer(UUID.fromString(ownerUUIDString)); - if (owner.isOnline()) { - EntityLiving livingOwner = (EntityLiving) ((CraftEntity) owner).getHandle(); - tamableFox.setOwner(livingOwner); - } else { - tamableFox.setOwnerUUID(UUID.fromString(ownerUUIDString)); - } - tamableFox.setTamed(true); - } - - if (sitting && tamed) { - tamableFox.setHardSitting(true); - } else { - tamableFox.setSitting(false); - tamableFox.setSleeping(false); - } - } - }).collect(Collectors.toList()); - } - } diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/command/CommandSpawnTamableFox.java b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/command/CommandSpawnTamableFox.java index 2282fe7..397119e 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/command/CommandSpawnTamableFox.java +++ b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/command/CommandSpawnTamableFox.java @@ -41,8 +41,6 @@ public class CommandSpawnTamableFox implements TabExecutor { case "red": try { EntityTamableFox fox = plugin.spawnTamableFox(player.getLocation(), EntityFox.Type.RED); - fox.saveNbt(); - player.sendMessage(Utils.getPrefix() + ChatColor.RESET + LanguageConfig.getSpawnedFoxMessage(EntityFox.Type.RED)); } catch (Exception e) { e.printStackTrace(); @@ -52,8 +50,6 @@ public class CommandSpawnTamableFox implements TabExecutor { case "snow": try { EntityTamableFox spawnedFox = plugin.spawnTamableFox(player.getLocation(), EntityFox.Type.SNOW); - spawnedFox.saveNbt(); - player.sendMessage(Utils.getPrefix() + ChatColor.RESET + LanguageConfig.getSpawnedFoxMessage(EntityFox.Type.SNOW)); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalFollowOwner.java b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalFollowOwner.java index de11343..213d472 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -51,7 +51,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { } public boolean b() { - return this.e.m() ? false : (this.a.isSitting() ? false : this.a.h(this.b) > (double)(this.g * this.g)); + return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); } public void c() { diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalMeleeAttack.java b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalMeleeAttack.java index 2845443..c8a65b7 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalMeleeAttack.java +++ b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalMeleeAttack.java @@ -32,6 +32,6 @@ public class FoxPathfinderGoalMeleeAttack extends PathfinderGoalMeleeAttack { } public boolean a() { - return !tamableFox.isSitting() && !tamableFox.isSleeping() && !tamableFox.isCrouching() && !tamableFox.es() && !tamableFox.isOtherFoxFamily(enemy) && super.a(); + return !tamableFox.isSitting() && !tamableFox.isSleeping() && !tamableFox.isCrouching() && !tamableFox.es() && super.a(); } } diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java index 3555885..709ad1c 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java +++ b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java @@ -28,7 +28,7 @@ public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { } else { this.b = entityliving.getLastDamager(); int i = entityliving.cI(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a); //&& this.a.a(this.b, entityliving); // Returns true in any condition + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); } } else { return false; diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java index 40168d9..dd6a59c 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java +++ b/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java @@ -1,9 +1,9 @@ package net.seanomik.tamablefoxes.versions.version_1_15.pathfinding; -import net.seanomik.tamablefoxes.EntityTamableFox; import net.minecraft.server.v1_15_R1.EntityLiving; import net.minecraft.server.v1_15_R1.PathfinderGoalTarget; import net.minecraft.server.v1_15_R1.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.EntityTamableFox; import org.bukkit.event.entity.EntityTargetEvent.TargetReason; import java.util.EnumSet; @@ -25,13 +25,10 @@ public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { if (entityliving == null) { e.setGoalTarget(null); return false; - } else if (fox.isOtherFoxFamily(hitEntity)) { - e.setGoalTarget(null); - return false; } else { hitEntity = entityliving.cJ(); int i = entityliving.cK(); - return i != this.c && this.a(hitEntity, PathfinderTargetCondition.a);// && fox.a.a(hitEntity, entityliving); // Just returns true in any case + return i != this.c && this.a(hitEntity, PathfinderTargetCondition.a) && fox.a(hitEntity, entityliving); } } else { return false; @@ -39,16 +36,12 @@ public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { } public void c() { - if (!fox.isOtherFoxFamily(hitEntity)) { - this.e.setGoalTarget(hitEntity, TargetReason.OWNER_ATTACKED_TARGET, true); - EntityLiving entityliving = fox.getOwner(); - if (entityliving != null) { - this.c = entityliving.cK(); - } - - super.c(); - } else { - e.setGoalTarget(null); + this.e.setGoalTarget(hitEntity, TargetReason.OWNER_ATTACKED_TARGET, true); + EntityLiving entityliving = fox.getOwner(); + if (entityliving != null) { + this.c = entityliving.cK(); } + + super.c(); } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4c538b5..44fd464 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # Config for Tamable Foxes -show-owner-in-fox-name: true +show-owner-in-fox-name: false enable-taming-permission: true ask-for-name-after-taming: false diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4370e9b..eb9a35e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,7 +2,7 @@ name: Tamablefoxes version: ${project.version} main: net.seanomik.tamablefoxes.TamableFoxes api-version: 1.15 -load: POSTWORLD +load: STARTUP description: Adds tamable foxes to Minecraft! commands: diff --git a/target/classes/config.yml b/target/classes/config.yml index 0741882..44fd464 100644 --- a/target/classes/config.yml +++ b/target/classes/config.yml @@ -1,7 +1,7 @@ # Config for Tamable Foxes -show-owner-in-fox-name: true -show-nametags: true +show-owner-in-fox-name: false enable-taming-permission: true +ask-for-name-after-taming: false tamed-behavior: attack-wild-animals: true \ No newline at end of file diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml index a1035dc..a839e2d 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -1,8 +1,8 @@ name: Tamablefoxes -version: 1.5.2-SNAPSHOT +version: 1.6.0-SNAPSHOT main: net.seanomik.tamablefoxes.TamableFoxes api-version: 1.15 -load: POSTWORLD +load: STARTUP description: Adds tamable foxes to Minecraft! commands: diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index 8f4c0a8..6b45ffb 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Mon Jan 27 07:55:13 CST 2020 -version=1.5.2-SNAPSHOT +#Tue Feb 18 22:29:20 GMT 2020 +version=1.6.0-SNAPSHOT groupId=net.seanomik artifactId=tamablefoxes diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index b641638..1c258ab 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -4,7 +4,6 @@ net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalPan net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalHurtByTarget.class net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalFollowOwner.class net\seanomik\tamablefoxes\TamableFoxes.class -net\seanomik\tamablefoxes\EntityTamableFox$UpdateFoxRunnable.class net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalSit.class net\seanomik\tamablefoxes\versions\version_1_15\command\CommandSpawnTamableFox.class net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtByTarget.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index df075aa..fee61e5 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1,13 +1,13 @@ -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalHurtByTarget.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalPanic.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtByTarget.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\command\CommandSpawnTamableFox.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalSit.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\Utils.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalFollowOwner.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\TamableFoxes.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\Config.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtTarget.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalMeleeAttack.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\EntityTamableFox.java -D:\Code\java\spigotPlugins\myPlugins\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\LanguageConfig.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\LanguageConfig.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalMeleeAttack.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalHurtByTarget.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtTarget.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalFollowOwner.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalOwnerHurtByTarget.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalSit.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalPanic.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\EntityTamableFox.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\versions\version_1_15\command\CommandSpawnTamableFox.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\Utils.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\TamableFoxes.java +C:\Users\Checkium\IdeaProjects\TamableFoxes\src\main\java\net\seanomik\tamablefoxes\io\Config.java From d2f7281a89edcfe1b7fd16cd8413ca0c983cbb13 Mon Sep 17 00:00:00 2001 From: Checkium Folf Date: Fri, 21 Feb 2020 23:13:13 +0000 Subject: [PATCH 2/4] Fix removing items of foxes --- .idea/workspace.xml | 38 ++++++++----------- .../tamablefoxes/EntityTamableFox.java | 2 +- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ac27c62..650a9a0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,26 +1,9 @@ - - - + - - - - - - - - - - - - - - - @@ -196,7 +186,8 @@ - @@ -210,10 +201,11 @@ - - + + + diff --git a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java index 7a97acf..a2e3e47 100644 --- a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java +++ b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java @@ -256,7 +256,7 @@ public class EntityTamableFox extends EntityFox { if (isOwnedBy(entityhuman)) { boolean flag = super.a(entityhuman, enumhand); - if ((item == Items.AIR || !entityhuman.isSneaking()) && !flag || this.isBaby()) { + if (!entityhuman.isSneaking() && (!flag || this.isBaby())) { this.goalSit.setSitting(!this.isSitting()); return flag; } else if (entityhuman.isSneaking()) { From 5ac36cb9f2aa3cf1611c99bfb293b05a1f580b64 Mon Sep 17 00:00:00 2001 From: Checkium Folf Date: Sat, 22 Feb 2020 15:08:05 +0000 Subject: [PATCH 3/4] Fix fox running away from players --- .../seanomik/tamablefoxes/EntityTamableFox.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java index a2e3e47..6cd219b 100644 --- a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java +++ b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java @@ -1,5 +1,6 @@ package net.seanomik.tamablefoxes; +import com.google.common.collect.Lists; import net.minecraft.server.v1_15_R1.*; import net.seanomik.tamablefoxes.io.Config; import net.seanomik.tamablefoxes.versions.version_1_15.pathfinding.*; @@ -12,15 +13,19 @@ import javax.annotation.Nullable; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.*; +import java.util.function.Predicate; public class EntityTamableFox extends EntityFox { protected static final DataWatcherObject tamed; protected static final DataWatcherObject> ownerUUID; + private static final Predicate bD; static { tamed = DataWatcher.a(EntityTamableFox.class, DataWatcherRegistry.a); ownerUUID = DataWatcher.a(EntityTamableFox.class, DataWatcherRegistry.o); + + bD = (entity) -> !entity.bm() && IEntitySelector.e.test(entity); } List untamedGoals; @@ -45,7 +50,9 @@ public class EntityTamableFox extends EntityFox { this.goalSelector.a(4, getFoxInnerPathfinderGoal("e", Arrays.asList(1.0D), Arrays.asList(double.class))); // BreedGoal // Avoid human only if not tamed - this.goalSelector.a(5, new PathfinderGoalAvoidTarget(this, EntityHuman.class, 16.0F, 1.6D, 1.4D, (entityliving) -> !isTamed())); + this.goalSelector.a(5, new PathfinderGoalAvoidTarget(this, EntityHuman.class, 16.0F, 1.6D, 1.4D, (entityliving) -> { + return bD.test((EntityLiving) entityliving); + })); // Avoid wolf if it is not tamed this.goalSelector.a(5, new PathfinderGoalAvoidTarget(this, EntityWolf.class, 8.0F, 1.6D, 1.4D, (entityliving) -> { @@ -64,7 +71,7 @@ public class EntityTamableFox extends EntityFox { this.goalSelector.a(8, new FoxPathfinderGoalMeleeAttack(this, 1.2000000476837158D, true)); this.goalSelector.a(9, new FoxPathfinderGoalFollowOwner(this, 1.3D, 10.0F, 2.0F, false)); this.goalSelector.a(6, getFoxInnerPathfinderGoal("u")); // StalkPrey - this.goalSelector.a(7, new EntityFox.o()); // Pounce + this.goalSelector.a(7, new o()); // Pounce this.goalSelector.a(9, getFoxInnerPathfinderGoal("h", Arrays.asList(this, 1.25D), Arrays.asList(EntityFox.class, double.class))); // FollowParent @@ -97,8 +104,6 @@ public class EntityTamableFox extends EntityFox { return (!isTamed() || (Config.doesTamedAttackWildAnimals() && isTamed())) && entityliving instanceof EntityFishSchool; })); - - untamedGoals = new ArrayList<>(); // Sleep @@ -112,7 +117,7 @@ public class EntityTamableFox extends EntityFox { untamedGoals.add(perchAndSearch); // EatBerries (Pick berry bushes) - PathfinderGoal eatBerries = new EntityFox.f(1.2000000476837158D, 12, 2); + PathfinderGoal eatBerries = new f(1.2000000476837158D, 12, 2); this.goalSelector.a(11, eatBerries); untamedGoals.add(eatBerries); // Maybe this should be configurable too? From 80200cf4159fc4345830d4be87fa30d5fb8de6ae Mon Sep 17 00:00:00 2001 From: Checkium Folf Date: Sat, 22 Feb 2020 15:10:24 +0000 Subject: [PATCH 4/4] Forgot to check if the fox was tamed too --- src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java index 6cd219b..539e3fd 100644 --- a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java +++ b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java @@ -51,7 +51,7 @@ public class EntityTamableFox extends EntityFox { // Avoid human only if not tamed this.goalSelector.a(5, new PathfinderGoalAvoidTarget(this, EntityHuman.class, 16.0F, 1.6D, 1.4D, (entityliving) -> { - return bD.test((EntityLiving) entityliving); + return !isTamed() && bD.test((EntityLiving) entityliving); })); // Avoid wolf if it is not tamed