-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
EntityItemProjectileImpl.java
91 lines (76 loc) · 2.97 KB
/
EntityItemProjectileImpl.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
package com.denizenscript.denizen.nms.v1_17.impl.entities;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.google.common.base.Preconditions;
import net.minecraft.server.v1_16_R3.*;
import org.bukkit.Location;
import java.lang.invoke.MethodHandle;
public class EntityItemProjectileImpl extends EntityProjectile {
public static MethodHandle setBukkitEntityMethod = ReflectionHelper.getFinalSetter(Entity.class, "bukkitEntity");
public static final DataWatcherObject<ItemStack> ITEM;
static {
DataWatcherObject<ItemStack> watcher = null;
try {
watcher = (DataWatcherObject<ItemStack>) ReflectionHelper.getFields(EntityItem.class).get("ITEM").get(null);
}
catch (Throwable ex) {
Debug.echoError(ex);
}
ITEM = watcher;
}
public EntityItemProjectileImpl(World world, Location location, ItemStack item) {
super((EntityTypes) EntityTypes.ITEM, world);
try {
setBukkitEntityMethod.invoke(this, new CraftItemProjectileImpl(world.getServer(), this));
}
catch (Throwable ex) {
Debug.echoError(ex);
}
setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
setItemStack(item);
}
@Override
protected void initDatawatcher() {
this.getDataWatcher().register(ITEM, ItemStack.b);
}
public ItemStack getItemStack() {
return this.getDataWatcher().get(ITEM);
}
public void setItemStack(ItemStack itemstack) {
Preconditions.checkArgument(!itemstack.isEmpty(), "Cannot drop air");
this.getDataWatcher().set(ITEM, itemstack);
this.getDataWatcher().markDirty(ITEM);
}
@Override
protected void a(MovingObjectPositionBlock movingobjectpositionblock) {
super.a(movingobjectpositionblock);
die();
}
@Override
public void a(DataWatcherObject<?> datawatcherobject) {
super.a(datawatcherobject);
if (ITEM.equals(datawatcherobject)) {
this.getItemStack().a(this);
}
}
@Override
public void saveData(NBTTagCompound nbttagcompound) {
if (!this.getItemStack().isEmpty()) {
nbttagcompound.set("Item", this.getItemStack().save(new NBTTagCompound()));
}
super.saveData(nbttagcompound);
}
@Override
public void loadData(NBTTagCompound nbttagcompound) {
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("Item");
this.setItemStack(ItemStack.a(nbttagcompound1));
if (this.getItemStack().isEmpty()) {
this.die();
}
super.loadData(nbttagcompound);
}
@Override
public CraftItemProjectileImpl getBukkitEntity() {
return (CraftItemProjectileImpl) super.getBukkitEntity();
}
}