Fix #51, also implement the fix for #52 for all version implementations

This commit is contained in:
SeanOMik 2021-07-07 15:24:49 -04:00
parent 5ec2b578e0
commit 9e8b06c9c0
No known key found for this signature in database
GPG Key ID: CA09E5BE1F32728A
16 changed files with 278 additions and 134 deletions

View File

@ -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 // deobf: mobInteract
public boolean a(EntityHuman entityhuman, EnumHand enumhand) { public boolean a(EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(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 the player is not sneaking and the fox cannot breed, then make the fox sit.
if (!entityhuman.isSneaking() && (!flag || this.isBaby())) { 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.setSleeping(false);
this.goalSit.setSitting(!this.isSitting()); this.goalSit.setSitting(!this.isSitting());
return flag; return flag;
@ -356,24 +384,7 @@ public class EntityTamableFox extends EntityFox {
Player player = (Player) entityhuman.getBukkitEntity(); Player player = (Player) entityhuman.getBukkitEntity();
player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName());
new AnvilGUI.Builder() rename(player);
.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
} }
} else { } else {
getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D);

View File

@ -38,7 +38,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal {
return false; return false;
} else if (entityliving instanceof EntityHuman && ((EntityHuman)entityliving).isSpectator()) { } else if (entityliving instanceof EntityHuman && ((EntityHuman)entityliving).isSpectator()) {
return false; return false;
} else if (this.a.isSitting()) { } else if (this.a.isSitting() || this.a.isSleeping()) {
return false; return false;
} else if (this.a.h(entityliving) < (double)(this.h * this.h)) { } else if (this.a.h(entityliving) < (double)(this.h * this.h)) {
return false; return false;

View File

@ -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 // deobf: mobInteract
public boolean a(EntityHuman entityhuman, EnumHand enumhand) { public boolean a(EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(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 the player is not sneaking and the fox cannot breed, then make the fox sit.
if (!entityhuman.isSneaking() && (!flag || this.isBaby())) { 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.setSleeping(false);
this.goalSit.setSitting(!this.isSitting()); this.goalSit.setSitting(!this.isSitting());
return flag; return flag;
@ -356,24 +384,7 @@ public class EntityTamableFox extends EntityFox {
Player player = (Player) entityhuman.getBukkitEntity(); Player player = (Player) entityhuman.getBukkitEntity();
player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName());
new AnvilGUI.Builder() rename(player);
.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
} }
} else { } else {
getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D);

View File

@ -40,7 +40,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal {
return false; return false;
} else if (entityliving.isSpectator()) { } else if (entityliving.isSpectator()) {
return false; return false;
} else if (this.a.isSitting()) { } else if (this.a.isSitting() || this.a.isSleeping()) {
return false; return false;
} else if (this.a.h(entityliving) < (double)(this.h * this.h)) { } else if (this.a.h(entityliving) < (double)(this.h * this.h)) {
return false; return false;

View File

@ -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 // deobf: mobInteract
@Override @Override
public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) { 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. // 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? // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS?
if (!entityhuman.isSneaking() && (flag != EnumInteractionResult.SUCCESS || this.isBaby())) { 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.setSleeping(false);
this.goalSit.setSitting(!this.isSitting()); this.goalSit.setSitting(!this.isSitting());
return flag; return flag;
@ -357,24 +385,7 @@ public class EntityTamableFox extends EntityFox {
Player player = (Player) entityhuman.getBukkitEntity(); Player player = (Player) entityhuman.getBukkitEntity();
player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName());
new AnvilGUI.Builder() rename(player);
.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
} }
} else { } else {
getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D);

View File

@ -40,7 +40,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal {
return false; return false;
} else if (entityliving.isSpectator()) { } else if (entityliving.isSpectator()) {
return false; return false;
} else if (this.a.isSitting()) { // this.a.isWillSit() } else if (this.a.isSitting() || this.a.isSleeping()) { // this.a.isWillSit()
return false; return false;
} else if (this.a.h(entityliving) < (double)(this.h * this.h)) { } else if (this.a.h(entityliving) < (double)(this.h * this.h)) {
return false; return false;

View File

@ -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 // deobf: mobInteract
public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) { public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(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. // 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? // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS?
if (!entityhuman.isSneaking() && (flag != EnumInteractionResult.SUCCESS || this.isBaby())) { 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.setSleeping(false);
this.goalSit.setSitting(!this.isSitting()); this.goalSit.setSitting(!this.isSitting());
return flag; return flag;
@ -349,24 +377,7 @@ public class EntityTamableFox extends EntityFox {
Player player = (Player) entityhuman.getBukkitEntity(); Player player = (Player) entityhuman.getBukkitEntity();
player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName());
new AnvilGUI.Builder() rename(player);
.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
} }
} else { } else {
getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D);

View File

@ -40,7 +40,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal {
return false; return false;
} else if (entityliving.isSpectator()) { } else if (entityliving.isSpectator()) {
return false; return false;
} else if (this.a.isSitting()) { // this.a.isWillSit() } else if (this.a.isSitting() || this.a.isSleeping()) { // this.a.isWillSit()
return false; return false;
} else if (this.a.h(entityliving) < (double)(this.h * this.h)) { } else if (this.a.h(entityliving) < (double)(this.h * this.h)) {
return false; return false;

View File

@ -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 // deobf: mobInteract
public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) { public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(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. // 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? // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS?
if (!entityhuman.isSneaking() && (flag != EnumInteractionResult.SUCCESS || this.isBaby())) { 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.setSleeping(false);
this.goalSit.setSitting(!this.isSitting()); this.goalSit.setSitting(!this.isSitting());
return flag; return flag;
@ -349,24 +377,7 @@ public class EntityTamableFox extends EntityFox {
Player player = (Player) entityhuman.getBukkitEntity(); Player player = (Player) entityhuman.getBukkitEntity();
player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName());
new AnvilGUI.Builder() rename(player);
.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
} }
} else { } else {
getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D);

View File

@ -40,7 +40,7 @@ public class FoxPathfinderGoalFollowOwner extends PathfinderGoal {
return false; return false;
} else if (entityliving.isSpectator()) { } else if (entityliving.isSpectator()) {
return false; return false;
} else if (this.a.isSitting()) { // this.a.isWillSit() } else if (this.a.isSitting() || this.a.isSleeping()) { // this.a.isWillSit()
return false; return false;
} else if (this.a.h(entityliving) < (double)(this.h * this.h)) { } else if (this.a.h(entityliving) < (double)(this.h * this.h)) {
return false; return false;

View File

@ -1,5 +1,6 @@
package net.seanomik.tamablefoxes.versions.version_1_17_R1; 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.advancements.CriteriaTriggers;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.*; import net.minecraft.network.syncher.*;
@ -45,14 +46,14 @@ import java.util.function.Predicate;
public class EntityTamableFox extends Fox { public class EntityTamableFox extends Fox {
protected static final EntityDataAccessor<Byte> tamed; protected static final EntityDataAccessor<Boolean> tamed;
protected static final EntityDataAccessor<Optional<UUID>> ownerUUID; protected static final EntityDataAccessor<Optional<UUID>> ownerUUID;
//private static final EntityDataAccessor<Byte> bw; // DATA_FLAGS_ID //private static final EntityDataAccessor<Byte> bw; // DATA_FLAGS_ID
private static final Predicate<Entity> AVOID_PLAYERS; // AVOID_PLAYERS private static final Predicate<Entity> AVOID_PLAYERS; // AVOID_PLAYERS
static { static {
tamed = SynchedEntityData.defineId(EntityTamableFox.class, EntityDataSerializers.BYTE); tamed = SynchedEntityData.defineId(EntityTamableFox.class, EntityDataSerializers.BOOLEAN);
ownerUUID = SynchedEntityData.defineId(EntityTamableFox.class, EntityDataSerializers.OPTIONAL_UUID); ownerUUID = SynchedEntityData.defineId(EntityTamableFox.class, EntityDataSerializers.OPTIONAL_UUID);
AVOID_PLAYERS = (entity) -> !entity.isCrouching();// && EntitySelector.test(entity); 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.MAX_HEALTH).setBaseValue(10.0D);
this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(2.0D); this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(2.0D);
} }
this.setTamed(false);
} }
@Override @Override
@ -103,7 +106,7 @@ public class EntityTamableFox extends Fox {
this.goalSelector.addGoal(0, getFoxInnerPathfinderGoal("g")); // FoxFloatGoal this.goalSelector.addGoal(0, getFoxInnerPathfinderGoal("g")); // FoxFloatGoal
this.goalSelector.addGoal(1, getFoxInnerPathfinderGoal("b")); // FaceplantGoal 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(2, new FoxPathfinderGoalSleepWithOwner(this));
this.goalSelector.addGoal(3, getFoxInnerPathfinderGoal("e", Arrays.asList(1.0D), Arrays.asList(double.class))); // FoxBreedGoal 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; 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 @Override
protected void defineSynchedData() { protected void defineSynchedData() {
super.defineSynchedData(); super.defineSynchedData();
this.entityData.define(tamed, (byte) 0); this.entityData.define(tamed, false);
this.entityData.define(ownerUUID, Optional.empty()); 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.setOwnerUUID(ownerUuid);
this.setTamed(true); this.setTamed(true);
} else {
this.setTamed(false);
} }
if (this.goalSitWhenOrdered != null) { if (this.goalSitWhenOrdered != null) {
@ -236,19 +252,15 @@ public class EntityTamableFox extends Fox {
} }
public boolean isTamed() { 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_) { public void setTamed(boolean tamed) {
byte isTamed = this.entityData.get(tamed); this.entityData.set(EntityTamableFox.tamed, tamed);
if (tamed_) {
this.entityData.set(tamed, (byte) (isTamed | 4));
} else {
this.entityData.set(tamed, (byte) (isTamed & -5));
}
this.reassessTameGoals(); this.reassessTameGoals();
if (tamed_) { if (tamed) {
this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(24.0D); this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(24.0D);
this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(3.0D); this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(3.0D);
} else { } 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 @Override
public InteractionResult mobInteract(Player entityhuman, InteractionHand enumhand) { public InteractionResult mobInteract(Player entityhuman, InteractionHand enumhand) {
ItemStack itemstack = entityhuman.getItemInHand(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. // 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? // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS?
if (!entityhuman.isCrouching() && (flag != InteractionResult.SUCCESS || this.isBaby())) { 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.goalSleepWhenOrdered.setOrderedToSleep(false);
this.goalSitWhenOrdered.setOrderedToSit(!this.isOrderedToSit()); this.goalSitWhenOrdered.setOrderedToSit(!this.isOrderedToSit());
return InteractionResult.SUCCESS; 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. // Let the player choose the new fox's name if its enabled in config.
if (Config.askForNameAfterTaming()) { if (Config.askForNameAfterTaming()) {
player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); player.sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName());
new AnvilGUI.Builder() rename(player);
.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
} }
} else { } else {
getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D);

View File

@ -42,6 +42,15 @@ public class FoxPathfinderGoalOwnerHurtByTarget extends TargetGoal {
this.timestamp = entityliving.getLastHurtByMobTimestamp(); this.timestamp = entityliving.getLastHurtByMobTimestamp();
} }
tameAnimal.setDefending(false);
super.start(); super.start();
} }
@Override
public void stop() {
tameAnimal.setDefending(false);
super.stop();
}
} }

View File

@ -42,6 +42,16 @@ public class FoxPathfinderGoalOwnerHurtTarget extends TargetGoal {
this.timestamp = entityliving.getLastHurtMobTimestamp(); this.timestamp = entityliving.getLastHurtMobTimestamp();
} }
tameAnimal.setDefending(true);
super.start(); super.start();
} }
@Override
public void stop() {
tameAnimal.setDefending(false);
super.stop();
}
} }

View File

@ -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();
}
}

View File

@ -22,15 +22,28 @@
<build> <build>
<plugins> <plugins>
<!--<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.8.1</version> <version>3.1.0</version>
<configuration> <configuration>
<source>${java.version}</source> <relocations>
<target>${java.version}</target> <relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>net.seanomik.tamablefoxes.bstats</shadedPattern>
</relocation>
</relocations>
</configuration> </configuration>
</plugin>--> <executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
@ -41,7 +54,7 @@
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration> <configuration>
<outputFile>D:\Code\java\spigotPlugins\servers\${server.version}\plugins\TamableFoxes_v${project.parent.version}.jar</outputFile> <!--<outputFile>D:\Code\java\spigotPlugins\servers\${server.version}\plugins\TamableFoxes_v${project.parent.version}.jar</outputFile>-->
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
</configuration> </configuration>
</execution> </execution>
@ -118,6 +131,12 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- End of entity implementations --> <!-- End of entity implementations -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>net.seanomik</groupId> <groupId>net.seanomik</groupId>
<artifactId>tamablefoxes-util</artifactId> <artifactId>tamablefoxes-util</artifactId>

View File

@ -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_16_R3.NMSInterface_1_16_R3;
import net.seanomik.tamablefoxes.versions.version_1_17_R1.NMSInterface_1_17_R1; import net.seanomik.tamablefoxes.versions.version_1_17_R1.NMSInterface_1_17_R1;
import net.seanomik.tamablefoxes.util.io.LanguageConfig; import net.seanomik.tamablefoxes.util.io.LanguageConfig;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SingleLineChart;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public final class TamableFoxes extends JavaPlugin implements Listener { public final class TamableFoxes extends JavaPlugin implements Listener {
private static TamableFoxes plugin; private static TamableFoxes plugin;
public static final int BSTATS_PLUGIN_ID = 11944;
private boolean versionSupported = true; private boolean versionSupported = true;
@ -65,6 +68,9 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
if (Config.getMaxPlayerFoxTames() != 0) { if (Config.getMaxPlayerFoxTames() != 0) {
SQLiteHelper.getInstance(this).createTablesIfNotExist(); SQLiteHelper.getInstance(this).createTablesIfNotExist();
} }
Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
//metrics.addCustomChart(new SingleLineChart("servers", () -> 1));
} }
@Override @Override