Refactor blockbreaker, add /npc blockbreak
This commit is contained in:
parent
87d27c09dc
commit
be019c0e83
|
@ -69,6 +69,8 @@ import net.citizensnpcs.api.event.PlayerCloneNPCEvent;
|
|||
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
|
||||
import net.citizensnpcs.api.event.SpawnReason;
|
||||
import net.citizensnpcs.api.gui.InventoryMenu;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
|
||||
import net.citizensnpcs.api.npc.MemoryNPCDataStore;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
|
@ -289,7 +291,8 @@ public class NPCCommands {
|
|||
desc = "Edit armorstand properties",
|
||||
modifiers = { "armorstand" },
|
||||
min = 1,
|
||||
max = 1)
|
||||
max = 1,
|
||||
permission = "citizens.npc.armorstand")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.ARMOR_STAND)
|
||||
public void armorstand(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
ArmorStandTrait trait = npc.getOrAddTrait(ArmorStandTrait.class);
|
||||
|
@ -310,6 +313,24 @@ public class NPCCommands {
|
|||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "breakblock --location [x,y,z] --radius [radius]",
|
||||
desc = "Mine a block at the given location or cursor if not specified",
|
||||
modifiers = { "breakblock" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.breakblock")
|
||||
@Requirements(selected = true, ownership = true, livingEntity = true)
|
||||
public void breakblock(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
BlockBreakerConfiguration cfg = new BlockBreakerConfiguration();
|
||||
if (args.hasValueFlag("radius")) {
|
||||
cfg.radius(args.getFlagDouble("radius"));
|
||||
}
|
||||
BlockBreaker breaker = npc.getBlockBreaker(args.getSenderTargetBlockLocation().getBlock(), cfg);
|
||||
npc.getDefaultGoalController().addBehavior(breaker, 1);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "chunkload (-t(emporary))",
|
||||
|
|
|
@ -427,7 +427,7 @@ public class CitizensNPC extends AbstractNPC {
|
|||
private void updateCustomName() {
|
||||
boolean nameVisibility = false;
|
||||
if (!getEntity().isCustomNameVisible()
|
||||
&& !data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString().equals("hover")) {
|
||||
&& !data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString().equals("hover")) {
|
||||
} else if (!requiresNameHologram()) {
|
||||
nameVisibility = true;
|
||||
getEntity().setCustomName(getFullName());
|
||||
|
@ -471,14 +471,18 @@ public class CitizensNPC extends AbstractNPC {
|
|||
private void updateUsingItemState(Player player) {
|
||||
boolean useItem = data().get(NPC.Metadata.USING_HELD_ITEM, false),
|
||||
offhand = data().get(NPC.Metadata.USING_OFFHAND_ITEM, false);
|
||||
if (useItem) {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_MAINHAND_ITEM, player, 64);
|
||||
} else if (offhand) {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_OFFHAND_ITEM, player, 64);
|
||||
} else {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
if (!SUPPORT_USE_ITEM)
|
||||
return;
|
||||
try {
|
||||
if (useItem) {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_MAINHAND_ITEM, player, 64);
|
||||
} else if (offhand) {
|
||||
NMS.playAnimation(PlayerAnimation.STOP_USE_ITEM, player, 64);
|
||||
NMS.playAnimation(PlayerAnimation.START_USE_OFFHAND_ITEM, player, 64);
|
||||
}
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
SUPPORT_USE_ITEM = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -487,4 +491,5 @@ public class CitizensNPC extends AbstractNPC {
|
|||
private static final String NPC_METADATA_MARKER = "NPC";
|
||||
private static boolean SUPPORT_GLOWING = true;
|
||||
private static boolean SUPPORT_SILENT = true;
|
||||
private static boolean SUPPORT_USE_ITEM = true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
package net.citizensnpcs.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
|
||||
public abstract class AbstractBlockBreaker extends BlockBreaker {
|
||||
protected final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
protected final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
protected final int x;
|
||||
protected final int y;
|
||||
protected final int z;
|
||||
|
||||
public AbstractBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = entity;
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
}
|
||||
|
||||
private double distance() {
|
||||
Location loc = entity.getLocation();
|
||||
return Math.sqrt(Math.pow(loc.getX() - x, 2) + Math.pow(loc.getZ() - z, 2));
|
||||
}
|
||||
|
||||
protected abstract float getDamage(int tickDifference);
|
||||
|
||||
protected ItemStack getItemStack() {
|
||||
return configuration.item() != null ? configuration.item()
|
||||
: entity instanceof LivingEntity ? ((LivingEntity) entity).getEquipment().getItemInHand() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (!entity.isValid()) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50);
|
||||
if (configuration.radius() > 0 && distance() >= configuration.radius()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().setTarget(location.clone().add(0, 1, 0));
|
||||
npc.getNavigator().getLocalParameters().distanceMargin(configuration.radius() - 1);
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity, location);
|
||||
if (entity instanceof Player && currentTick % 5 == 0) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity);
|
||||
}
|
||||
if (entity.getWorld().getBlockAt(x, y, z).isEmpty()) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getDamage(tickDifference);
|
||||
if (damage >= 1F) {
|
||||
entity.getWorld().getBlockAt(x, y, z).breakNaturally(getItemStack());
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
protected abstract void setBlockDamage(int damage);
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return !entity.getWorld().getBlockAt(x, y, z).isEmpty();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +1,39 @@
|
|||
package net.citizensnpcs.nms.v1_10_R1.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.server.v1_10_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_10_R1.Blocks;
|
||||
import net.minecraft.server.v1_10_R1.EnchantmentManager;
|
||||
import net.minecraft.server.v1_10_R1.Entity;
|
||||
import net.minecraft.server.v1_10_R1.EntityLiving;
|
||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_10_R1.EnumItemSlot;
|
||||
import net.minecraft.server.v1_10_R1.IBlockData;
|
||||
import net.minecraft.server.v1_10_R1.ItemStack;
|
||||
import net.minecraft.server.v1_10_R1.Material;
|
||||
import net.minecraft.server.v1_10_R1.MobEffects;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.locX - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.locY - y, 2)
|
||||
+ Math.pow(entity.locZ - z, 2);
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_10_R1.ItemStack getCurrentItem() {
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(EnumItemSlot.MAINHAND) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().world.getType(new BlockPosition(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
private float getStrength(IBlockData block) {
|
||||
float base = block.getBlock().b(block, null, new BlockPosition(0, 0, 0));
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
|
@ -71,80 +49,15 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.dead) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
|
||||
if (block == null || block == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.world.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
entity.world.c(entity.getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR;
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
getHandle().world.c(getHandle().getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
private float strengthMod(IBlockData block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.a(block);
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) entity;
|
||||
if (getHandle() instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
|
||||
if (i > 0) {
|
||||
|
@ -172,11 +85,13 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
f *= f1;
|
||||
}
|
||||
if ((handle.a(Material.WATER)) && (!EnchantmentManager.i(handle))) {
|
||||
|
||||
if (handle.a(Material.WATER) && !EnchantmentManager.i(handle)) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
|
||||
}
|
||||
if (!entity.onGround) {
|
||||
if (!getHandle().onGround) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
return f;
|
||||
|
|
|
@ -1,61 +1,39 @@
|
|||
package net.citizensnpcs.nms.v1_11_R1.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_11_R1.Blocks;
|
||||
import net.minecraft.server.v1_11_R1.EnchantmentManager;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityLiving;
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_11_R1.EnumItemSlot;
|
||||
import net.minecraft.server.v1_11_R1.IBlockData;
|
||||
import net.minecraft.server.v1_11_R1.ItemStack;
|
||||
import net.minecraft.server.v1_11_R1.Material;
|
||||
import net.minecraft.server.v1_11_R1.MobEffects;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.locX - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.locY - y, 2)
|
||||
+ Math.pow(entity.locZ - z, 2);
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_11_R1.ItemStack getCurrentItem() {
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(EnumItemSlot.MAINHAND) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().world.getType(new BlockPosition(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
private float getStrength(IBlockData block) {
|
||||
float base = block.getBlock().a(block, null, new BlockPosition(0, 0, 0));
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
|
@ -71,80 +49,15 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.dead) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
|
||||
if (block == null || block == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.world.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
entity.world.c(entity.getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR;
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
getHandle().world.c(getHandle().getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
private float strengthMod(IBlockData block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.a(block);
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) entity;
|
||||
if (getHandle() instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
|
||||
if (i > 0) {
|
||||
|
@ -172,11 +85,13 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
f *= f1;
|
||||
}
|
||||
if ((handle.a(Material.WATER)) && (!EnchantmentManager.i(handle))) {
|
||||
|
||||
if (handle.a(Material.WATER) && !EnchantmentManager.i(handle)) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
|
||||
}
|
||||
if (!entity.onGround) {
|
||||
if (!getHandle().onGround) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
return f;
|
||||
|
|
|
@ -1,61 +1,39 @@
|
|||
package net.citizensnpcs.nms.v1_12_R1.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.Blocks;
|
||||
import net.minecraft.server.v1_12_R1.EnchantmentManager;
|
||||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityLiving;
|
||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_12_R1.EnumItemSlot;
|
||||
import net.minecraft.server.v1_12_R1.IBlockData;
|
||||
import net.minecraft.server.v1_12_R1.ItemStack;
|
||||
import net.minecraft.server.v1_12_R1.Material;
|
||||
import net.minecraft.server.v1_12_R1.MobEffects;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.locX - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.locY - y, 2)
|
||||
+ Math.pow(entity.locZ - z, 2);
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_12_R1.ItemStack getCurrentItem() {
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(EnumItemSlot.MAINHAND) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().world.getType(new BlockPosition(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
private float getStrength(IBlockData block) {
|
||||
float base = block.getBlock().a(block, null, new BlockPosition(0, 0, 0));
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
|
@ -71,80 +49,15 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.dead) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
|
||||
if (block == null || block == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.world.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
entity.world.c(entity.getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR;
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
getHandle().world.c(getHandle().getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
private float strengthMod(IBlockData block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.a(block);
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) entity;
|
||||
if (getHandle() instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
|
||||
if (i > 0) {
|
||||
|
@ -172,11 +85,13 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
f *= f1;
|
||||
}
|
||||
if ((handle.a(Material.WATER)) && (!EnchantmentManager.i(handle))) {
|
||||
|
||||
if (handle.a(Material.WATER) && !EnchantmentManager.i(handle)) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
|
||||
}
|
||||
if (!entity.onGround) {
|
||||
if (!getHandle().onGround) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
return f;
|
||||
|
|
|
@ -1,61 +1,39 @@
|
|||
package net.citizensnpcs.nms.v1_13_R2.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.Blocks;
|
||||
import net.minecraft.server.v1_13_R2.EnchantmentManager;
|
||||
import net.minecraft.server.v1_13_R2.Entity;
|
||||
import net.minecraft.server.v1_13_R2.EntityLiving;
|
||||
import net.minecraft.server.v1_13_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_13_R2.EnumItemSlot;
|
||||
import net.minecraft.server.v1_13_R2.IBlockData;
|
||||
import net.minecraft.server.v1_13_R2.ItemStack;
|
||||
import net.minecraft.server.v1_13_R2.MobEffects;
|
||||
import net.minecraft.server.v1_13_R2.TagsFluid;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.locX - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.locY - y, 2)
|
||||
+ Math.pow(entity.locZ - z, 2);
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_13_R2.ItemStack getCurrentItem() {
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(EnumItemSlot.MAINHAND) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().world.getType(new BlockPosition(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
private float getStrength(IBlockData block) {
|
||||
float base = block.getBlock().a(block, null, new BlockPosition(0, 0, 0));
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
|
@ -71,80 +49,15 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.dead) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
|
||||
if (block == null || block == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.world.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
entity.world.c(entity.getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR;
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
getHandle().world.c(getHandle().getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
private float strengthMod(IBlockData block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.a(block);
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) entity;
|
||||
if (getHandle() instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
|
||||
if (i > 0) {
|
||||
|
@ -178,7 +91,7 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
}
|
||||
if (!entity.onGround) {
|
||||
if (!getHandle().onGround) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
return f;
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
package net.citizensnpcs.nms.v1_14_R1.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_14_R1.Blocks;
|
||||
import net.minecraft.server.v1_14_R1.EnchantmentManager;
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityLiving;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.EnumItemSlot;
|
||||
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||
import net.minecraft.server.v1_14_R1.ItemStack;
|
||||
|
@ -25,38 +14,27 @@ import net.minecraft.server.v1_14_R1.MobEffects;
|
|||
import net.minecraft.server.v1_14_R1.TagsFluid;
|
||||
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.locX - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.locY - y, 2)
|
||||
+ Math.pow(entity.locZ - z, 2);
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_14_R1.ItemStack getCurrentItem() {
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(EnumItemSlot.MAINHAND) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().world.getType(new BlockPosition(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
private float getStrength(IBlockData block) {
|
||||
float base = block.getBlock().a(block, null, new BlockPosition(0, 0, 0));
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
|
@ -72,81 +50,15 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.dead) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
|
||||
if (block == null || block.getBlock() == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.world.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
((WorldServer) entity.world).a(entity.getId(), new BlockPosition(x, y, z), modifiedDamage); // TODO: does this
|
||||
// work?
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR;
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
((WorldServer) getHandle().world).a(getHandle().getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
private float strengthMod(IBlockData block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.a(block);
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) entity;
|
||||
if (getHandle() instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
|
||||
if (i > 0) {
|
||||
|
@ -180,7 +92,7 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
}
|
||||
if (!entity.onGround) {
|
||||
if (!getHandle().onGround) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
return f;
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
package net.citizensnpcs.nms.v1_15_R1.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_15_R1.Blocks;
|
||||
import net.minecraft.server.v1_15_R1.EnchantmentManager;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityLiving;
|
||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_15_R1.EnumItemSlot;
|
||||
import net.minecraft.server.v1_15_R1.IBlockData;
|
||||
import net.minecraft.server.v1_15_R1.ItemStack;
|
||||
|
@ -25,38 +14,27 @@ import net.minecraft.server.v1_15_R1.MobEffects;
|
|||
import net.minecraft.server.v1_15_R1.TagsFluid;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.locX() - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.locY() - y, 2)
|
||||
+ Math.pow(entity.locZ() - z, 2);
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_15_R1.ItemStack getCurrentItem() {
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(EnumItemSlot.MAINHAND) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().world.getType(new BlockPosition(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
private float getStrength(IBlockData block) {
|
||||
float base = block.getBlock().a(block, null, new BlockPosition(0, 0, 0));
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
|
@ -72,81 +50,15 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.dead) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
|
||||
if (block == null || block.getBlock() == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.world.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
((WorldServer) entity.world).a(entity.getId(), new BlockPosition(x, y, z), modifiedDamage); // TODO: does this
|
||||
// work?
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR;
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
((WorldServer) getHandle().world).a(getHandle().getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
private float strengthMod(IBlockData block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.a(block);
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) entity;
|
||||
if (getHandle() instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
|
||||
if (i > 0) {
|
||||
|
@ -180,7 +92,7 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
}
|
||||
if (!entity.onGround) {
|
||||
if (!getHandle().onGround) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
return f;
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
package net.citizensnpcs.nms.v1_16_R3.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R3.Blocks;
|
||||
import net.minecraft.server.v1_16_R3.EnchantmentManager;
|
||||
import net.minecraft.server.v1_16_R3.Entity;
|
||||
import net.minecraft.server.v1_16_R3.EntityLiving;
|
||||
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R3.EnumItemSlot;
|
||||
import net.minecraft.server.v1_16_R3.IBlockData;
|
||||
import net.minecraft.server.v1_16_R3.ItemStack;
|
||||
|
@ -25,31 +14,10 @@ import net.minecraft.server.v1_16_R3.MobEffects;
|
|||
import net.minecraft.server.v1_16_R3.TagsFluid;
|
||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.locX() - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.locY() - y, 2)
|
||||
+ Math.pow(entity.locZ() - z, 2);
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_16_R3.ItemStack getCurrentItem() {
|
||||
|
@ -57,6 +25,16 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
: entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(EnumItemSlot.MAINHAND) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().world.getType(new BlockPosition(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
private float getStrength(IBlockData block) {
|
||||
float base = block.h(null, new BlockPosition(0, 0, 0));
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
|
@ -72,81 +50,15 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.dead) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
|
||||
if (block == null || block.getBlock() == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.world.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
((WorldServer) entity.world).a(entity.getId(), new BlockPosition(x, y, z), modifiedDamage); // TODO: does this
|
||||
// work?
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR;
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
((WorldServer) getHandle().world).a(getHandle().getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
private float strengthMod(IBlockData block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.a(block);
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) entity;
|
||||
if (getHandle() instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
|
||||
if (i > 0) {
|
||||
|
@ -180,7 +92,7 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
}
|
||||
if (!entity.isOnGround()) {
|
||||
if (!getHandle().isOnGround()) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
return f;
|
||||
|
|
|
@ -1,20 +1,10 @@
|
|||
package net.citizensnpcs.nms.v1_17_R1.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.world.effect.MobEffectUtil;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
|
@ -22,42 +12,30 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.getX() - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.getY() - y, 2)
|
||||
+ Math.pow(entity.getZ() - z, 2);
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof LivingEntity ? ((LivingEntity) entity).getMainHandItem() : null;
|
||||
: getHandle() instanceof LivingEntity ? ((LivingEntity) getHandle()).getMainHandItem() : null;
|
||||
}
|
||||
|
||||
private float getStrength(BlockState block) {
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().level.getBlockState(new BlockPos(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
protected float getStrength(BlockState block) {
|
||||
float base = block.getDestroySpeed(null, BlockPos.ZERO);
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
}
|
||||
|
@ -72,81 +50,17 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.isRemoved()) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.level.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof ServerPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
BlockState block = entity.level.getBlockState(new BlockPos(x, y, z));
|
||||
if (block == null || block.getBlock() == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.level.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
((ServerLevel) entity.level).destroyBlockProgress(entity.getId(), new BlockPos(x, y, z), modifiedDamage);
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
((ServerLevel) getHandle().level).destroyBlockProgress(getHandle().getId(), new BlockPos(x, y, z),
|
||||
modifiedDamage);
|
||||
// TODO: check this works
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.level.getBlockState(new BlockPos(x, y, z)).getBlock() != Blocks.AIR;
|
||||
}
|
||||
|
||||
private float strengthMod(BlockState block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.getDestroySpeed(block);
|
||||
if (entity instanceof LivingEntity) {
|
||||
LivingEntity handle = (LivingEntity) entity;
|
||||
if (getHandle() instanceof LivingEntity) {
|
||||
LivingEntity handle = (LivingEntity) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentHelper.getBlockEfficiency(handle);
|
||||
if (i > 0) {
|
||||
|
@ -178,8 +92,8 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
if (handle.isEyeInFluid(FluidTags.WATER) && !EnchantmentHelper.hasAquaAffinity(handle)) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!entity.isOnGround()) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,16 @@ public abstract class MobEntityController extends AbstractEntityController {
|
|||
entity.setOnGround(true);
|
||||
}
|
||||
entity.setUUID(npc.getUniqueId());
|
||||
|
||||
/*String name = npc.getFullName().length() > 16 ? npc.getFullName().substring(0, 16) : npc.getFullName();
|
||||
String teamName = Util.getTeamName(npc.getUniqueId());
|
||||
if (npc.requiresNameHologram()) {
|
||||
name = teamName;
|
||||
}
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
Util.generateTeamFor(npc, name, teamName);
|
||||
}*/
|
||||
return entity.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,9 +56,7 @@ public class RavagerController extends MobEntityController {
|
|||
|
||||
@Override
|
||||
public boolean canBeControlledByRider() {
|
||||
return (npc == null || npc.data().<Boolean> get(NPC.Metadata.USE_MINECRAFT_AI, false))
|
||||
? super.canBeControlledByRider()
|
||||
: false;
|
||||
return (npc == null || npc.useMinecraftAI()) ? super.canBeControlledByRider() : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,20 +1,10 @@
|
|||
package net.citizensnpcs.nms.v1_18_R1.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.world.effect.MobEffectUtil;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
|
@ -22,42 +12,30 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.getX() - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.getY() - y, 2)
|
||||
+ Math.pow(entity.getZ() - z, 2);
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof LivingEntity ? ((LivingEntity) entity).getMainHandItem() : null;
|
||||
: getHandle() instanceof LivingEntity ? ((LivingEntity) getHandle()).getMainHandItem() : null;
|
||||
}
|
||||
|
||||
private float getStrength(BlockState block) {
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().level.getBlockState(new BlockPos(x, y, z))) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
protected float getStrength(BlockState block) {
|
||||
float base = block.getDestroySpeed(null, BlockPos.ZERO);
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
}
|
||||
|
@ -72,81 +50,17 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.isRemoved()) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.level.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof ServerPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
BlockState block = entity.level.getBlockState(new BlockPos(x, y, z));
|
||||
if (block == null || block.getBlock() == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.level.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
((ServerLevel) entity.level).destroyBlockProgress(entity.getId(), new BlockPos(x, y, z), modifiedDamage);
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
((ServerLevel) getHandle().level).destroyBlockProgress(getHandle().getId(), new BlockPos(x, y, z),
|
||||
modifiedDamage);
|
||||
// TODO: check this works
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.level.getBlockState(new BlockPos(x, y, z)).getBlock() != Blocks.AIR;
|
||||
}
|
||||
|
||||
private float strengthMod(BlockState block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.getDestroySpeed(block);
|
||||
if (entity instanceof LivingEntity) {
|
||||
LivingEntity handle = (LivingEntity) entity;
|
||||
if (getHandle() instanceof LivingEntity) {
|
||||
LivingEntity handle = (LivingEntity) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentHelper.getBlockEfficiency(handle);
|
||||
if (i > 0) {
|
||||
|
@ -178,8 +92,8 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
if (handle.isEyeInFluid(FluidTags.WATER) && !EnchantmentHelper.hasAquaAffinity(handle)) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!entity.isOnGround()) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
|
|
|
@ -1,61 +1,38 @@
|
|||
package net.citizensnpcs.nms.v1_8_R3.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.ai.tree.BehaviorStatus;
|
||||
import net.citizensnpcs.api.npc.BlockBreaker;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.citizensnpcs.util.AbstractBlockBreaker;
|
||||
import net.minecraft.server.v1_8_R3.Block;
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.Blocks;
|
||||
import net.minecraft.server.v1_8_R3.EnchantmentManager;
|
||||
import net.minecraft.server.v1_8_R3.Entity;
|
||||
import net.minecraft.server.v1_8_R3.EntityLiving;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.IBlockData;
|
||||
import net.minecraft.server.v1_8_R3.ItemStack;
|
||||
import net.minecraft.server.v1_8_R3.Material;
|
||||
import net.minecraft.server.v1_8_R3.MobEffectList;
|
||||
|
||||
public class CitizensBlockBreaker extends BlockBreaker {
|
||||
private final BlockBreakerConfiguration configuration;
|
||||
private int currentDamage;
|
||||
private int currentTick;
|
||||
private final Entity entity;
|
||||
private boolean isDigging = true;
|
||||
private final Location location;
|
||||
private boolean setTarget;
|
||||
private int startDigTick;
|
||||
private final int x, y, z;
|
||||
|
||||
public class CitizensBlockBreaker extends AbstractBlockBreaker {
|
||||
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
|
||||
BlockBreakerConfiguration config) {
|
||||
this.entity = ((CraftEntity) entity).getHandle();
|
||||
this.x = target.getX();
|
||||
this.y = target.getY();
|
||||
this.z = target.getZ();
|
||||
this.location = target.getLocation();
|
||||
this.startDigTick = (int) (System.currentTimeMillis() / 50);
|
||||
this.configuration = config;
|
||||
super(entity, target, config);
|
||||
}
|
||||
|
||||
private double distanceSquared() {
|
||||
return Math.pow(entity.locX - x, 2) + Math.pow(NMS.getHeight(entity.getBukkitEntity()) + entity.locY - y, 2)
|
||||
+ Math.pow(entity.locZ - z, 2);
|
||||
}
|
||||
|
||||
private net.minecraft.server.v1_8_R3.ItemStack getCurrentItem() {
|
||||
private ItemStack getCurrentItem() {
|
||||
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
|
||||
: entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(0) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage(int tickDifference) {
|
||||
return getStrength(getHandle().world.getType(new BlockPosition(x, y, z)).getBlock()) * (tickDifference + 1)
|
||||
* configuration.blockStrengthModifier();
|
||||
}
|
||||
|
||||
private Entity getHandle() {
|
||||
return NMSImpl.getHandle(entity);
|
||||
}
|
||||
|
||||
private float getStrength(Block block) {
|
||||
float base = block.g(null, new BlockPosition(0, 0, 0));
|
||||
return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F);
|
||||
|
@ -71,80 +48,15 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
if (setTarget && entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
setTarget = false;
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
setBlockDamage(currentDamage = -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviorStatus run() {
|
||||
if (entity.dead) {
|
||||
return BehaviorStatus.FAILURE;
|
||||
}
|
||||
if (!isDigging) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
|
||||
startDigTick = currentTick;
|
||||
if (entity instanceof NPCHolder) {
|
||||
NPC npc = ((NPCHolder) entity).getNPC();
|
||||
if (npc != null && !npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator()
|
||||
.setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
|
||||
setTarget = true;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
Util.faceLocation(entity.getBukkitEntity(), location);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
|
||||
}
|
||||
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
|
||||
if (block == null || block == Blocks.AIR) {
|
||||
return BehaviorStatus.SUCCESS;
|
||||
} else {
|
||||
int tickDifference = currentTick - startDigTick;
|
||||
float damage = getStrength(block.getBlock()) * (tickDifference + 1) * configuration.blockStrengthModifier();
|
||||
if (damage >= 1F) {
|
||||
entity.world.getWorld().getBlockAt(x, y, z)
|
||||
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
|
||||
return BehaviorStatus.SUCCESS;
|
||||
}
|
||||
int modifiedDamage = (int) (damage * 10.0F);
|
||||
if (modifiedDamage != currentDamage) {
|
||||
setBlockDamage(modifiedDamage);
|
||||
currentDamage = modifiedDamage;
|
||||
}
|
||||
}
|
||||
return BehaviorStatus.RUNNING;
|
||||
}
|
||||
|
||||
private void setBlockDamage(int modifiedDamage) {
|
||||
entity.world.c(entity.getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR;
|
||||
protected void setBlockDamage(int modifiedDamage) {
|
||||
getHandle().world.c(getHandle().getId(), new BlockPosition(x, y, z), modifiedDamage);
|
||||
}
|
||||
|
||||
private float strengthMod(Block block) {
|
||||
ItemStack itemstack = getCurrentItem();
|
||||
float f = itemstack.a(block);
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) entity;
|
||||
if (getHandle() instanceof EntityLiving) {
|
||||
EntityLiving handle = (EntityLiving) getHandle();
|
||||
if (f > 1.0F) {
|
||||
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
|
||||
if (i > 0) {
|
||||
|
@ -172,11 +84,13 @@ public class CitizensBlockBreaker extends BlockBreaker {
|
|||
}
|
||||
f *= f1;
|
||||
}
|
||||
if ((handle.a(Material.WATER)) && (!EnchantmentManager.j(handle))) {
|
||||
|
||||
if (handle.a(Material.WATER) && !EnchantmentManager.j(handle)) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
|
||||
}
|
||||
if (!entity.onGround) {
|
||||
if (!getHandle().onGround) {
|
||||
f /= 5.0F;
|
||||
}
|
||||
return f;
|
||||
|
|
Loading…
Reference in New Issue