SPIGOT-2871: Improve BlockStates + BlockStateMeta

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2016-12-02 09:29:33 +11:00
parent 159538aaba
commit a00951dd57
16 changed files with 275 additions and 28 deletions

View File

@@ -323,6 +323,16 @@ public class CraftBlock implements Block {
case RED_SHULKER_BOX:
case BLACK_SHULKER_BOX:
return new CraftShulkerBox(this);
case ENCHANTMENT_TABLE:
return new CraftEnchantingTable(this);
case ENDER_CHEST:
return new CraftEnderChest(this);
case DAYLIGHT_DETECTOR:
case DAYLIGHT_DETECTOR_INVERTED:
return new CraftDaylightDetector(this);
case REDSTONE_COMPARATOR_OFF:
case REDSTONE_COMPARATOR_ON:
return new CraftComparator(this);
default:
return new CraftBlockState(this);
}

View File

@@ -0,0 +1,33 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntity;
import net.minecraft.server.TileEntityComparator;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.EnderChest;
import org.bukkit.craftbukkit.CraftWorld;
public class CraftComparator extends CraftBlockState implements EnderChest {
private final CraftWorld world;
private final TileEntityComparator comparator;
public CraftComparator(final Block block) {
super(block);
world = (CraftWorld) block.getWorld();
comparator = (TileEntityComparator) world.getTileEntityAt(getX(), getY(), getZ());
}
public CraftComparator(final Material material, final TileEntityComparator te) {
super(material);
comparator = te;
world = null;
}
@Override
public TileEntity getTileEntity() {
return comparator;
}
}

View File

@@ -1,7 +1,7 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.ChestLock;
import net.minecraft.server.TileEntity;
import net.minecraft.server.ITileInventory;
import net.minecraft.server.TileEntityContainer;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -10,7 +10,7 @@ import org.bukkit.craftbukkit.CraftWorld;
public class CraftContainer extends CraftBlockState implements Lockable {
private final TileEntityContainer container;
private final ITileInventory container;
public CraftContainer(Block block) {
super(block);
@@ -18,10 +18,10 @@ public class CraftContainer extends CraftBlockState implements Lockable {
container = (TileEntityContainer) ((CraftWorld) block.getWorld()).getTileEntityAt(block.getX(), block.getY(), block.getZ());
}
public CraftContainer(final Material material, TileEntity tileEntity) {
public CraftContainer(final Material material, ITileInventory tileEntity) {
super(material);
container = (TileEntityContainer) tileEntity;
container = tileEntity;
}
@Override

View File

@@ -0,0 +1,33 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntity;
import net.minecraft.server.TileEntityLightDetector;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.EnderChest;
import org.bukkit.craftbukkit.CraftWorld;
public class CraftDaylightDetector extends CraftBlockState implements EnderChest {
private final CraftWorld world;
private final TileEntityLightDetector detector;
public CraftDaylightDetector(final Block block) {
super(block);
world = (CraftWorld) block.getWorld();
detector = (TileEntityLightDetector) world.getTileEntityAt(getX(), getY(), getZ());
}
public CraftDaylightDetector(final Material material, final TileEntityLightDetector te) {
super(material);
detector = te;
world = null;
}
@Override
public TileEntity getTileEntity() {
return detector;
}
}

View File

@@ -0,0 +1,43 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntity;
import net.minecraft.server.TileEntityEnchantTable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.block.EnchantingTable;
public class CraftEnchantingTable extends CraftBlockState implements EnchantingTable {
private final CraftWorld world;
private final TileEntityEnchantTable enchant;
public CraftEnchantingTable(final Block block) {
super(block);
world = (CraftWorld) block.getWorld();
enchant = (TileEntityEnchantTable) world.getTileEntityAt(getX(), getY(), getZ());
}
public CraftEnchantingTable(final Material material, final TileEntityEnchantTable te) {
super(material);
enchant = te;
world = null;
}
@Override
public TileEntity getTileEntity() {
return enchant;
}
@Override
public String getCustomName() {
return enchant.hasCustomName() ? enchant.getName() : null;
}
@Override
public void setCustomName(String name) {
enchant.a(name); // PAIL: setCustomName
}
}

View File

@@ -0,0 +1,33 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntity;
import net.minecraft.server.TileEntityEnderChest;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.EnderChest;
import org.bukkit.craftbukkit.CraftWorld;
public class CraftEnderChest extends CraftBlockState implements EnderChest {
private final CraftWorld world;
private final TileEntityEnderChest chest;
public CraftEnderChest(final Block block) {
super(block);
world = (CraftWorld) block.getWorld();
chest = (TileEntityEnderChest) world.getTileEntityAt(getX(), getY(), getZ());
}
public CraftEnderChest(final Material material, final TileEntityEnderChest te) {
super(material);
chest = te;
world = null;
}
@Override
public TileEntity getTileEntity() {
return chest;
}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.ItemStack;
import net.minecraft.server.TileEntity;
import net.minecraft.server.TileEntityFlowerPot;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -26,6 +27,11 @@ public class CraftFlowerPot extends CraftBlockState implements FlowerPot {
this.pot = pot;
}
@Override
public TileEntity getTileEntity() {
return pot;
}
@Override
public MaterialData getContents() {
return (pot.d() == null) ? null : CraftMagicNumbers.getMaterial(pot.getItem()).getNewData((byte) pot.getData()); // PAIL: rename

View File

@@ -1,6 +1,5 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntity;
import net.minecraft.server.TileEntityLootable;
import org.bukkit.Material;
import org.bukkit.Nameable;
@@ -17,10 +16,10 @@ public class CraftLootable extends CraftContainer implements Nameable {
te = (TileEntityLootable) ((CraftWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ());
}
public CraftLootable(Material material, TileEntity tileEntity) {
public CraftLootable(Material material, TileEntityLootable tileEntity) {
super(material, tileEntity);
te = (TileEntityLootable) tileEntity;
te = tileEntity;
}
@Override

View File

@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntity;
import net.minecraft.server.TileEntityStructure;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -20,4 +21,9 @@ public class CraftStructureBlock extends CraftBlockState {
this.structure = structure;
}
@Override
public TileEntity getTileEntity() {
return structure;
}
}