diff options
author | md_5 <git@md-5.net> | 2016-09-18 09:58:54 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2016-09-18 09:58:54 +1000 |
commit | 6af9f5b84a18f0c40e1ad3893a5de27fb3c35fd3 (patch) | |
tree | 09f33711b87268a0334ebb3228a9b2912d1fca03 /src/main/java/org | |
parent | 75a8885d1fbb8f1bb38ef3d6a0f03598893c01ed (diff) | |
download | craftbukkit-6af9f5b84a18f0c40e1ad3893a5de27fb3c35fd3.tar craftbukkit-6af9f5b84a18f0c40e1ad3893a5de27fb3c35fd3.tar.gz craftbukkit-6af9f5b84a18f0c40e1ad3893a5de27fb3c35fd3.tar.lz craftbukkit-6af9f5b84a18f0c40e1ad3893a5de27fb3c35fd3.tar.xz craftbukkit-6af9f5b84a18f0c40e1ad3893a5de27fb3c35fd3.zip |
SPIGOT-2679: Add meta for StructureBlock
Diffstat (limited to 'src/main/java/org')
5 files changed, 42 insertions, 5 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index 03addbd6..89b23e29 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -304,6 +304,8 @@ public class CraftBlock implements Block { return new CraftBanner(this); case FLOWER_POT: return new CraftFlowerPot(this); + case STRUCTURE_BLOCK: + return new CraftStructureBlock(this); default: return new CraftBlockState(this); } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java new file mode 100644 index 00000000..038aa21d --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java @@ -0,0 +1,23 @@ +package org.bukkit.craftbukkit.block; + +import net.minecraft.server.TileEntityStructure; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.CraftWorld; + +public class CraftStructureBlock extends CraftBlockState { + + private final TileEntityStructure structure; + + public CraftStructureBlock(Block block) { + super(block); + + this.structure = (TileEntityStructure) ((CraftWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ()); + } + + public CraftStructureBlock(Material material, TileEntityStructure structure) { + super(material); + + this.structure = structure; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java index 2e6c5669..4e4a46f1 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java @@ -113,6 +113,7 @@ public final class CraftItemFactory implements ItemFactory { case REDSTONE_COMPARATOR: case FLOWER_POT_ITEM: case SHIELD: + case STRUCTURE_BLOCK: return new CraftMetaBlockState(meta, material); default: return new CraftMetaItem(meta); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index 8b6fd4ff..6f5dcbd6 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -374,6 +374,7 @@ public final class CraftItemStack extends ItemStack { case REDSTONE_COMPARATOR: case FLOWER_POT_ITEM: case SHIELD: + case STRUCTURE_BLOCK: return new CraftMetaBlockState(item.getTag(), CraftMagicNumbers.getMaterial(item.getItem())); default: return new CraftMetaItem(item.getTag()); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java index ee36785e..b9d4717f 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java @@ -4,7 +4,6 @@ import com.google.common.base.Objects; import com.google.common.collect.ImmutableMap; import java.util.Map; import net.minecraft.server.BlockJukeBox; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.NBTBase; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.TileEntity; @@ -23,6 +22,7 @@ import net.minecraft.server.TileEntityMobSpawner; import net.minecraft.server.TileEntityNote; import net.minecraft.server.TileEntitySign; import net.minecraft.server.TileEntitySkull; +import net.minecraft.server.TileEntityStructure; import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.BlockState; @@ -44,14 +44,15 @@ import org.bukkit.craftbukkit.block.CraftJukebox; import org.bukkit.craftbukkit.block.CraftNoteBlock; import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.craftbukkit.block.CraftSkull; +import org.bukkit.craftbukkit.block.CraftStructureBlock; import org.bukkit.inventory.meta.BlockStateMeta; @DelegateDeserialization(CraftMetaItem.SerializableMeta.class) public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta { - + @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) static final ItemMetaKey BLOCK_ENTITY_TAG = new ItemMetaKey("BlockEntityTag"); - + final Material material; NBTTagCompound blockEntityTag; @@ -72,7 +73,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta CraftMetaBlockState(NBTTagCompound tag, Material material) { super(tag); this.material = material; - + if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) { blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT); } else { @@ -94,7 +95,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta @Override void applyToItem(NBTTagCompound tag) { super.applyToItem(tag); - + if (blockEntityTag != null) { tag.set(BLOCK_ENTITY_TAG.NBT, blockEntityTag); } @@ -179,6 +180,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta case REDSTONE_COMPARATOR: case FLOWER_POT_ITEM: case SHIELD: + case STRUCTURE_BLOCK: return true; } return false; @@ -286,6 +288,11 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta te = new TileEntityFlowerPot(); } return new CraftFlowerPot(material, (TileEntityFlowerPot) te); + case STRUCTURE_BLOCK: + if (te == null) { + te = new TileEntityStructure(); + } + return new CraftStructureBlock(material, (TileEntityStructure) te); default: throw new IllegalStateException("Missing blockState for " + material); } @@ -356,6 +363,9 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta case FLOWER_POT_ITEM: valid = te instanceof TileEntityFlowerPot; break; + case STRUCTURE_BLOCK: + valid = te instanceof TileEntityStructure; + break; default: valid = false; break; |