Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-16 21:10:17 +01:00
Implement the API for ItemFrames. Adds BUKKIT-2668
Dieser Commit ist enthalten in:
Ursprung
02ca9be079
Commit
63eaf74d44
@ -1,7 +1,13 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import net.minecraft.server.EntityItemFrame;
|
||||
import net.minecraft.server.ItemStack;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Rotation;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
|
||||
@ -10,6 +16,61 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
public void setItem(org.bukkit.inventory.ItemStack item) {
|
||||
if (item == null || item.getTypeId() == 0) {
|
||||
getHandle().getDataWatcher().a(2, 5);
|
||||
getHandle().getDataWatcher().h(2);
|
||||
} else {
|
||||
getHandle().a(CraftItemStack.createNMSItemStack(item));
|
||||
}
|
||||
}
|
||||
|
||||
public org.bukkit.inventory.ItemStack getItem() {
|
||||
ItemStack i = getHandle().i();
|
||||
return i == null ? new org.bukkit.inventory.ItemStack(Material.AIR) : new CraftItemStack(i);
|
||||
}
|
||||
|
||||
public Rotation getRotation() {
|
||||
return toBukkitRotation(getHandle().j());
|
||||
}
|
||||
|
||||
Rotation toBukkitRotation(int value) {
|
||||
// Translate NMS rotation integer to Bukkit API
|
||||
switch (value) {
|
||||
case 0:
|
||||
return Rotation.NONE;
|
||||
case 1:
|
||||
return Rotation.CLOCKWISE;
|
||||
case 2:
|
||||
return Rotation.FLIPPED;
|
||||
case 3:
|
||||
return Rotation.COUNTER_CLOCKWISE;
|
||||
default:
|
||||
throw new AssertionError("Unknown rotation " + getHandle().j() + " for " + getHandle());
|
||||
}
|
||||
}
|
||||
|
||||
public void setRotation(Rotation rotation) {
|
||||
Validate.notNull(rotation, "Rotation cannot be null");
|
||||
getHandle().g(toInteger(rotation));
|
||||
}
|
||||
|
||||
static int toInteger(Rotation rotation) {
|
||||
// Translate Bukkit API rotation to NMS integer
|
||||
switch (rotation) {
|
||||
case NONE:
|
||||
return 0;
|
||||
case CLOCKWISE:
|
||||
return 1;
|
||||
case FLIPPED:
|
||||
return 2;
|
||||
case COUNTER_CLOCKWISE:
|
||||
return 3;
|
||||
default:
|
||||
throw new IllegalArgumentException(rotation + " is not applicable to an ItemFrame");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityItemFrame getHandle() {
|
||||
return (EntityItemFrame) entity;
|
||||
@ -17,7 +78,7 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftItemFrame";
|
||||
return "CraftItemFrame{item=" + getItem() + ", rotation=" + getRotation() + "}";
|
||||
}
|
||||
|
||||
public EntityType getType() {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren