-
-
Notifications
You must be signed in to change notification settings - Fork 307
/
CitizensBlockBreaker.java
97 lines (88 loc) · 3.66 KB
/
CitizensBlockBreaker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package net.citizensnpcs.nms.v1_11_R1.util;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
import net.citizensnpcs.util.AbstractBlockBreaker;
import net.minecraft.server.v1_11_R1.BlockPosition;
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.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 AbstractBlockBreaker {
public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target,
BlockBreakerConfiguration config) {
super(entity, target, config);
}
private ItemStack getCurrentItem() {
return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item())
: getHandle() instanceof EntityLiving ? ((EntityLiving) getHandle()).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);
}
private boolean isDestroyable(IBlockData block) {
if (block.getMaterial().isAlwaysDestroyable()) {
return true;
} else {
ItemStack current = getCurrentItem();
return current != null ? current.b(block) : false;
}
}
@Override
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 (getHandle() instanceof EntityLiving) {
EntityLiving handle = (EntityLiving) getHandle();
if (f > 1.0F) {
int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
if (i > 0) {
f += i * i + 1;
}
}
if (handle.hasEffect(MobEffects.FASTER_DIG)) {
f *= (1.0F + (handle.getEffect(MobEffects.FASTER_DIG).getAmplifier() + 1) * 0.2F);
}
if (handle.hasEffect(MobEffects.SLOWER_DIG)) {
float f1 = 1.0F;
switch (handle.getEffect(MobEffects.SLOWER_DIG).getAmplifier()) {
case 0:
f1 = 0.3F;
break;
case 1:
f1 = 0.09F;
break;
case 2:
f1 = 0.0027F;
break;
case 3:
default:
f1 = 8.1E-4F;
}
f *= f1;
}
if (handle.a(Material.WATER) && !EnchantmentManager.i(handle)) {
f /= 5.0F;
}
}
if (!getHandle().onGround) {
f /= 5.0F;
}
return f;
}
}