diff --git a/.idea/misc.xml b/.idea/misc.xml index 28ed9dc..06cebc3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -15,7 +15,7 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fe486a4..92a3d76 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,20 @@ + + + + + + + + + + + + - - - - - - - - - - @@ -190,10 +180,10 @@ - + - + @@ -201,6 +191,10 @@ + + + + @@ -219,31 +213,31 @@ - - + + - + - - + + - + - - + + - + - - + + - + @@ -308,20 +302,20 @@ - - + + - + - + - + @@ -360,16 +354,6 @@ - - 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 diff --git a/pom.xml b/pom.xml index 2999840..2443ffb 100644 --- a/pom.xml +++ b/pom.xml @@ -39,8 +39,8 @@ shade - - C:\Users\Checkium\Desktop\vps\smp\SMP\plugins\TamableFoxes-MC-v1.15.X-v${project.version}.jar + D:\Code\java\spigotPlugins\_TEST_SERVER_1.15.2_\plugins\TamableFoxes-MC-v1.15.1-v${project.version}.jar + false @@ -71,18 +71,18 @@ - - + + diff --git a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java index 539e3fd..6a84901 100644 --- a/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java +++ b/src/main/java/net/seanomik/tamablefoxes/EntityTamableFox.java @@ -1,10 +1,9 @@ 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.*; -import org.apache.commons.lang.reflect.FieldUtils; +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.event.entity.EntityRegainHealthEvent; @@ -33,8 +32,6 @@ public class EntityTamableFox extends EntityFox { public EntityTamableFox(EntityTypes entitytypes, World world) { super(entitytypes, world); - // clearPathFinderGoals(); - //initPathfinderGoals(); } @Override @@ -143,7 +140,7 @@ public class EntityTamableFox extends EntityFox { this.getAttributeMap().b(GenericAttributes.ARMOR_TOUGHNESS); // Default value is 32, might want to make this configurable in the future - this.getAttributeMap().b(GenericAttributes.FOLLOW_RANGE).setValue(16.0D); + this.getAttributeMap().b(GenericAttributes.FOLLOW_RANGE).setValue(32.0D); this.getAttributeMap().b(GenericAttributes.ATTACK_KNOCKBACK); @@ -161,6 +158,7 @@ public class EntityTamableFox extends EntityFox { public static Object getPrivateField(String fieldName, Class clazz, Object object) { Field field; Object o = null; + try { field = clazz.getDeclaredField(fieldName); field.setAccessible(true); @@ -168,6 +166,7 @@ public class EntityTamableFox extends EntityFox { } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } + return o; } @@ -193,12 +192,14 @@ public class EntityTamableFox extends EntityFox { 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)); @@ -207,9 +208,11 @@ public class EntityTamableFox extends EntityFox { this.setTamed(false); } } + if (this.goalSit != null) { this.goalSit.setSitting(compound.getBoolean("Sitting")); } + this.setSitting(compound.getBoolean("Sitting")); } @@ -236,8 +239,10 @@ public class EntityTamableFox extends EntityFox { } } + // Remove untamed goals if its tamed. private void reassessTameGoals() { if (!isTamed()) return; + for (PathfinderGoal untamedGoal : untamedGoals) { this.goalSelector.a(untamedGoal); } @@ -247,50 +252,77 @@ public class EntityTamableFox extends EntityFox { 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()) { + + // Heal the fox if its health is below the max. if (item.isFood() && item.getFoodInfo().c() && this.getHealth() < this.getMaxHealth()) { + // Only remove the item from the player if they're in survival mode. if (!entityhuman.abilities.canInstantlyBuild) { itemstack.subtract(1); } + this.heal((float)item.getFoodInfo().getNutrition(), EntityRegainHealthEvent.RegainReason.EATING); return true; } if (isOwnedBy(entityhuman)) { + // This super method checks if the fox can breed or not. boolean flag = super.a(entityhuman, enumhand); + + // If the player is not sneaking and the fox cannot breed, then make the fox sit. if (!entityhuman.isSneaking() && (!flag || this.isBaby())) { this.goalSit.setSitting(!this.isSitting()); return flag; - } else if (entityhuman.isSneaking()) { + } else if (entityhuman.isSneaking()) { // Swap/Put/Take item from fox. 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); - } + + // Run this task async to make sure to not slow the server down. + // This is needed due to the item being remove as soon as its put in the foxes mouth. + Bukkit.getScheduler().runTaskLaterAsynchronously(TamableFoxes.getPlugin(), ()-> { + // Put item in mouth + if (item != Items.AIR) { + ItemStack c = itemstack.cloneItemStack(); + c.setCount(1); + + // Only remove the item from the player if they're in survival mode. + if (!entityhuman.abilities.canInstantlyBuild) { + itemstack.subtract(1); + } + + this.setSlot(EnumItemSlot.MAINHAND, c); + } + }, (long) 0.1); + + return true; } } - // TODO: take/give items - } else if (item == Items.SWEET_BERRIES) { + } else if (item == Items.CHICKEN) { + // Only remove the item from the player if they're in survival mode. if (!entityhuman.abilities.canInstantlyBuild) { itemstack.subtract(1); } + + // 0.33% chance to tame the fox, also check if the called tame entity event is cancelled or not. if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { this.tame(entityhuman); + + // Remove all navigation when tamed. 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; } @@ -298,14 +330,11 @@ public class EntityTamableFox extends EntityFox { } } - // deobf: isFood (used for breeding) - public boolean i(ItemStack itemstack) { - Item item = itemstack.getItem(); - return item.isFood() && item.getFoodInfo().c(); - } - + @Override public EntityTamableFox createChild(EntityAgeable entityageable) { EntityTamableFox entityFox = (EntityTamableFox) EntityTypes.FOX.a(this.world); + entityFox.setFoxType(this.getFoxType()); + UUID uuid = this.getOwnerUUID(); if (uuid != null) { entityFox.setOwnerUUID(uuid); @@ -321,8 +350,8 @@ public class EntityTamableFox extends EntityFox { } else if (!(entityanimal instanceof EntityTamableFox)) { return false; } else { - EntityTamableFox entitywolf = (EntityTamableFox)entityanimal; - return (!entitywolf.isSitting() && (this.isInLove() && entitywolf.isInLove())); + EntityTamableFox entityFox = (EntityTamableFox) entityanimal; + return (!entityFox.isSitting() && (this.isInLove() && entityFox.isInLove())); } } @@ -338,12 +367,11 @@ public class EntityTamableFox extends EntityFox { 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 + + // Give the player the taming advancement. if (owner instanceof EntityPlayer) { CriterionTriggers.x.a((EntityPlayer)owner, this); } - */ } @Nullable @@ -356,7 +384,7 @@ public class EntityTamableFox extends EntityFox { } } - // deobf: canAttack + // Only attack entity if its not attacking owner. public boolean c(EntityLiving entity) { return !this.isOwnedBy(entity) && super.c(entity); } @@ -366,7 +394,7 @@ public class EntityTamableFox extends EntityFox { } /* - deobf: wantsToAttack (copied from EntityWolf) + 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 */ @@ -387,6 +415,7 @@ public class EntityTamableFox extends EntityFox { } } + // Set the scoreboard team to the same as the owner if its tamed. public ScoreboardTeamBase getScoreboardTeam() { if (this.isTamed()) { EntityLiving var0 = this.getOwner(); @@ -398,13 +427,14 @@ public class EntityTamableFox extends EntityFox { return super.getScoreboardTeam(); } - // override isAlliedTo + // Override isAlliedTo (Entity::r(Entity)) public boolean r(Entity entity) { if (this.isTamed()) { EntityLiving entityOwner = this.getOwner(); if (entity == entityOwner) { return true; } + if (entityOwner != null) { return entityOwner.r(entity); } @@ -412,6 +442,7 @@ public class EntityTamableFox extends EntityFox { return super.r(entity); } + // When the fox dies, show a chat message. 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()); @@ -445,5 +476,4 @@ public class EntityTamableFox extends EntityFox { goalEnumSet.clear(); targetEnumSet.clear(); } - } diff --git a/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java b/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java index 5e0dd72..8c2c456 100644 --- a/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java +++ b/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java @@ -2,36 +2,15 @@ package net.seanomik.tamablefoxes; 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 org.bukkit.*; -import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.player.PlayerBedEnterEvent; -import org.bukkit.event.player.PlayerBedLeaveEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.event.world.WorldSaveEvent; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; // @TODO: diff --git a/target/classes/config.yml b/target/classes/config.yml index 44fd464..d6183f6 100644 --- a/target/classes/config.yml +++ b/target/classes/config.yml @@ -1,7 +1,7 @@ -# Config for Tamable Foxes -show-owner-in-fox-name: false -enable-taming-permission: true -ask-for-name-after-taming: false - -tamed-behavior: +# Config for Tamable Foxes +show-owner-in-fox-name: false +enable-taming-permission: true +ask-for-name-after-taming: true + +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 a839e2d..f2c9ef3 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -1,19 +1,19 @@ -name: Tamablefoxes -version: 1.6.0-SNAPSHOT -main: net.seanomik.tamablefoxes.TamableFoxes -api-version: 1.15 -load: STARTUP -description: Adds tamable foxes to Minecraft! - -commands: - spawntamablefox: - aliases: [tamablefox, stf, spawntf] - usage: /spawntamablefox [type] - description: Spawn a tamable fox at the standing location. Type can be snow or red, or left empty for a red. -permissions: - tamablefoxes.spawn: - description: "Gives the player the ability to spawn tamable foxes." - default: false - tamablefoxes.tame: - description: "Gives the player the ability to tame a fox." - default: false +name: Tamablefoxes +version: 1.6.0-SNAPSHOT +main: net.seanomik.tamablefoxes.TamableFoxes +api-version: 1.15 +load: STARTUP +description: Adds tamable foxes to Minecraft! + +commands: + spawntamablefox: + aliases: [tamablefox, stf, spawntf] + usage: /spawntamablefox [type] + description: Spawn a tamable fox at the standing location. Type can be snow or red, or left empty for a red. +permissions: + tamablefoxes.spawn: + description: "Gives the player the ability to spawn tamable foxes." + default: false + tamablefoxes.tame: + description: "Gives the player the ability to tame a fox." + default: false 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 93cca77..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 @@ -1,7 +1,6 @@ net\seanomik\tamablefoxes\EntityTamableFox.class net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalMeleeAttack.class net\seanomik\tamablefoxes\versions\version_1_15\pathfinding\FoxPathfinderGoalPanic.class -net\seanomik\tamablefoxes\EntityTamableFox$1.class 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