SPIGOT-5311: Add API to get/set item associated with throwable projectiles

This commit is contained in:
Lars Dormans 2020-02-21 09:53:51 +11:00 committed by md_5
parent 689f429c50
commit f7cdb53c0e
10 changed files with 97 additions and 7 deletions

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/server/EntityFireballFireball.java
+++ b/net/minecraft/server/EntityFireballFireball.java
@@ -18,7 +18,7 @@
@@ -18,14 +18,14 @@
public void b(ItemStack itemstack) {
if (itemstack.getItem() != Items.FIRE_CHARGE || itemstack.hasTag()) {
@ -9,6 +9,14 @@
itemstack1.setCount(1);
}));
}
}
- protected ItemStack l() {
+ public ItemStack l() { // PAIL protected -> public
return (ItemStack) this.getDataWatcher().get(EntityFireballFireball.f);
}
@@ -50,6 +50,6 @@
super.a(nbttagcompound);
ItemStack itemstack = ItemStack.a(nbttagcompound.getCompound("Item"));

View File

@ -11,3 +11,18 @@
}));
}
@@ -27,7 +27,13 @@
protected abstract Item i();
- protected ItemStack getItem() {
+ // CraftBukkit start
+ public Item getDefaultItem() {
+ return i();
+ }
+ // CraftBukkit end
+
+ public ItemStack getItem() { // PAIL protected -> public
return (ItemStack) this.getDataWatcher().get(EntityProjectileThrowable.e);
}

View File

@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Egg;
import org.bukkit.entity.EntityType;
public class CraftEgg extends CraftProjectile implements Egg {
public class CraftEgg extends CraftThrowableProjectile implements Egg {
public CraftEgg(CraftServer server, EntityEgg entity) {
super(server, entity);
}

View File

@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.EntityType;
public class CraftEnderPearl extends CraftProjectile implements EnderPearl {
public class CraftEnderPearl extends CraftThrowableProjectile implements EnderPearl {
public CraftEnderPearl(CraftServer server, EntityEnderPearl entity) {
super(server, entity);
}

View File

@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LargeFireball;
public class CraftLargeFireball extends CraftFireball implements LargeFireball {
public class CraftLargeFireball extends CraftSizedFireball implements LargeFireball {
public CraftLargeFireball(CraftServer server, EntityLargeFireball entity) {
super(server, entity);
}

View File

@ -0,0 +1,34 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityFireballFireball;
import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.SizedFireball;
import org.bukkit.inventory.ItemStack;
public class CraftSizedFireball extends CraftFireball implements SizedFireball {
public CraftSizedFireball(CraftServer server, EntityFireballFireball entity) {
super(server, entity);
}
@Override
public ItemStack getDisplayItem() {
if (getHandle().l().isEmpty()) { // PAIL rename getItem
return new ItemStack(Material.FIRE_CHARGE);
} else {
return CraftItemStack.asBukkitCopy(getHandle().l()); // PAIL rename getItem
}
}
@Override
public void setDisplayItem(ItemStack item) {
getHandle().b(CraftItemStack.asNMSCopy(item)); // PAIL rename setItem
}
@Override
public EntityFireballFireball getHandle() {
return (EntityFireballFireball) entity;
}
}

View File

@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.SmallFireball;
public class CraftSmallFireball extends CraftFireball implements SmallFireball {
public class CraftSmallFireball extends CraftSizedFireball implements SmallFireball {
public CraftSmallFireball(CraftServer server, EntitySmallFireball entity) {
super(server, entity);
}

View File

@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Snowball;
public class CraftSnowball extends CraftProjectile implements Snowball {
public class CraftSnowball extends CraftThrowableProjectile implements Snowball {
public CraftSnowball(CraftServer server, EntitySnowball entity) {
super(server, entity);
}

View File

@ -0,0 +1,33 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityProjectileThrowable;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.ThrowableProjectile;
import org.bukkit.inventory.ItemStack;
public abstract class CraftThrowableProjectile extends CraftProjectile implements ThrowableProjectile {
public CraftThrowableProjectile(CraftServer server, EntityProjectileThrowable entity) {
super(server, entity);
}
@Override
public ItemStack getItem() {
if (getHandle().getItem().isEmpty()) {
return CraftItemStack.asBukkitCopy(new net.minecraft.server.ItemStack(getHandle().getDefaultItem()));
} else {
return CraftItemStack.asBukkitCopy(getHandle().getItem());
}
}
@Override
public void setItem(ItemStack item) {
getHandle().setItem(CraftItemStack.asNMSCopy(item));
}
@Override
public EntityProjectileThrowable getHandle() {
return (EntityProjectileThrowable) entity;
}
}

View File

@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ThrownExpBottle;
public class CraftThrownExpBottle extends CraftProjectile implements ThrownExpBottle {
public class CraftThrownExpBottle extends CraftThrowableProjectile implements ThrownExpBottle {
public CraftThrownExpBottle(CraftServer server, EntityThrownExpBottle entity) {
super(server, entity);
}