diff --git a/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java b/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java index b418a73..60deca0 100644 --- a/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java +++ b/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java @@ -244,6 +244,27 @@ public class EntityTamableFox extends EntityFox { } } + public void rename(org.bukkit.entity.Player player) { + new AnvilGUI.Builder() + .onComplete((plr, input) -> { // Called when the inventory output slot is clicked + if (!input.equals("")) { + org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); + + // This will auto format the name for config settings. + String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); + + tamableFox.setCustomName(foxName); + tamableFox.setCustomNameVisible(true); + plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); + } + + return AnvilGUI.Response.close(); + }) + .text("Fox name") // Sets the text the GUI should start with + .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance + .open(player); // Opens the GUI for the player provided + } + // deobf: mobInteract public boolean a(EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.b(enumhand); @@ -271,6 +292,13 @@ public class EntityTamableFox extends EntityFox { // If the player is not sneaking and the fox cannot breed, then make the fox sit. if (!entityhuman.isSneaking() && (!flag || this.isBaby())) { + // Show the rename menu again when trying to use a nametag on the fox. + if (itemstack.getItem() instanceof ItemNameTag) { + org.bukkit.entity.Player player = (org.bukkit.entity.Player) entityhuman.getBukkitEntity(); + rename(player); + return true; + } + this.setSleeping(false); this.goalSit.setSitting(!this.isSitting()); return flag; @@ -356,24 +384,7 @@ public class EntityTamableFox extends EntityFox { Player player = (Player) entityhuman.getBukkitEntity(); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); - new AnvilGUI.Builder() - .onComplete((plr, input) -> { // Called when the inventory output slot is clicked - if (!input.equals("")) { - org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); - - // This will auto format the name for config settings. - String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); - - tamableFox.setCustomName(foxName); - tamableFox.setCustomNameVisible(true); - plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); - } - - return AnvilGUI.Response.close(); - }) - .text("Fox name") // Sets the text the GUI should start with - .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance - .open(player); // Opens the GUI for the player provided + rename(player); } } else { getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); diff --git a/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java b/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java index 9f71ce7..0fef3bc 100644 --- a/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/1_14_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -38,7 +38,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { return false; } else if (entityliving instanceof EntityHuman && ((EntityHuman)entityliving).isSpectator()) { return false; - } else if (this.a.isSitting()) { + } else if (this.a.isSitting() || this.a.isSleeping()) { return false; } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { return false; diff --git a/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java b/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java index 1bc8a1a..09cad60 100644 --- a/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java +++ b/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java @@ -244,6 +244,27 @@ public class EntityTamableFox extends EntityFox { } } + public void rename(org.bukkit.entity.Player player) { + new AnvilGUI.Builder() + .onComplete((plr, input) -> { // Called when the inventory output slot is clicked + if (!input.equals("")) { + org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); + + // This will auto format the name for config settings. + String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); + + tamableFox.setCustomName(foxName); + tamableFox.setCustomNameVisible(true); + plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); + } + + return AnvilGUI.Response.close(); + }) + .text("Fox name") // Sets the text the GUI should start with + .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance + .open(player); // Opens the GUI for the player provided + } + // deobf: mobInteract public boolean a(EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.b(enumhand); @@ -271,6 +292,13 @@ public class EntityTamableFox extends EntityFox { // If the player is not sneaking and the fox cannot breed, then make the fox sit. if (!entityhuman.isSneaking() && (!flag || this.isBaby())) { + // Show the rename menu again when trying to use a nametag on the fox. + if (itemstack.getItem() instanceof ItemNameTag) { + org.bukkit.entity.Player player = (org.bukkit.entity.Player) entityhuman.getBukkitEntity(); + rename(player); + return true; + } + this.setSleeping(false); this.goalSit.setSitting(!this.isSitting()); return flag; @@ -356,24 +384,7 @@ public class EntityTamableFox extends EntityFox { Player player = (Player) entityhuman.getBukkitEntity(); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); - new AnvilGUI.Builder() - .onComplete((plr, input) -> { // Called when the inventory output slot is clicked - if (!input.equals("")) { - org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); - - // This will auto format the name for config settings. - String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); - - tamableFox.setCustomName(foxName); - tamableFox.setCustomNameVisible(true); - plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); - } - - return AnvilGUI.Response.close(); - }) - .text("Fox name") // Sets the text the GUI should start with - .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance - .open(player); // Opens the GUI for the player provided + rename(player); } } else { getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); diff --git a/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java b/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java index 4442de5..2fa8319 100644 --- a/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/1_15_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -40,7 +40,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { return false; } else if (entityliving.isSpectator()) { return false; - } else if (this.a.isSitting()) { + } else if (this.a.isSitting() || this.a.isSleeping()) { return false; } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { return false; diff --git a/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java b/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java index b3b8015..d9a150a 100644 --- a/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java +++ b/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java @@ -242,6 +242,27 @@ public class EntityTamableFox extends EntityFox { } } + public void rename(org.bukkit.entity.Player player) { + new AnvilGUI.Builder() + .onComplete((plr, input) -> { // Called when the inventory output slot is clicked + if (!input.equals("")) { + org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); + + // This will auto format the name for config settings. + String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); + + tamableFox.setCustomName(foxName); + tamableFox.setCustomNameVisible(true); + plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); + } + + return AnvilGUI.Response.close(); + }) + .text("Fox name") // Sets the text the GUI should start with + .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance + .open(player); // Opens the GUI for the player provided + } + // deobf: mobInteract @Override public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) { @@ -271,6 +292,13 @@ public class EntityTamableFox extends EntityFox { // If the player is not sneaking and the fox cannot breed, then make the fox sit. // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS? if (!entityhuman.isSneaking() && (flag != EnumInteractionResult.SUCCESS || this.isBaby())) { + // Show the rename menu again when trying to use a nametag on the fox. + if (itemstack.getItem() instanceof ItemNameTag) { + org.bukkit.entity.Player player = (org.bukkit.entity.Player) entityhuman.getBukkitEntity(); + rename(player); + return EnumInteractionResult.PASS; + } + this.setSleeping(false); this.goalSit.setSitting(!this.isSitting()); return flag; @@ -357,24 +385,7 @@ public class EntityTamableFox extends EntityFox { Player player = (Player) entityhuman.getBukkitEntity(); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); - new AnvilGUI.Builder() - .onComplete((plr, input) -> { // Called when the inventory output slot is clicked - if (!input.equals("")) { - org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); - - // This will auto format the name for config settings. - String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); - - tamableFox.setCustomName(foxName); - tamableFox.setCustomNameVisible(true); - plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); - } - - return AnvilGUI.Response.close(); - }) - .text("Fox name") // Sets the text the GUI should start with - .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance - .open(player); // Opens the GUI for the player provided + rename(player); } } else { getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); diff --git a/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java b/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java index c7ebd64..462f8be 100644 --- a/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/1_16_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -40,7 +40,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { return false; } else if (entityliving.isSpectator()) { return false; - } else if (this.a.isSitting()) { // this.a.isWillSit() + } else if (this.a.isSitting() || this.a.isSleeping()) { // this.a.isWillSit() return false; } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { return false; diff --git a/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java b/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java index 3001430..e135e5d 100644 --- a/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java +++ b/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java @@ -240,6 +240,27 @@ public class EntityTamableFox extends EntityFox { } } + public void rename(org.bukkit.entity.Player player) { + new AnvilGUI.Builder() + .onComplete((plr, input) -> { // Called when the inventory output slot is clicked + if (!input.equals("")) { + org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); + + // This will auto format the name for config settings. + String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); + + tamableFox.setCustomName(foxName); + tamableFox.setCustomNameVisible(true); + plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); + } + + return AnvilGUI.Response.close(); + }) + .text("Fox name") // Sets the text the GUI should start with + .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance + .open(player); // Opens the GUI for the player provided + } + // deobf: mobInteract public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.b(enumhand); @@ -268,6 +289,13 @@ public class EntityTamableFox extends EntityFox { // If the player is not sneaking and the fox cannot breed, then make the fox sit. // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS? if (!entityhuman.isSneaking() && (flag != EnumInteractionResult.SUCCESS || this.isBaby())) { + // Show the rename menu again when trying to use a nametag on the fox. + if (itemstack.getItem() instanceof ItemNameTag) { + org.bukkit.entity.Player player = (org.bukkit.entity.Player) entityhuman.getBukkitEntity(); + rename(player); + return EnumInteractionResult.PASS; + } + this.setSleeping(false); this.goalSit.setSitting(!this.isSitting()); return flag; @@ -349,24 +377,7 @@ public class EntityTamableFox extends EntityFox { Player player = (Player) entityhuman.getBukkitEntity(); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); - new AnvilGUI.Builder() - .onComplete((plr, input) -> { // Called when the inventory output slot is clicked - if (!input.equals("")) { - org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); - - // This will auto format the name for config settings. - String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); - - tamableFox.setCustomName(foxName); - tamableFox.setCustomNameVisible(true); - plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); - } - - return AnvilGUI.Response.close(); - }) - .text("Fox name") // Sets the text the GUI should start with - .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance - .open(player); // Opens the GUI for the player provided + rename(player); } } else { getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); diff --git a/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java b/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java index d80f3a0..fa3820d 100644 --- a/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/1_16_R2/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -40,7 +40,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { return false; } else if (entityliving.isSpectator()) { return false; - } else if (this.a.isSitting()) { // this.a.isWillSit() + } else if (this.a.isSitting() || this.a.isSleeping()) { // this.a.isWillSit() return false; } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { return false; diff --git a/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java b/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java index 8949cc5..e938c9d 100644 --- a/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java +++ b/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java @@ -240,6 +240,27 @@ public class EntityTamableFox extends EntityFox { } } + public void rename(org.bukkit.entity.Player player) { + new AnvilGUI.Builder() + .onComplete((plr, input) -> { // Called when the inventory output slot is clicked + if (!input.equals("")) { + org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); + + // This will auto format the name for config settings. + String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); + + tamableFox.setCustomName(foxName); + tamableFox.setCustomNameVisible(true); + plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); + } + + return AnvilGUI.Response.close(); + }) + .text("Fox name") // Sets the text the GUI should start with + .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance + .open(player); // Opens the GUI for the player provided + } + // deobf: mobInteract public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.b(enumhand); @@ -268,6 +289,13 @@ public class EntityTamableFox extends EntityFox { // If the player is not sneaking and the fox cannot breed, then make the fox sit. // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS? if (!entityhuman.isSneaking() && (flag != EnumInteractionResult.SUCCESS || this.isBaby())) { + // Show the rename menu again when trying to use a nametag on the fox. + if (itemstack.getItem() instanceof ItemNameTag) { + org.bukkit.entity.Player player = (org.bukkit.entity.Player) entityhuman.getBukkitEntity(); + rename(player); + return EnumInteractionResult.PASS; + } + this.setSleeping(false); this.goalSit.setSitting(!this.isSitting()); return flag; @@ -349,24 +377,7 @@ public class EntityTamableFox extends EntityFox { Player player = (Player) entityhuman.getBukkitEntity(); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); - new AnvilGUI.Builder() - .onComplete((plr, input) -> { // Called when the inventory output slot is clicked - if (!input.equals("")) { - org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); - - // This will auto format the name for config settings. - String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); - - tamableFox.setCustomName(foxName); - tamableFox.setCustomNameVisible(true); - plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); - } - - return AnvilGUI.Response.close(); - }) - .text("Fox name") // Sets the text the GUI should start with - .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance - .open(player); // Opens the GUI for the player provided + rename(player); } } else { getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); diff --git a/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java b/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java index 1f11ea6..93e8962 100644 --- a/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/1_16_R3/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -40,7 +40,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { return false; } else if (entityliving.isSpectator()) { return false; - } else if (this.a.isSitting()) { // this.a.isWillSit() + } else if (this.a.isSitting() || this.a.isSleeping()) { // this.a.isWillSit() return false; } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { return false; diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/EntityTamableFox.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/EntityTamableFox.java index 289d5c4..481f4f6 100644 --- a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/EntityTamableFox.java +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/EntityTamableFox.java @@ -1,5 +1,6 @@ package net.seanomik.tamablefoxes.versions.version_1_17_R1; +import com.sun.org.apache.xpath.internal.operations.Bool; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.syncher.*; @@ -45,14 +46,14 @@ import java.util.function.Predicate; public class EntityTamableFox extends Fox { - protected static final EntityDataAccessor tamed; + protected static final EntityDataAccessor tamed; protected static final EntityDataAccessor> ownerUUID; //private static final EntityDataAccessor bw; // DATA_FLAGS_ID private static final Predicate AVOID_PLAYERS; // AVOID_PLAYERS static { - tamed = SynchedEntityData.defineId(EntityTamableFox.class, EntityDataSerializers.BYTE); + tamed = SynchedEntityData.defineId(EntityTamableFox.class, EntityDataSerializers.BOOLEAN); ownerUUID = SynchedEntityData.defineId(EntityTamableFox.class, EntityDataSerializers.OPTIONAL_UUID); AVOID_PLAYERS = (entity) -> !entity.isCrouching();// && EntitySelector.test(entity); @@ -74,6 +75,8 @@ public class EntityTamableFox extends Fox { this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(10.0D); this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(2.0D); } + + this.setTamed(false); } @Override @@ -103,7 +106,7 @@ public class EntityTamableFox extends Fox { this.goalSelector.addGoal(0, getFoxInnerPathfinderGoal("g")); // FoxFloatGoal this.goalSelector.addGoal(1, getFoxInnerPathfinderGoal("b")); // FaceplantGoal - this.goalSelector.addGoal(2, getFoxInnerPathfinderGoal("n", Arrays.asList(2.2D), Arrays.asList(double.class))); // FoxPanicGoal + this.goalSelector.addGoal(2, new FoxPathfinderGoalPanic(this, 2.2D)); // FoxPanicGoal this.goalSelector.addGoal(2, new FoxPathfinderGoalSleepWithOwner(this)); this.goalSelector.addGoal(3, getFoxInnerPathfinderGoal("e", Arrays.asList(1.0D), Arrays.asList(double.class))); // FoxBreedGoal @@ -178,10 +181,21 @@ public class EntityTamableFox extends Fox { return false; } + public void setDefending(boolean defending) { + try { + Method method = Fox.class.getDeclaredMethod("A", boolean.class); // setDefending + method.setAccessible(true); + method.invoke((Fox) this, defending); + method.setAccessible(false); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + @Override protected void defineSynchedData() { super.defineSynchedData(); - this.entityData.define(tamed, (byte) 0); + this.entityData.define(tamed, false); this.entityData.define(ownerUUID, Optional.empty()); } @@ -216,9 +230,11 @@ public class EntityTamableFox extends Fox { } } - if (ownerUuid != null) { + if (ownerUuid != null && !ownerUuid.equals(new UUID(0, 0))) { this.setOwnerUUID(ownerUuid); this.setTamed(true); + } else { + this.setTamed(false); } if (this.goalSitWhenOrdered != null) { @@ -236,19 +252,15 @@ public class EntityTamableFox extends Fox { } public boolean isTamed() { - return ((Byte) this.entityData.get(tamed) & 4) != 0; + UUID ownerUuid = getOwnerUUID(); + return this.entityData.get(tamed) && (ownerUuid != null && !ownerUuid.equals(new UUID(0, 0))); } - public void setTamed(boolean tamed_) { - byte isTamed = this.entityData.get(tamed); - if (tamed_) { - this.entityData.set(tamed, (byte) (isTamed | 4)); - } else { - this.entityData.set(tamed, (byte) (isTamed & -5)); - } + public void setTamed(boolean tamed) { + this.entityData.set(EntityTamableFox.tamed, tamed); this.reassessTameGoals(); - if (tamed_) { + if (tamed) { this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(24.0D); this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(3.0D); } else { @@ -267,6 +279,28 @@ public class EntityTamableFox extends Fox { } } + public void rename(org.bukkit.entity.Player player) { + new AnvilGUI.Builder() + .onComplete((plr, input) -> { // Called when the inventory output slot is clicked + if (!input.equals("")) { + org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); + + // This will auto format the name for config settings. + String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); + + tamableFox.setCustomName(foxName); + tamableFox.setCustomNameVisible(true); + plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); + } + + return AnvilGUI.Response.close(); + }) + .preventClose() + .text("Fox name") // Sets the text the GUI should start with + .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance + .open(player); // Opens the GUI for the player provided + } + @Override public InteractionResult mobInteract(Player entityhuman, InteractionHand enumhand) { ItemStack itemstack = entityhuman.getItemInHand(enumhand); @@ -296,6 +330,13 @@ public class EntityTamableFox extends Fox { // If the player is not sneaking and the fox cannot breed, then make the fox sit. // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS? if (!entityhuman.isCrouching() && (flag != InteractionResult.SUCCESS || this.isBaby())) { + // Show the rename menu again when trying to use a nametag on the fox. + if (itemstack.getItem() instanceof NameTagItem) { + org.bukkit.entity.Player player = (org.bukkit.entity.Player) entityhuman.getBukkitEntity(); + rename(player); + return InteractionResult.PASS; + } + this.goalSleepWhenOrdered.setOrderedToSleep(false); this.goalSitWhenOrdered.setOrderedToSit(!this.isOrderedToSit()); return InteractionResult.SUCCESS; @@ -374,24 +415,7 @@ public class EntityTamableFox extends Fox { // Let the player choose the new fox's name if its enabled in config. if (Config.askForNameAfterTaming()) { player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); - new AnvilGUI.Builder() - .onComplete((plr, input) -> { // Called when the inventory output slot is clicked - if (!input.equals("")) { - org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); - - // This will auto format the name for config settings. - String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); - - tamableFox.setCustomName(foxName); - tamableFox.setCustomNameVisible(true); - plr.sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); - } - - return AnvilGUI.Response.close(); - }) - .text("Fox name") // Sets the text the GUI should start with - .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance - .open(player); // Opens the GUI for the player provided + rename(player); } } else { getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java index 56ad4c0..1f4138f 100644 --- a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java @@ -42,6 +42,15 @@ public class FoxPathfinderGoalOwnerHurtByTarget extends TargetGoal { this.timestamp = entityliving.getLastHurtByMobTimestamp(); } + tameAnimal.setDefending(false); + super.start(); } + + @Override + public void stop() { + tameAnimal.setDefending(false); + + super.stop(); + } } \ No newline at end of file diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java index 456c62f..3dba85b 100644 --- a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java @@ -42,6 +42,16 @@ public class FoxPathfinderGoalOwnerHurtTarget extends TargetGoal { this.timestamp = entityliving.getLastHurtMobTimestamp(); } + tameAnimal.setDefending(true); + super.start(); } + + + @Override + public void stop() { + tameAnimal.setDefending(false); + + super.stop(); + } } \ No newline at end of file diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalPanic.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalPanic.java new file mode 100644 index 0000000..2f9f60d --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalPanic.java @@ -0,0 +1,21 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding; + +import net.minecraft.world.entity.ai.goal.PanicGoal; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.EntityTamableFox; + +public class FoxPathfinderGoalPanic extends PanicGoal { + EntityTamableFox tamableFox; + + public FoxPathfinderGoalPanic(EntityTamableFox tamableFox, double d0) { + super(tamableFox, d0); + this.tamableFox = tamableFox; + } + + public boolean canUse() { + if (tamableFox.isTamed()) { + return tamableFox.getHealth() < 2.0f && super.canUse(); + } + + return tamableFox.isDefending() && super.canUse(); + } +} diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 8a5c53a..cd0cd40 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -22,15 +22,28 @@ - + net.seanomik.tamablefoxes.bstats + + - --> + + + package + + shade + + + + org.apache.maven.plugins maven-shade-plugin @@ -41,7 +54,7 @@ shade - D:\Code\java\spigotPlugins\servers\${server.version}\plugins\TamableFoxes_v${project.parent.version}.jar + false @@ -118,6 +131,12 @@ compile + + org.bstats + bstats-bukkit + 2.2.1 + compile + net.seanomik tamablefoxes-util diff --git a/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java index bfe02bd..222d1cd 100644 --- a/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java @@ -11,12 +11,15 @@ import net.seanomik.tamablefoxes.versions.version_1_16_R2.NMSInterface_1_16_R2; import net.seanomik.tamablefoxes.versions.version_1_16_R3.NMSInterface_1_16_R3; import net.seanomik.tamablefoxes.versions.version_1_17_R1.NMSInterface_1_17_R1; import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bstats.bukkit.Metrics; +import org.bstats.charts.SingleLineChart; import org.bukkit.*; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; public final class TamableFoxes extends JavaPlugin implements Listener { private static TamableFoxes plugin; + public static final int BSTATS_PLUGIN_ID = 11944; private boolean versionSupported = true; @@ -65,6 +68,9 @@ public final class TamableFoxes extends JavaPlugin implements Listener { if (Config.getMaxPlayerFoxTames() != 0) { SQLiteHelper.getInstance(this).createTablesIfNotExist(); } + + Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID); + //metrics.addCustomChart(new SingleLineChart("servers", () -> 1)); } @Override