SPIGOT-231 and SPIGOT-229. Fix itemframe behaviour.

Confirmed fix for itemframes not showing up. Based on the code in
CraftPainting.
Besids this fix we now pass null itemstacks directly to the
EntityItemFrame to allow the removal of items in ItemFrames.
This commit is contained in:
FearThe1337 2014-12-17 23:45:49 +01:00 committed by md_5
parent ce7dd34b5c
commit 89944c09c9

View File

@ -1,6 +1,9 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import net.minecraft.server.BlockPosition;
import net.minecraft.server.EntityItemFrame; import net.minecraft.server.EntityItemFrame;
import net.minecraft.server.EnumDirection;
import net.minecraft.server.ItemStack;
import net.minecraft.server.WorldServer; import net.minecraft.server.WorldServer;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
@ -23,16 +26,31 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
return false; return false;
} }
WorldServer world = ((CraftWorld) this.getWorld()).getHandle(); update();
world.getTracker().untrackEntity(this.getHandle());
world.getTracker().track(this.getHandle());
return true; return true;
} }
private void update() {
EntityItemFrame old = this.getHandle();
WorldServer world = ((CraftWorld) getWorld()).getHandle();
BlockPosition position = old.getBlockPosition();
EnumDirection direction = old.getDirection();
ItemStack item = old.getItem() != null ? old.getItem().cloneItemStack() : null;
old.die();
EntityItemFrame frame = new EntityItemFrame(world,position,direction);
frame.setItem(item);
world.addEntity(frame);
this.entity = frame;
}
public void setItem(org.bukkit.inventory.ItemStack item) { public void setItem(org.bukkit.inventory.ItemStack item) {
if (item == null || item.getTypeId() == 0) { if (item == null || item.getTypeId() == 0) {
getHandle().getDataWatcher().add(2, 5); getHandle().setItem(null);
getHandle().getDataWatcher().update(2);
} else { } else {
getHandle().setItem(CraftItemStack.asNMSCopy(item)); getHandle().setItem(CraftItemStack.asNMSCopy(item));
} }