mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Added full tile entity data support for all block types that use it, including chests, dispensers, furnaces, mob spawners, and note blocks.
By: sk89q <the.sk89q@gmail.com>
This commit is contained in:
parent
bde24c6ec9
commit
b49ed260f6
@ -288,6 +288,17 @@ public class CraftBlock implements Block {
|
||||
case SIGN_POST:
|
||||
case WALL_SIGN:
|
||||
return new CraftSign(this);
|
||||
case CHEST:
|
||||
return new CraftChest(this);
|
||||
case BURNING_FURNACE:
|
||||
case FURNACE:
|
||||
return new CraftFurnace(this);
|
||||
case DISPENSER:
|
||||
return new CraftDispenser(this);
|
||||
case MOB_SPAWNER:
|
||||
return new CraftMobSpawner(this);
|
||||
case NOTE_BLOCK:
|
||||
return new CraftNoteBlock(this);
|
||||
default:
|
||||
return new CraftBlockState(this);
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.server.TileEntityChest;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
/**
|
||||
* Represents a chest.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CraftChest extends CraftBlockState implements Chest {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityChest chest;
|
||||
|
||||
public CraftChest(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld)block.getWorld();
|
||||
chest = (TileEntityChest)world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventory(chest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force) {
|
||||
boolean result = super.update(force);
|
||||
|
||||
if (result) {
|
||||
chest.d();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.server.TileEntityDispenser;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
/**
|
||||
* Represents a dispenser.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CraftDispenser extends CraftBlockState implements Dispenser {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityDispenser dispenser;
|
||||
|
||||
public CraftDispenser(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld)block.getWorld();
|
||||
dispenser = (TileEntityDispenser)world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventory(dispenser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force) {
|
||||
boolean result = super.update(force);
|
||||
|
||||
if (result) {
|
||||
dispenser.d();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.server.TileEntityFurnace;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
/**
|
||||
* Represents a furnace.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CraftFurnace extends CraftBlockState implements Furnace {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityFurnace furnace;
|
||||
|
||||
public CraftFurnace(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld)block.getWorld();
|
||||
furnace = (TileEntityFurnace)world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventory(furnace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force) {
|
||||
boolean result = super.update(force);
|
||||
|
||||
if (result) {
|
||||
furnace.d();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public short getBurnTime() {
|
||||
return (short)furnace.e;
|
||||
}
|
||||
|
||||
public void setBurnTime(short burnTime) {
|
||||
furnace.e = burnTime;
|
||||
}
|
||||
|
||||
public short getCookTime() {
|
||||
return (short)furnace.g;
|
||||
}
|
||||
|
||||
public void setCookTime(short cookTime) {
|
||||
furnace.g = cookTime;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.server.TileEntityMobSpawner;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.MobSpawner;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.MobType;
|
||||
|
||||
public class CraftMobSpawner extends CraftBlockState implements MobSpawner {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityMobSpawner spawner;
|
||||
|
||||
public CraftMobSpawner(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld)block.getWorld();
|
||||
spawner = (TileEntityMobSpawner)world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public MobType getMobType() {
|
||||
return MobType.fromName(spawner.h);
|
||||
}
|
||||
|
||||
public void setMobType(MobType mobType) {
|
||||
spawner.h = mobType.getName();
|
||||
}
|
||||
|
||||
public String getMobTypeId() {
|
||||
return spawner.h;
|
||||
}
|
||||
|
||||
public void setMobTypeId(String mobType) {
|
||||
// Verify input
|
||||
MobType type = MobType.fromName(mobType);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
spawner.h = type.getName();
|
||||
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
return spawner.e;
|
||||
}
|
||||
|
||||
public void setDelay(int delay) {
|
||||
spawner.e = delay;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.server.TileEntityNote;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.NoteBlock;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
||||
/**
|
||||
* Represents a note block.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CraftNoteBlock extends CraftBlockState implements NoteBlock {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityNote note;
|
||||
|
||||
public CraftNoteBlock(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld)block.getWorld();
|
||||
note = (TileEntityNote)world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public byte getNote() {
|
||||
return note.e;
|
||||
}
|
||||
|
||||
public void setNote(byte n) {
|
||||
note.e = n;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user