mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 13:06:02 +01:00
SPIGOT-2679: Add meta for StructureBlock
This commit is contained in:
parent
75a8885d1f
commit
6af9f5b84a
@ -304,6 +304,8 @@ public class CraftBlock implements Block {
|
|||||||
return new CraftBanner(this);
|
return new CraftBanner(this);
|
||||||
case FLOWER_POT:
|
case FLOWER_POT:
|
||||||
return new CraftFlowerPot(this);
|
return new CraftFlowerPot(this);
|
||||||
|
case STRUCTURE_BLOCK:
|
||||||
|
return new CraftStructureBlock(this);
|
||||||
default:
|
default:
|
||||||
return new CraftBlockState(this);
|
return new CraftBlockState(this);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -113,6 +113,7 @@ public final class CraftItemFactory implements ItemFactory {
|
|||||||
case REDSTONE_COMPARATOR:
|
case REDSTONE_COMPARATOR:
|
||||||
case FLOWER_POT_ITEM:
|
case FLOWER_POT_ITEM:
|
||||||
case SHIELD:
|
case SHIELD:
|
||||||
|
case STRUCTURE_BLOCK:
|
||||||
return new CraftMetaBlockState(meta, material);
|
return new CraftMetaBlockState(meta, material);
|
||||||
default:
|
default:
|
||||||
return new CraftMetaItem(meta);
|
return new CraftMetaItem(meta);
|
||||||
|
@ -374,6 +374,7 @@ public final class CraftItemStack extends ItemStack {
|
|||||||
case REDSTONE_COMPARATOR:
|
case REDSTONE_COMPARATOR:
|
||||||
case FLOWER_POT_ITEM:
|
case FLOWER_POT_ITEM:
|
||||||
case SHIELD:
|
case SHIELD:
|
||||||
|
case STRUCTURE_BLOCK:
|
||||||
return new CraftMetaBlockState(item.getTag(), CraftMagicNumbers.getMaterial(item.getItem()));
|
return new CraftMetaBlockState(item.getTag(), CraftMagicNumbers.getMaterial(item.getItem()));
|
||||||
default:
|
default:
|
||||||
return new CraftMetaItem(item.getTag());
|
return new CraftMetaItem(item.getTag());
|
||||||
|
@ -4,7 +4,6 @@ import com.google.common.base.Objects;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.minecraft.server.BlockJukeBox;
|
import net.minecraft.server.BlockJukeBox;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.NBTBase;
|
import net.minecraft.server.NBTBase;
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
import net.minecraft.server.TileEntity;
|
import net.minecraft.server.TileEntity;
|
||||||
@ -23,6 +22,7 @@ import net.minecraft.server.TileEntityMobSpawner;
|
|||||||
import net.minecraft.server.TileEntityNote;
|
import net.minecraft.server.TileEntityNote;
|
||||||
import net.minecraft.server.TileEntitySign;
|
import net.minecraft.server.TileEntitySign;
|
||||||
import net.minecraft.server.TileEntitySkull;
|
import net.minecraft.server.TileEntitySkull;
|
||||||
|
import net.minecraft.server.TileEntityStructure;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
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.CraftNoteBlock;
|
||||||
import org.bukkit.craftbukkit.block.CraftSign;
|
import org.bukkit.craftbukkit.block.CraftSign;
|
||||||
import org.bukkit.craftbukkit.block.CraftSkull;
|
import org.bukkit.craftbukkit.block.CraftSkull;
|
||||||
|
import org.bukkit.craftbukkit.block.CraftStructureBlock;
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
|
|
||||||
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
|
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
|
||||||
public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta {
|
public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta {
|
||||||
|
|
||||||
@ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT)
|
@ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT)
|
||||||
static final ItemMetaKey BLOCK_ENTITY_TAG = new ItemMetaKey("BlockEntityTag");
|
static final ItemMetaKey BLOCK_ENTITY_TAG = new ItemMetaKey("BlockEntityTag");
|
||||||
|
|
||||||
final Material material;
|
final Material material;
|
||||||
NBTTagCompound blockEntityTag;
|
NBTTagCompound blockEntityTag;
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|||||||
CraftMetaBlockState(NBTTagCompound tag, Material material) {
|
CraftMetaBlockState(NBTTagCompound tag, Material material) {
|
||||||
super(tag);
|
super(tag);
|
||||||
this.material = material;
|
this.material = material;
|
||||||
|
|
||||||
if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) {
|
if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) {
|
||||||
blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
|
blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
|
||||||
} else {
|
} else {
|
||||||
@ -94,7 +95,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|||||||
@Override
|
@Override
|
||||||
void applyToItem(NBTTagCompound tag) {
|
void applyToItem(NBTTagCompound tag) {
|
||||||
super.applyToItem(tag);
|
super.applyToItem(tag);
|
||||||
|
|
||||||
if (blockEntityTag != null) {
|
if (blockEntityTag != null) {
|
||||||
tag.set(BLOCK_ENTITY_TAG.NBT, blockEntityTag);
|
tag.set(BLOCK_ENTITY_TAG.NBT, blockEntityTag);
|
||||||
}
|
}
|
||||||
@ -179,6 +180,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|||||||
case REDSTONE_COMPARATOR:
|
case REDSTONE_COMPARATOR:
|
||||||
case FLOWER_POT_ITEM:
|
case FLOWER_POT_ITEM:
|
||||||
case SHIELD:
|
case SHIELD:
|
||||||
|
case STRUCTURE_BLOCK:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -286,6 +288,11 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|||||||
te = new TileEntityFlowerPot();
|
te = new TileEntityFlowerPot();
|
||||||
}
|
}
|
||||||
return new CraftFlowerPot(material, (TileEntityFlowerPot) te);
|
return new CraftFlowerPot(material, (TileEntityFlowerPot) te);
|
||||||
|
case STRUCTURE_BLOCK:
|
||||||
|
if (te == null) {
|
||||||
|
te = new TileEntityStructure();
|
||||||
|
}
|
||||||
|
return new CraftStructureBlock(material, (TileEntityStructure) te);
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Missing blockState for " + material);
|
throw new IllegalStateException("Missing blockState for " + material);
|
||||||
}
|
}
|
||||||
@ -356,6 +363,9 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|||||||
case FLOWER_POT_ITEM:
|
case FLOWER_POT_ITEM:
|
||||||
valid = te instanceof TileEntityFlowerPot;
|
valid = te instanceof TileEntityFlowerPot;
|
||||||
break;
|
break;
|
||||||
|
case STRUCTURE_BLOCK:
|
||||||
|
valid = te instanceof TileEntityStructure;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user