Fire EntityDamageByEntityEvent for ItemFrames. This allows them to be protected more effectively.
This commit is contained in:
parent
6ec37d4fe9
commit
83a93937f7
|
@ -1,4 +1,4 @@
|
|||
From 820960f77326fbb326aeab226fc1a3859e3eb274 Mon Sep 17 00:00:00 2001
|
||||
From cead4c266909b279e8eeeea1d021d1f647b150e5 Mon Sep 17 00:00:00 2001
|
||||
From: md_5 <md_5@live.com.au>
|
||||
Date: Sun, 1 Dec 2013 15:10:48 +1100
|
||||
Subject: [PATCH] mc-dev imports
|
||||
|
@ -406,6 +406,158 @@ index 0000000..6d5090b
|
|||
+ return false;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityItemFrame.java b/src/main/java/net/minecraft/server/EntityItemFrame.java
|
||||
new file mode 100644
|
||||
index 0000000..261d0c1
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/minecraft/server/EntityItemFrame.java
|
||||
@@ -0,0 +1,146 @@
|
||||
+package net.minecraft.server;
|
||||
+
|
||||
+public class EntityItemFrame extends EntityHanging {
|
||||
+
|
||||
+ private float e = 1.0F;
|
||||
+
|
||||
+ public EntityItemFrame(World world) {
|
||||
+ super(world);
|
||||
+ }
|
||||
+
|
||||
+ public EntityItemFrame(World world, int i, int j, int k, int l) {
|
||||
+ super(world, i, j, k, l);
|
||||
+ this.setDirection(l);
|
||||
+ }
|
||||
+
|
||||
+ protected void c() {
|
||||
+ this.getDataWatcher().a(2, 5);
|
||||
+ this.getDataWatcher().a(3, Byte.valueOf((byte) 0));
|
||||
+ }
|
||||
+
|
||||
+ public boolean damageEntity(DamageSource damagesource, float f) {
|
||||
+ if (this.isInvulnerable()) {
|
||||
+ return false;
|
||||
+ } else if (this.getItem() != null) {
|
||||
+ if (!this.world.isStatic) {
|
||||
+ this.b(damagesource.getEntity(), false);
|
||||
+ this.setItem((ItemStack) null);
|
||||
+ }
|
||||
+
|
||||
+ return true;
|
||||
+ } else {
|
||||
+ return super.damageEntity(damagesource, f);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public int f() {
|
||||
+ return 9;
|
||||
+ }
|
||||
+
|
||||
+ public int i() {
|
||||
+ return 9;
|
||||
+ }
|
||||
+
|
||||
+ public void b(Entity entity) {
|
||||
+ this.b(entity, true);
|
||||
+ }
|
||||
+
|
||||
+ public void b(Entity entity, boolean flag) {
|
||||
+ ItemStack itemstack = this.getItem();
|
||||
+
|
||||
+ if (entity instanceof EntityHuman) {
|
||||
+ EntityHuman entityhuman = (EntityHuman) entity;
|
||||
+
|
||||
+ if (entityhuman.abilities.canInstantlyBuild) {
|
||||
+ this.b(itemstack);
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (flag) {
|
||||
+ this.a(new ItemStack(Items.ITEM_FRAME), 0.0F);
|
||||
+ }
|
||||
+
|
||||
+ if (itemstack != null && this.random.nextFloat() < this.e) {
|
||||
+ itemstack = itemstack.cloneItemStack();
|
||||
+ this.b(itemstack);
|
||||
+ this.a(itemstack, 0.0F);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private void b(ItemStack itemstack) {
|
||||
+ if (itemstack != null) {
|
||||
+ if (itemstack.getItem() == Items.MAP) {
|
||||
+ WorldMap worldmap = ((ItemWorldMap) itemstack.getItem()).getSavedMap(itemstack, this.world);
|
||||
+
|
||||
+ worldmap.g.remove("frame-" + this.getId());
|
||||
+ }
|
||||
+
|
||||
+ itemstack.a((EntityItemFrame) null);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public ItemStack getItem() {
|
||||
+ return this.getDataWatcher().getItemStack(2);
|
||||
+ }
|
||||
+
|
||||
+ public void setItem(ItemStack itemstack) {
|
||||
+ if (itemstack != null) {
|
||||
+ itemstack = itemstack.cloneItemStack();
|
||||
+ itemstack.count = 1;
|
||||
+ itemstack.a(this);
|
||||
+ }
|
||||
+
|
||||
+ this.getDataWatcher().watch(2, itemstack);
|
||||
+ this.getDataWatcher().h(2);
|
||||
+ }
|
||||
+
|
||||
+ public int getRotation() {
|
||||
+ return this.getDataWatcher().getByte(3);
|
||||
+ }
|
||||
+
|
||||
+ public void setRotation(int i) {
|
||||
+ this.getDataWatcher().watch(3, Byte.valueOf((byte) (i % 4)));
|
||||
+ }
|
||||
+
|
||||
+ public void b(NBTTagCompound nbttagcompound) {
|
||||
+ if (this.getItem() != null) {
|
||||
+ nbttagcompound.set("Item", this.getItem().save(new NBTTagCompound()));
|
||||
+ nbttagcompound.setByte("ItemRotation", (byte) this.getRotation());
|
||||
+ nbttagcompound.setFloat("ItemDropChance", this.e);
|
||||
+ }
|
||||
+
|
||||
+ super.b(nbttagcompound);
|
||||
+ }
|
||||
+
|
||||
+ public void a(NBTTagCompound nbttagcompound) {
|
||||
+ NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("Item");
|
||||
+
|
||||
+ if (nbttagcompound1 != null && !nbttagcompound1.isEmpty()) {
|
||||
+ this.setItem(ItemStack.createStack(nbttagcompound1));
|
||||
+ this.setRotation(nbttagcompound.getByte("ItemRotation"));
|
||||
+ if (nbttagcompound.hasKeyOfType("ItemDropChance", 99)) {
|
||||
+ this.e = nbttagcompound.getFloat("ItemDropChance");
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ super.a(nbttagcompound);
|
||||
+ }
|
||||
+
|
||||
+ public boolean c(EntityHuman entityhuman) {
|
||||
+ if (this.getItem() == null) {
|
||||
+ ItemStack itemstack = entityhuman.be();
|
||||
+
|
||||
+ if (itemstack != null && !this.world.isStatic) {
|
||||
+ this.setItem(itemstack);
|
||||
+ if (!entityhuman.abilities.canInstantlyBuild && --itemstack.count <= 0) {
|
||||
+ entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
|
||||
+ }
|
||||
+ }
|
||||
+ } else if (!this.world.isStatic) {
|
||||
+ this.setRotation(this.getRotation() + 1);
|
||||
+ }
|
||||
+
|
||||
+ return true;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/minecraft/server/NextTickListEntry.java b/src/main/java/net/minecraft/server/NextTickListEntry.java
|
||||
new file mode 100644
|
||||
index 0000000..06934a1
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
From 44a4aeef7c0503db9894cd45b16d0dc8a93848f6 Mon Sep 17 00:00:00 2001
|
||||
From: md_5 <md_5@live.com.au>
|
||||
Date: Thu, 5 Dec 2013 18:41:32 +1100
|
||||
Subject: [PATCH] Fire EntityDamageByEntityEvent for ItemFrames
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityItemFrame.java b/src/main/java/net/minecraft/server/EntityItemFrame.java
|
||||
index 261d0c1..58d0d26 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityItemFrame.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityItemFrame.java
|
||||
@@ -23,6 +23,15 @@ public class EntityItemFrame extends EntityHanging {
|
||||
return false;
|
||||
} else if (this.getItem() != null) {
|
||||
if (!this.world.isStatic) {
|
||||
+ // Spigot Start
|
||||
+ org.bukkit.event.entity.EntityDamageByEntityEvent event = new org.bukkit.event.entity.EntityDamageByEntityEvent(
|
||||
+ damagesource.getEntity().getBukkitEntity(), getBukkitEntity(), org.bukkit.event.entity.EntityDamageEvent.DamageCause.ENTITY_ATTACK, f );
|
||||
+ getBukkitEntity().getServer().getPluginManager().callEvent( event );
|
||||
+ if ( event.isCancelled() )
|
||||
+ {
|
||||
+ return false;
|
||||
+ }
|
||||
+ // Spigot End
|
||||
this.b(damagesource.getEntity(), false);
|
||||
this.setItem((ItemStack) null);
|
||||
}
|
||||
--
|
||||
1.8.3.2
|
||||
|
Loading…
Reference in New Issue