Initial commit (Forge 1291).
This commit is contained in:
37
src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
Normal file
37
src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
Normal file
@ -0,0 +1,37 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityBeacon;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Beacon;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryBeacon;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class CraftBeacon extends CraftBlockState implements Beacon {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityBeacon beacon;
|
||||
|
||||
public CraftBeacon(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld) block.getWorld();
|
||||
beacon = (TileEntityBeacon) world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventoryBeacon(beacon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
beacon.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
621
src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
Normal file
621
src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
Normal file
@ -0,0 +1,621 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.BlockRedstoneWire;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.tileentity.TileEntitySkull;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.PistonMoveReaction;
|
||||
import org.bukkit.craftbukkit.CraftChunk;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.BlockVector;
|
||||
// Cauldron start
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraftforge.cauldron.block.CraftCustomContainer;
|
||||
// Cauldron end
|
||||
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
||||
public class CraftBlock implements Block {
|
||||
private final CraftChunk chunk;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
// Cauldron start - add support for custom biomes
|
||||
private static final Biome[] BIOME_MAPPING = new Biome[BiomeGenBase.getBiomeGenArray().length];
|
||||
private static final BiomeGenBase[] BIOMEBASE_MAPPING = new BiomeGenBase[BiomeGenBase.getBiomeGenArray().length];
|
||||
// Cauldron end
|
||||
|
||||
public CraftBlock(CraftChunk chunk, int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
private net.minecraft.block.Block getNMSBlock() {
|
||||
return CraftMagicNumbers.getBlock(this); // TODO: UPDATE THIS
|
||||
}
|
||||
|
||||
private static net.minecraft.block.Block getNMSBlock(int type) {
|
||||
return CraftMagicNumbers.getBlock(type);
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return chunk.getWorld();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return new Location(getWorld(), x, y, z);
|
||||
}
|
||||
|
||||
public Location getLocation(Location loc) {
|
||||
if (loc != null) {
|
||||
loc.setWorld(getWorld());
|
||||
loc.setX(x);
|
||||
loc.setY(y);
|
||||
loc.setZ(z);
|
||||
loc.setYaw(0);
|
||||
loc.setPitch(0);
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
public BlockVector getVector() {
|
||||
return new BlockVector(x, y, z);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public void setData(final byte data) {
|
||||
chunk.getHandle().worldObj.setBlockMetadataWithNotify(x, y, z, data, 3);
|
||||
}
|
||||
|
||||
public void setData(final byte data, boolean applyPhysics) {
|
||||
if (applyPhysics) {
|
||||
chunk.getHandle().worldObj.setBlockMetadataWithNotify(x, y, z, data, 3);
|
||||
} else {
|
||||
chunk.getHandle().worldObj.setBlockMetadataWithNotify(x, y, z, data, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public byte getData() {
|
||||
return (byte) chunk.getHandle().getBlockMetadata(this.x & 0xF, this.y & 0xFF, this.z & 0xF);
|
||||
}
|
||||
|
||||
public void setType(final Material type) {
|
||||
setTypeId(type.getId());
|
||||
}
|
||||
|
||||
public boolean setTypeId(final int type) {
|
||||
return setTypeId(type, true);
|
||||
}
|
||||
|
||||
public boolean setTypeId(final int type, final boolean applyPhysics) {
|
||||
return setTypeIdAndData(type, getData(), applyPhysics);
|
||||
}
|
||||
|
||||
public boolean setTypeIdAndData(final int type, final byte data, final boolean applyPhysics) {
|
||||
if (applyPhysics) {
|
||||
return chunk.getHandle().worldObj.setBlock(x, y, z, getNMSBlock(type), data, 3);
|
||||
} else {
|
||||
boolean success = chunk.getHandle().worldObj.setBlock(x, y, z, getNMSBlock(type), data, 2);
|
||||
if (success) {
|
||||
chunk.getHandle().worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
public Material getType() {
|
||||
return Material.getMaterial(getTypeId());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public int getTypeId() {
|
||||
return CraftMagicNumbers.getId(chunk.getHandle().getBlock(this.x & 0xF, this.y & 0xFF, this.z & 0xF));
|
||||
}
|
||||
|
||||
public byte getLightLevel() {
|
||||
return (byte) chunk.getHandle().worldObj.getBlockLightValue(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
public byte getLightFromSky() {
|
||||
return (byte) chunk.getHandle().getSavedLightValue(EnumSkyBlock.Sky, this.x & 0xF, this.y & 0xFF, this.z & 0xF);
|
||||
}
|
||||
|
||||
public byte getLightFromBlocks() {
|
||||
return (byte) chunk.getHandle().getSavedLightValue(EnumSkyBlock.Block, this.x & 0xF, this.y & 0xFF, this.z & 0xF);
|
||||
}
|
||||
|
||||
|
||||
public Block getFace(final BlockFace face) {
|
||||
return getRelative(face, 1);
|
||||
}
|
||||
|
||||
public Block getFace(final BlockFace face, final int distance) {
|
||||
return getRelative(face, distance);
|
||||
}
|
||||
|
||||
public Block getRelative(final int modX, final int modY, final int modZ) {
|
||||
return getWorld().getBlockAt(getX() + modX, getY() + modY, getZ() + modZ);
|
||||
}
|
||||
|
||||
public Block getRelative(BlockFace face) {
|
||||
return getRelative(face, 1);
|
||||
}
|
||||
|
||||
public Block getRelative(BlockFace face, int distance) {
|
||||
return getRelative(face.getModX() * distance, face.getModY() * distance, face.getModZ() * distance);
|
||||
}
|
||||
|
||||
public BlockFace getFace(final Block block) {
|
||||
BlockFace[] values = BlockFace.values();
|
||||
|
||||
for (BlockFace face : values) {
|
||||
if ((this.getX() + face.getModX() == block.getX()) &&
|
||||
(this.getY() + face.getModY() == block.getY()) &&
|
||||
(this.getZ() + face.getModZ() == block.getZ())
|
||||
) {
|
||||
return face;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftBlock{" + "chunk=" + chunk + ",x=" + x + ",y=" + y + ",z=" + z + ",type=" + getType() + ",data=" + getData() + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notch uses a 0-5 to mean DOWN, UP, NORTH, SOUTH, WEST, EAST
|
||||
* in that order all over. This method is convenience to convert for us.
|
||||
*
|
||||
* @return BlockFace the BlockFace represented by this number
|
||||
*/
|
||||
public static BlockFace notchToBlockFace(int notch) {
|
||||
switch (notch) {
|
||||
case 0:
|
||||
return BlockFace.DOWN;
|
||||
case 1:
|
||||
return BlockFace.UP;
|
||||
case 2:
|
||||
return BlockFace.NORTH;
|
||||
case 3:
|
||||
return BlockFace.SOUTH;
|
||||
case 4:
|
||||
return BlockFace.WEST;
|
||||
case 5:
|
||||
return BlockFace.EAST;
|
||||
default:
|
||||
return BlockFace.SELF;
|
||||
}
|
||||
}
|
||||
|
||||
public static int blockFaceToNotch(BlockFace face) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
return 0;
|
||||
case UP:
|
||||
return 1;
|
||||
case NORTH:
|
||||
return 2;
|
||||
case SOUTH:
|
||||
return 3;
|
||||
case WEST:
|
||||
return 4;
|
||||
case EAST:
|
||||
return 5;
|
||||
default:
|
||||
return 7; // Good as anything here, but technically invalid
|
||||
}
|
||||
}
|
||||
|
||||
public BlockState getState() {
|
||||
Material material = getType();
|
||||
// Cauldron start - if null, check for TE that implements IInventory
|
||||
if (material == null)
|
||||
{
|
||||
TileEntity te = ((CraftWorld)this.getWorld()).getHandle().getTileEntity(this.getX(), this.getY(), this.getZ());
|
||||
if (te != null && te instanceof IInventory)
|
||||
{
|
||||
// In order to allow plugins to properly grab the container location, we must pass a class that extends CraftBlockState and implements InventoryHolder.
|
||||
// Note: This will be returned when TileEntity.getOwner() is called
|
||||
return new CraftCustomContainer(this);
|
||||
}
|
||||
// pass default state
|
||||
return new CraftBlockState(this);
|
||||
}
|
||||
// Cauldron end
|
||||
switch (material) {
|
||||
case SIGN:
|
||||
case SIGN_POST:
|
||||
case WALL_SIGN:
|
||||
return new CraftSign(this);
|
||||
case CHEST:
|
||||
case TRAPPED_CHEST:
|
||||
return new CraftChest(this);
|
||||
case BURNING_FURNACE:
|
||||
case FURNACE:
|
||||
return new CraftFurnace(this);
|
||||
case DISPENSER:
|
||||
return new CraftDispenser(this);
|
||||
case DROPPER:
|
||||
return new CraftDropper(this);
|
||||
case HOPPER:
|
||||
return new CraftHopper(this);
|
||||
case MOB_SPAWNER:
|
||||
return new CraftCreatureSpawner(this);
|
||||
case NOTE_BLOCK:
|
||||
return new CraftNoteBlock(this);
|
||||
case JUKEBOX:
|
||||
return new CraftJukebox(this);
|
||||
case BREWING_STAND:
|
||||
return new CraftBrewingStand(this);
|
||||
case SKULL:
|
||||
return new CraftSkull(this);
|
||||
case COMMAND:
|
||||
return new CraftCommandBlock(this);
|
||||
case BEACON:
|
||||
return new CraftBeacon(this);
|
||||
default:
|
||||
// Cauldron start
|
||||
TileEntity te = ((CraftWorld)this.getWorld()).getHandle().getTileEntity(this.getX(), this.getY(), this.getZ());
|
||||
if (te != null && te instanceof IInventory)
|
||||
{
|
||||
// In order to allow plugins to properly grab the container location, we must pass a class that extends CraftBlockState and implements InventoryHolder.
|
||||
// Note: This will be returned when TileEntity.getOwner() is called
|
||||
return new CraftCustomContainer(this);
|
||||
}
|
||||
// pass default state
|
||||
// Cauldron end
|
||||
return new CraftBlockState(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Biome getBiome() {
|
||||
return getWorld().getBiome(x, z);
|
||||
}
|
||||
|
||||
public void setBiome(Biome bio) {
|
||||
getWorld().setBiome(x, z, bio);
|
||||
}
|
||||
|
||||
public static Biome biomeBaseToBiome(BiomeGenBase base) {
|
||||
if (base == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return BIOME_MAPPING[base.biomeID];
|
||||
}
|
||||
|
||||
public static BiomeGenBase biomeToBiomeBase(Biome bio) {
|
||||
if (bio == null) {
|
||||
return null;
|
||||
}
|
||||
return BIOMEBASE_MAPPING[bio.ordinal()];
|
||||
}
|
||||
|
||||
public double getTemperature() {
|
||||
return getWorld().getTemperature(x, z);
|
||||
}
|
||||
|
||||
public double getHumidity() {
|
||||
return getWorld().getHumidity(x, z);
|
||||
}
|
||||
|
||||
public boolean isBlockPowered() {
|
||||
return chunk.getHandle().worldObj.getBlockPowerInput(x, y, z) > 0;
|
||||
}
|
||||
|
||||
public boolean isBlockIndirectlyPowered() {
|
||||
return chunk.getHandle().worldObj.isBlockIndirectlyGettingPowered(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof CraftBlock)) return false;
|
||||
CraftBlock other = (CraftBlock) o;
|
||||
|
||||
return this.x == other.x && this.y == other.y && this.z == other.z && this.getWorld().equals(other.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.y << 24 ^ this.x ^ this.z ^ this.getWorld().hashCode();
|
||||
}
|
||||
|
||||
public boolean isBlockFacePowered(BlockFace face) {
|
||||
return chunk.getHandle().worldObj.getIndirectPowerOutput(x, y, z, blockFaceToNotch(face));
|
||||
}
|
||||
|
||||
public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
|
||||
int power = chunk.getHandle().worldObj.getIndirectPowerLevelTo(x, y, z, blockFaceToNotch(face));
|
||||
|
||||
Block relative = getRelative(face);
|
||||
if (relative.getType() == Material.REDSTONE_WIRE) {
|
||||
return Math.max(power, relative.getData()) > 0;
|
||||
}
|
||||
|
||||
return power > 0;
|
||||
}
|
||||
|
||||
public int getBlockPower(BlockFace face) {
|
||||
int power = 0;
|
||||
BlockRedstoneWire wire = Blocks.redstone_wire;
|
||||
net.minecraft.world.World world = chunk.getHandle().worldObj;
|
||||
if ((face == BlockFace.DOWN || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y - 1, z, 0)) power = wire.func_150178_a(world, x, y - 1, z, power);
|
||||
if ((face == BlockFace.UP || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y + 1, z, 1)) power = wire.func_150178_a(world, x, y + 1, z, power);
|
||||
if ((face == BlockFace.EAST || face == BlockFace.SELF) && world.getIndirectPowerOutput(x + 1, y, z, 2)) power = wire.func_150178_a(world, x + 1, y, z, power);
|
||||
if ((face == BlockFace.WEST || face == BlockFace.SELF) && world.getIndirectPowerOutput(x - 1, y, z, 3)) power = wire.func_150178_a(world, x - 1, y, z, power);
|
||||
if ((face == BlockFace.NORTH || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y, z - 1, 4)) power = wire.func_150178_a(world, x, y, z - 1, power);
|
||||
if ((face == BlockFace.SOUTH || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y, z + 1, 5)) power = wire.func_150178_a(world, x, y, z - 1, power);
|
||||
return power > 0 ? power : (face == BlockFace.SELF ? isBlockIndirectlyPowered() : isBlockFaceIndirectlyPowered(face)) ? 15 : 0;
|
||||
}
|
||||
|
||||
public int getBlockPower() {
|
||||
return getBlockPower(BlockFace.SELF);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
// Cauldron start - support custom air blocks (Railcraft player aura tracking block)
|
||||
//return getType() == Material.AIR;
|
||||
if (getType() == Material.AIR) return true;
|
||||
if (!(getWorld() instanceof CraftWorld)) return false;
|
||||
return ((CraftWorld) getWorld()).getHandle().isAirBlock(getX(), getY(), getZ());
|
||||
// Cauldron end
|
||||
}
|
||||
|
||||
public boolean isLiquid() {
|
||||
return (getType() == Material.WATER) || (getType() == Material.STATIONARY_WATER) || (getType() == Material.LAVA) || (getType() == Material.STATIONARY_LAVA);
|
||||
}
|
||||
|
||||
public PistonMoveReaction getPistonMoveReaction() {
|
||||
return PistonMoveReaction.getById(getNMSBlock().getMaterial().getMaterialMobility());
|
||||
}
|
||||
|
||||
private boolean itemCausesDrops(ItemStack item) {
|
||||
net.minecraft.block.Block block = this.getNMSBlock();
|
||||
net.minecraft.item.Item itemType = item != null ? net.minecraft.item.Item.getItemById(item.getTypeId()) : null;
|
||||
return block != null && (block.getMaterial().isToolNotRequired() || (itemType != null && itemType.func_150897_b(block)));
|
||||
}
|
||||
|
||||
public boolean breakNaturally() {
|
||||
// Order matters here, need to drop before setting to air so skulls can get their data
|
||||
net.minecraft.block.Block block = this.getNMSBlock();
|
||||
byte data = getData();
|
||||
boolean result = false;
|
||||
|
||||
if (block != null && block != Blocks.air) {
|
||||
block.dropBlockAsItemWithChance(chunk.getHandle().worldObj, x, y, z, data, 1.0F, 0);
|
||||
result = true;
|
||||
}
|
||||
|
||||
setTypeId(Material.AIR.getId());
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean breakNaturally(ItemStack item) {
|
||||
if (itemCausesDrops(item)) {
|
||||
return breakNaturally();
|
||||
} else {
|
||||
return setTypeId(Material.AIR.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<ItemStack> getDrops() {
|
||||
List<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
|
||||
net.minecraft.block.Block block = this.getNMSBlock();
|
||||
if (block != Blocks.air) {
|
||||
byte data = getData();
|
||||
// based on nms.Block.dropNaturally
|
||||
int count = block.quantityDroppedWithBonus(0, chunk.getHandle().worldObj.rand);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Item item = block.getItemDropped(data, chunk.getHandle().worldObj.rand, 0);
|
||||
if (item != null) {
|
||||
// Skulls are special, their data is based on the tile entity
|
||||
if (Blocks.skull == block) {
|
||||
net.minecraft.item.ItemStack nmsStack = new net.minecraft.item.ItemStack(item, 1, block.getDamageValue(chunk.getHandle().worldObj, x, y, z));
|
||||
TileEntitySkull tileentityskull = (TileEntitySkull) chunk.getHandle().worldObj.getTileEntity(x, y, z);
|
||||
|
||||
if (tileentityskull.func_145904_a() == 3 && tileentityskull.func_152108_a() != null) {
|
||||
nmsStack.setTagCompound(new NBTTagCompound());
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
|
||||
NBTUtil.func_152460_a(nbttagcompound, tileentityskull.func_152108_a());
|
||||
nmsStack.getTagCompound().setTag("SkullOwner", nbttagcompound);
|
||||
}
|
||||
|
||||
drops.add(CraftItemStack.asBukkitCopy(nmsStack));
|
||||
// We don't want to drop cocoa blocks, we want to drop cocoa beans.
|
||||
} else if (Blocks.cocoa == block) {
|
||||
int dropAmount = (BlockCocoa.func_149987_c(data) >= 2 ? 3 : 1);
|
||||
for (int j = 0; j < dropAmount; ++j) {
|
||||
drops.add(new ItemStack(Material.INK_SACK, 1, (short) 3));
|
||||
}
|
||||
} else {
|
||||
drops.add(new ItemStack(org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(item), 1, (short) block.damageDropped(data)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return drops;
|
||||
}
|
||||
|
||||
public Collection<ItemStack> getDrops(ItemStack item) {
|
||||
if (itemCausesDrops(item)) {
|
||||
return getDrops();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/* Build biome index based lookup table for BiomeBase to Biome mapping */
|
||||
public static void initMappings() { // Cauldron - initializer to initMappings() method; called in CraftServer
|
||||
//BIOME_MAPPING = new Biome[BiomeGenBase.biomeList.length]; // Cauldron - move up
|
||||
//BIOMEBASE_MAPPING = new BiomeGenBase[Biome.values().length]; // Cauldron - move up
|
||||
BIOME_MAPPING[BiomeGenBase.swampland.biomeID] = Biome.SWAMPLAND;
|
||||
BIOME_MAPPING[BiomeGenBase.forest.biomeID] = Biome.FOREST;
|
||||
BIOME_MAPPING[BiomeGenBase.taiga.biomeID] = Biome.TAIGA;
|
||||
BIOME_MAPPING[BiomeGenBase.desert.biomeID] = Biome.DESERT;
|
||||
BIOME_MAPPING[BiomeGenBase.plains.biomeID] = Biome.PLAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.hell.biomeID] = Biome.HELL;
|
||||
BIOME_MAPPING[BiomeGenBase.sky.biomeID] = Biome.SKY;
|
||||
BIOME_MAPPING[BiomeGenBase.river.biomeID] = Biome.RIVER;
|
||||
BIOME_MAPPING[BiomeGenBase.extremeHills.biomeID] = Biome.EXTREME_HILLS;
|
||||
BIOME_MAPPING[BiomeGenBase.ocean.biomeID] = Biome.OCEAN;
|
||||
BIOME_MAPPING[BiomeGenBase.frozenOcean.biomeID] = Biome.FROZEN_OCEAN;
|
||||
BIOME_MAPPING[BiomeGenBase.frozenRiver.biomeID] = Biome.FROZEN_RIVER;
|
||||
BIOME_MAPPING[BiomeGenBase.icePlains.biomeID] = Biome.ICE_PLAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.iceMountains.biomeID] = Biome.ICE_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.mushroomIsland.biomeID] = Biome.MUSHROOM_ISLAND;
|
||||
BIOME_MAPPING[BiomeGenBase.mushroomIslandShore.biomeID] = Biome.MUSHROOM_SHORE;
|
||||
BIOME_MAPPING[BiomeGenBase.beach.biomeID] = Biome.BEACH;
|
||||
BIOME_MAPPING[BiomeGenBase.desertHills.biomeID] = Biome.DESERT_HILLS;
|
||||
BIOME_MAPPING[BiomeGenBase.forestHills.biomeID] = Biome.FOREST_HILLS;
|
||||
BIOME_MAPPING[BiomeGenBase.taigaHills.biomeID] = Biome.TAIGA_HILLS;
|
||||
BIOME_MAPPING[BiomeGenBase.extremeHillsEdge.biomeID] = Biome.SMALL_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.jungle.biomeID] = Biome.JUNGLE;
|
||||
BIOME_MAPPING[BiomeGenBase.jungleHills.biomeID] = Biome.JUNGLE_HILLS;
|
||||
BIOME_MAPPING[BiomeGenBase.jungleEdge.biomeID] = Biome.JUNGLE_EDGE;
|
||||
BIOME_MAPPING[BiomeGenBase.deepOcean.biomeID] = Biome.DEEP_OCEAN;
|
||||
BIOME_MAPPING[BiomeGenBase.stoneBeach.biomeID] = Biome.STONE_BEACH;
|
||||
BIOME_MAPPING[BiomeGenBase.coldBeach.biomeID] = Biome.COLD_BEACH;
|
||||
BIOME_MAPPING[BiomeGenBase.birchForest.biomeID] = Biome.BIRCH_FOREST;
|
||||
BIOME_MAPPING[BiomeGenBase.birchForestHills.biomeID] = Biome.BIRCH_FOREST_HILLS;
|
||||
BIOME_MAPPING[BiomeGenBase.roofedForest.biomeID] = Biome.ROOFED_FOREST;
|
||||
BIOME_MAPPING[BiomeGenBase.coldTaiga.biomeID] = Biome.COLD_TAIGA;
|
||||
BIOME_MAPPING[BiomeGenBase.coldTaigaHills.biomeID] = Biome.COLD_TAIGA_HILLS;
|
||||
BIOME_MAPPING[BiomeGenBase.megaTaiga.biomeID] = Biome.MEGA_TAIGA;
|
||||
BIOME_MAPPING[BiomeGenBase.megaTaigaHills.biomeID] = Biome.MEGA_TAIGA_HILLS;
|
||||
BIOME_MAPPING[BiomeGenBase.extremeHillsPlus.biomeID] = Biome.EXTREME_HILLS_PLUS;
|
||||
BIOME_MAPPING[BiomeGenBase.savanna.biomeID] = Biome.SAVANNA;
|
||||
BIOME_MAPPING[BiomeGenBase.savannaPlateau.biomeID] = Biome.SAVANNA_PLATEAU;
|
||||
BIOME_MAPPING[BiomeGenBase.mesa.biomeID] = Biome.MESA;
|
||||
BIOME_MAPPING[BiomeGenBase.mesaPlateau_F.biomeID] = Biome.MESA_PLATEAU_FOREST;
|
||||
BIOME_MAPPING[BiomeGenBase.mesaPlateau.biomeID] = Biome.MESA_PLATEAU;
|
||||
|
||||
// Extended Biomes
|
||||
BIOME_MAPPING[BiomeGenBase.plains.biomeID + 128] = Biome.SUNFLOWER_PLAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.desert.biomeID + 128] = Biome.DESERT_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.forest.biomeID + 128] = Biome.FLOWER_FOREST;
|
||||
BIOME_MAPPING[BiomeGenBase.taiga.biomeID + 128] = Biome.TAIGA_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.swampland.biomeID + 128] = Biome.SWAMPLAND_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.icePlains.biomeID + 128] = Biome.ICE_PLAINS_SPIKES;
|
||||
BIOME_MAPPING[BiomeGenBase.jungle.biomeID + 128] = Biome.JUNGLE_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.jungleEdge.biomeID + 128] = Biome.JUNGLE_EDGE_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.coldTaiga.biomeID + 128] = Biome.COLD_TAIGA_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.savanna.biomeID + 128] = Biome.SAVANNA_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.savannaPlateau.biomeID + 128] = Biome.SAVANNA_PLATEAU_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.mesa.biomeID + 128] = Biome.MESA_BRYCE;
|
||||
BIOME_MAPPING[BiomeGenBase.mesaPlateau_F.biomeID + 128] = Biome.MESA_PLATEAU_FOREST_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.mesaPlateau.biomeID + 128] = Biome.MESA_PLATEAU_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.birchForest.biomeID + 128] = Biome.BIRCH_FOREST_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.birchForestHills.biomeID + 128] = Biome.BIRCH_FOREST_HILLS_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.roofedForest.biomeID + 128] = Biome.ROOFED_FOREST_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.megaTaiga.biomeID + 128] = Biome.MEGA_SPRUCE_TAIGA;
|
||||
BIOME_MAPPING[BiomeGenBase.extremeHills.biomeID + 128] = Biome.EXTREME_HILLS_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.extremeHillsPlus.biomeID + 128] = Biome.EXTREME_HILLS_PLUS_MOUNTAINS;
|
||||
BIOME_MAPPING[BiomeGenBase.megaTaigaHills.biomeID + 128] = Biome.MEGA_SPRUCE_TAIGA_HILLS;
|
||||
|
||||
/* Sanity check - we should have a record for each record in the BiomeBase.a table */
|
||||
/* Helps avoid missed biomes when we upgrade bukkit to new code with new biomes */
|
||||
for (int i = 0; i < BIOME_MAPPING.length; i++) {
|
||||
if ((BiomeGenBase.getBiome(i) != null) && (BIOME_MAPPING[i] == null)) {
|
||||
// Cauldron start - add support for mod biomes
|
||||
//throw new IllegalArgumentException("Missing Biome mapping for BiomeBase[" + i + "]");
|
||||
String name = BiomeGenBase.getBiome(i).biomeName;
|
||||
int id = BiomeGenBase.getBiome(i).biomeID;
|
||||
|
||||
System.out.println("Adding biome mapping " + BiomeGenBase.getBiome(i).biomeID + " " + name + " at BiomeBase[" + i + "]");
|
||||
net.minecraftforge.common.util.EnumHelper.addBukkitBiome(name); // Forge
|
||||
BIOME_MAPPING[BiomeGenBase.getBiome(i).biomeID] = ((Biome) Enum.valueOf(Biome.class, name));
|
||||
// Cauldron end
|
||||
}
|
||||
if (BIOME_MAPPING[i] != null) { /* Build reverse mapping for setBiome */
|
||||
BIOMEBASE_MAPPING[BIOME_MAPPING[i].ordinal()] = BiomeGenBase.getBiome(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cauldron start - if cauldron.dump-materials is true, dump all materials with their corresponding id's
|
||||
public static void dumpMaterials() {
|
||||
if (MinecraftServer.getServer().cauldronConfig.dumpMaterials.getValue())
|
||||
{
|
||||
FMLLog.info("Cauldron Dump Materials is ENABLED. Starting dump...");
|
||||
for (int i = 0; i < 32000; i++)
|
||||
{
|
||||
Material material = Material.getMaterial(i);
|
||||
if (material != null)
|
||||
{
|
||||
FMLLog.info("Found material " + material + " with ID " + i);
|
||||
}
|
||||
}
|
||||
FMLLog.info("Cauldron Dump Materials complete.");
|
||||
FMLLog.info("To disable these dumps, set cauldron.dump-materials to false in bukkit.yml.");
|
||||
}
|
||||
}
|
||||
// Cauldron end
|
||||
|
||||
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
|
||||
chunk.getCraftWorld().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue);
|
||||
}
|
||||
|
||||
public List<MetadataValue> getMetadata(String metadataKey) {
|
||||
return chunk.getCraftWorld().getBlockMetadata().getMetadata(this, metadataKey);
|
||||
}
|
||||
|
||||
public boolean hasMetadata(String metadataKey) {
|
||||
return chunk.getCraftWorld().getBlockMetadata().hasMetadata(this, metadataKey);
|
||||
}
|
||||
|
||||
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
|
||||
chunk.getCraftWorld().getBlockMetadata().removeMetadata(this, metadataKey, owningPlugin);
|
||||
}
|
||||
}
|
284
src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
Normal file
284
src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
Normal file
@ -0,0 +1,284 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.CraftChunk;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
// Cauldron start
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
// Cauldron end
|
||||
|
||||
public class CraftBlockState implements BlockState {
|
||||
private final CraftWorld world;
|
||||
private final CraftChunk chunk;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final NBTTagCompound nbt; // Cauldron
|
||||
protected int type;
|
||||
protected MaterialData data;
|
||||
protected int flag;
|
||||
protected final byte light;
|
||||
|
||||
public CraftBlockState(final Block block) {
|
||||
this.world = (CraftWorld) block.getWorld();
|
||||
this.x = block.getX();
|
||||
this.y = block.getY();
|
||||
this.z = block.getZ();
|
||||
this.type = block.getTypeId();
|
||||
this.light = block.getLightLevel();
|
||||
this.chunk = (CraftChunk) block.getChunk();
|
||||
this.flag = 3;
|
||||
// Cauldron start - save TE data
|
||||
TileEntity te = world.getHandle().getTileEntity(x, y, z);
|
||||
if (te != null)
|
||||
{
|
||||
nbt = new NBTTagCompound();
|
||||
te.writeToNBT(nbt);
|
||||
}
|
||||
else nbt = null;
|
||||
// Cauldron end
|
||||
|
||||
createData(block.getData());
|
||||
}
|
||||
|
||||
public CraftBlockState(final Block block, int flag) {
|
||||
this(block);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static CraftBlockState getBlockState(net.minecraft.world.World world, int x, int y, int z) {
|
||||
return new CraftBlockState(world.getWorld().getBlockAt(x, y, z));
|
||||
}
|
||||
|
||||
public static CraftBlockState getBlockState(net.minecraft.world.World world, int x, int y, int z, int flag) {
|
||||
return new CraftBlockState(world.getWorld().getBlockAt(x, y, z), flag);
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public void setData(final MaterialData data) {
|
||||
Material mat = getType();
|
||||
|
||||
if ((mat == null) || (mat.getData() == null)) {
|
||||
this.data = data;
|
||||
} else {
|
||||
if ((data.getClass() == mat.getData()) || (data.getClass() == MaterialData.class)) {
|
||||
this.data = data;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Provided data is not of type "
|
||||
+ mat.getData().getName() + ", found " + data.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MaterialData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setType(final Material type) {
|
||||
setTypeId(type.getId());
|
||||
}
|
||||
|
||||
public boolean setTypeId(final int type) {
|
||||
if (this.type != type) {
|
||||
this.type = type;
|
||||
|
||||
createData((byte) 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Material getType() {
|
||||
return Material.getMaterial(getTypeId());
|
||||
}
|
||||
|
||||
public void setFlag(int flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public int getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public byte getLightLevel() {
|
||||
return light;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return world.getBlockAt(x, y, z);
|
||||
}
|
||||
|
||||
public boolean update() {
|
||||
return update(false);
|
||||
}
|
||||
|
||||
public boolean update(boolean force) {
|
||||
return update(force, true);
|
||||
}
|
||||
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
Block block = getBlock();
|
||||
|
||||
if (block.getType() != getType()) {
|
||||
if (force) {
|
||||
block.setTypeId(getTypeId(), applyPhysics);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
block.setData(getRawData(), applyPhysics);
|
||||
world.getHandle().markBlockForUpdate(x, y, z);
|
||||
// Cauldron start - restore TE data from snapshot
|
||||
if (nbt != null)
|
||||
{
|
||||
TileEntity te = world.getHandle().getTileEntity(x, y, z);
|
||||
if (te != null)
|
||||
{
|
||||
te.readFromNBT(nbt);
|
||||
}
|
||||
}
|
||||
// Cauldron end
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void createData(final byte data) {
|
||||
Material mat = getType();
|
||||
if (mat == null || mat.getData() == null) {
|
||||
this.data = new MaterialData(type, data);
|
||||
} else {
|
||||
this.data = mat.getNewData(data);
|
||||
}
|
||||
}
|
||||
|
||||
public byte getRawData() {
|
||||
return data.getData();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
public Location getLocation(Location loc) {
|
||||
if (loc != null) {
|
||||
loc.setWorld(world);
|
||||
loc.setX(x);
|
||||
loc.setY(y);
|
||||
loc.setZ(z);
|
||||
loc.setYaw(0);
|
||||
loc.setPitch(0);
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
public void setRawData(byte data) {
|
||||
this.data.setData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CraftBlockState other = (CraftBlockState) obj;
|
||||
if (this.world != other.world && (this.world == null || !this.world.equals(other.world))) {
|
||||
return false;
|
||||
}
|
||||
if (this.x != other.x) {
|
||||
return false;
|
||||
}
|
||||
if (this.y != other.y) {
|
||||
return false;
|
||||
}
|
||||
if (this.z != other.z) {
|
||||
return false;
|
||||
}
|
||||
if (this.type != other.type) {
|
||||
return false;
|
||||
}
|
||||
if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
|
||||
return false;
|
||||
}
|
||||
// Cauldron start
|
||||
if (this.nbt != other.nbt && (this.nbt == null || !this.nbt.equals(other.nbt))) {
|
||||
return false;
|
||||
}
|
||||
// Cauldron end
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 73 * hash + (this.world != null ? this.world.hashCode() : 0);
|
||||
hash = 73 * hash + this.x;
|
||||
hash = 73 * hash + this.y;
|
||||
hash = 73 * hash + this.z;
|
||||
hash = 73 * hash + this.type;
|
||||
hash = 73 * hash + (this.data != null ? this.data.hashCode() : 0);
|
||||
hash = 73 * hash + (this.nbt != null ? this.nbt.hashCode() : 0); // Cauldron
|
||||
return hash;
|
||||
}
|
||||
|
||||
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
|
||||
chunk.getCraftWorld().getBlockMetadata().setMetadata(getBlock(), metadataKey, newMetadataValue);
|
||||
}
|
||||
|
||||
public List<MetadataValue> getMetadata(String metadataKey) {
|
||||
return chunk.getCraftWorld().getBlockMetadata().getMetadata(getBlock(), metadataKey);
|
||||
}
|
||||
|
||||
public boolean hasMetadata(String metadataKey) {
|
||||
return chunk.getCraftWorld().getBlockMetadata().hasMetadata(getBlock(), metadataKey);
|
||||
}
|
||||
|
||||
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
|
||||
chunk.getCraftWorld().getBlockMetadata().removeMetadata(getBlock(), metadataKey, owningPlugin);
|
||||
}
|
||||
|
||||
// Cauldron start
|
||||
public TileEntity getTileEntity() {
|
||||
if (nbt != null)
|
||||
return TileEntity.createAndLoadEntity(nbt);
|
||||
else return null;
|
||||
}
|
||||
// Cauldron end
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityBrewingStand;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BrewingStand;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryBrewer;
|
||||
import org.bukkit.inventory.BrewerInventory;
|
||||
|
||||
public class CraftBrewingStand extends CraftBlockState implements BrewingStand {
|
||||
private final TileEntityBrewingStand brewingStand;
|
||||
|
||||
public CraftBrewingStand(Block block) {
|
||||
super(block);
|
||||
|
||||
brewingStand = (TileEntityBrewingStand) ((CraftWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public BrewerInventory getInventory() {
|
||||
return new CraftInventoryBrewer(brewingStand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
brewingStand.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getBrewingTime() {
|
||||
return brewingStand.brewTime;
|
||||
}
|
||||
|
||||
public void setBrewingTime(int brewTime) {
|
||||
brewingStand.brewTime = brewTime;
|
||||
}
|
||||
}
|
72
src/main/java/org/bukkit/craftbukkit/block/CraftChest.java
Normal file
72
src/main/java/org/bukkit/craftbukkit/block/CraftChest.java
Normal file
@ -0,0 +1,72 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
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 getBlockInventory() {
|
||||
return new CraftInventory(chest);
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
int x = getX();
|
||||
int y = getY();
|
||||
int z = getZ();
|
||||
// The logic here is basically identical to the logic in BlockChest.interact
|
||||
CraftInventory inventory = new CraftInventory(chest);
|
||||
int id;
|
||||
if (world.getBlockTypeIdAt(x, y, z) == Material.CHEST.getId()) {
|
||||
id = Material.CHEST.getId();
|
||||
} else if (world.getBlockTypeIdAt(x, y, z) == Material.TRAPPED_CHEST.getId()) {
|
||||
id = Material.TRAPPED_CHEST.getId();
|
||||
} else {
|
||||
throw new IllegalStateException("CraftChest is not a chest but is instead " + world.getBlockAt(x, y, z));
|
||||
}
|
||||
|
||||
if (world.getBlockTypeIdAt(x - 1, y, z) == id) {
|
||||
CraftInventory left = new CraftInventory((TileEntityChest)world.getHandle().getTileEntity(x - 1, y, z));
|
||||
inventory = new CraftInventoryDoubleChest(left, inventory);
|
||||
}
|
||||
if (world.getBlockTypeIdAt(x + 1, y, z) == id) {
|
||||
CraftInventory right = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(x + 1, y, z));
|
||||
inventory = new CraftInventoryDoubleChest(inventory, right);
|
||||
}
|
||||
if (world.getBlockTypeIdAt(x, y, z - 1) == id) {
|
||||
CraftInventory left = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(x, y, z - 1));
|
||||
inventory = new CraftInventoryDoubleChest(left, inventory);
|
||||
}
|
||||
if (world.getBlockTypeIdAt(x, y, z + 1) == id) {
|
||||
CraftInventory right = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(x, y, z + 1));
|
||||
inventory = new CraftInventoryDoubleChest(inventory, right);
|
||||
}
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
chest.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityCommandBlock;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CommandBlock;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
||||
public class CraftCommandBlock extends CraftBlockState implements CommandBlock {
|
||||
private final TileEntityCommandBlock commandBlock;
|
||||
private String command;
|
||||
private String name;
|
||||
|
||||
public CraftCommandBlock(Block block) {
|
||||
super(block);
|
||||
|
||||
CraftWorld world = (CraftWorld) block.getWorld();
|
||||
commandBlock = (TileEntityCommandBlock) world.getTileEntityAt(getX(), getY(), getZ());
|
||||
command = commandBlock.func_145993_a().field_145763_e;
|
||||
name = commandBlock.func_145993_a().getCommandSenderName();
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command != null ? command : "";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name != null ? name : "@";
|
||||
}
|
||||
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
commandBlock.func_145993_a().func_145752_a(command);
|
||||
commandBlock.func_145993_a().func_145754_b(name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityMobSpawner;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class CraftCreatureSpawner extends CraftBlockState implements CreatureSpawner {
|
||||
private final TileEntityMobSpawner spawner;
|
||||
|
||||
public CraftCreatureSpawner(final Block block) {
|
||||
super(block);
|
||||
|
||||
spawner = (TileEntityMobSpawner) ((CraftWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CreatureType getCreatureType() {
|
||||
return CreatureType.fromName(spawner.func_145881_a().getEntityNameToSpawn());
|
||||
}
|
||||
|
||||
public EntityType getSpawnedType() {
|
||||
return EntityType.fromName(spawner.func_145881_a().getEntityNameToSpawn());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setCreatureType(CreatureType creatureType) {
|
||||
spawner.func_145881_a().setEntityName(creatureType.getName());
|
||||
}
|
||||
|
||||
public void setSpawnedType(EntityType entityType) {
|
||||
if (entityType == null || entityType.getName() == null) {
|
||||
throw new IllegalArgumentException("Can't spawn EntityType " + entityType + " from mobspawners!");
|
||||
}
|
||||
|
||||
spawner.func_145881_a().setEntityName(entityType.getName());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getCreatureTypeId() {
|
||||
return spawner.func_145881_a().getEntityNameToSpawn();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setCreatureTypeId(String creatureName) {
|
||||
setCreatureTypeByName(creatureName);
|
||||
}
|
||||
|
||||
public String getCreatureTypeName() {
|
||||
return spawner.func_145881_a().getEntityNameToSpawn();
|
||||
}
|
||||
|
||||
public void setCreatureTypeByName(String creatureType) {
|
||||
// Verify input
|
||||
EntityType type = EntityType.fromName(creatureType);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
setSpawnedType(type);
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
return spawner.func_145881_a().spawnDelay;
|
||||
}
|
||||
|
||||
public void setDelay(int delay) {
|
||||
spawner.func_145881_a().spawnDelay = delay;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntityDispenser;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public BlockProjectileSource getBlockProjectileSource() {
|
||||
Block block = getBlock();
|
||||
|
||||
if (block.getType() != Material.DISPENSER) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CraftBlockProjectileSource(dispenser);
|
||||
}
|
||||
|
||||
public boolean dispense() {
|
||||
Block block = getBlock();
|
||||
|
||||
if (block.getType() == Material.DISPENSER) {
|
||||
BlockDispenser dispense = (BlockDispenser) Blocks.dispenser;
|
||||
|
||||
dispense.func_149941_e(world.getHandle(), getX(), getY(), getZ());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
dispenser.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
49
src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java
Normal file
49
src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java
Normal file
@ -0,0 +1,49 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.block.BlockDropper;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntityDropper;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Dropper;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class CraftDropper extends CraftBlockState implements Dropper {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityDropper dropper;
|
||||
|
||||
public CraftDropper(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld) block.getWorld();
|
||||
dropper = (TileEntityDropper) world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventory(dropper);
|
||||
}
|
||||
|
||||
public void drop() {
|
||||
Block block = getBlock();
|
||||
|
||||
if (block.getType() == Material.DROPPER) {
|
||||
BlockDropper drop = (BlockDropper) Blocks.dropper;
|
||||
|
||||
drop.func_149941_e(world.getHandle(), getX(), getY(), getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
dropper.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
49
src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
Normal file
49
src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
Normal file
@ -0,0 +1,49 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryFurnace;
|
||||
import org.bukkit.inventory.FurnaceInventory;
|
||||
|
||||
public class CraftFurnace extends CraftBlockState implements Furnace {
|
||||
private final TileEntityFurnace furnace;
|
||||
|
||||
public CraftFurnace(final Block block) {
|
||||
super(block);
|
||||
|
||||
furnace = (TileEntityFurnace) ((CraftWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public FurnaceInventory getInventory() {
|
||||
return new CraftInventoryFurnace(furnace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
furnace.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public short getBurnTime() {
|
||||
return (short) furnace.furnaceBurnTime;
|
||||
}
|
||||
|
||||
public void setBurnTime(short burnTime) {
|
||||
furnace.furnaceBurnTime = burnTime;
|
||||
}
|
||||
|
||||
public short getCookTime() {
|
||||
return (short) furnace.furnaceCookTime;
|
||||
}
|
||||
|
||||
public void setCookTime(short cookTime) {
|
||||
furnace.furnaceCookTime = cookTime;
|
||||
}
|
||||
}
|
33
src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java
Normal file
33
src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java
Normal file
@ -0,0 +1,33 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityHopper;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class CraftHopper extends CraftBlockState implements Hopper {
|
||||
private final TileEntityHopper hopper;
|
||||
|
||||
public CraftHopper(final Block block) {
|
||||
super(block);
|
||||
|
||||
hopper = (TileEntityHopper) ((CraftWorld) block.getWorld()).getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventory(hopper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
hopper.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
60
src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java
Normal file
60
src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java
Normal file
@ -0,0 +1,60 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.block.BlockJukebox;
|
||||
import net.minecraft.block.BlockJukebox.TileEntityJukebox;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Jukebox;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
|
||||
public class CraftJukebox extends CraftBlockState implements Jukebox {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityJukebox jukebox;
|
||||
|
||||
public CraftJukebox(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld) block.getWorld();
|
||||
jukebox = (TileEntityJukebox) world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getPlaying() {
|
||||
ItemStack record = jukebox.func_145856_a();
|
||||
if (record == null) {
|
||||
return Material.AIR;
|
||||
}
|
||||
return CraftMagicNumbers.getMaterial(record.getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlaying(Material record) {
|
||||
if (record == null || CraftMagicNumbers.getItem(record) == null) {
|
||||
record = Material.AIR;
|
||||
jukebox.func_145857_a(null);
|
||||
} else {
|
||||
jukebox.func_145857_a(new ItemStack(CraftMagicNumbers.getItem(record), 1));
|
||||
}
|
||||
jukebox.markDirty();
|
||||
if (record == Material.AIR) {
|
||||
world.getHandle().setBlockMetadataWithNotify(getX(), getY(), getZ(), 0, 3);
|
||||
} else {
|
||||
world.getHandle().setBlockMetadataWithNotify(getX(), getY(), getZ(), 1, 3);
|
||||
}
|
||||
world.playEffect(getLocation(), Effect.RECORD_PLAY, record.getId());
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
return getRawData() == 1;
|
||||
}
|
||||
|
||||
public boolean eject() {
|
||||
boolean result = isPlaying();
|
||||
((BlockJukebox) Blocks.jukebox).func_149925_e(world.getHandle(), getX(), getY(), getZ());
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityNote;
|
||||
|
||||
import org.bukkit.Instrument;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.NoteBlock;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
|
||||
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 Note getNote() {
|
||||
return new Note(note.note);
|
||||
}
|
||||
|
||||
public byte getRawNote() {
|
||||
return note.note;
|
||||
}
|
||||
|
||||
public void setNote(Note n) {
|
||||
note.note = n.getId();
|
||||
}
|
||||
|
||||
public void setRawNote(byte n) {
|
||||
note.note = n;
|
||||
}
|
||||
|
||||
public boolean play() {
|
||||
Block block = getBlock();
|
||||
|
||||
if (block.getType() == Material.NOTE_BLOCK) {
|
||||
note.triggerNote(world.getHandle(), getX(), getY(), getZ());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean play(byte instrument, byte note) {
|
||||
Block block = getBlock();
|
||||
|
||||
if (block.getType() == Material.NOTE_BLOCK) {
|
||||
world.getHandle().addBlockEvent(getX(), getY(), getZ(), CraftMagicNumbers.getBlock(block), instrument, note);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean play(Instrument instrument, Note note) {
|
||||
Block block = getBlock();
|
||||
|
||||
if (block.getType() == Material.NOTE_BLOCK) {
|
||||
world.getHandle().addBlockEvent(getX(), getY(), getZ(), CraftMagicNumbers.getBlock(block), instrument.getType(), note.getId());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
64
src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
Normal file
64
src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
Normal file
@ -0,0 +1,64 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.tileentity.TileEntitySign;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
||||
public class CraftSign extends CraftBlockState implements Sign {
|
||||
private final TileEntitySign sign;
|
||||
private final String[] lines;
|
||||
|
||||
public CraftSign(final Block block) {
|
||||
super(block);
|
||||
|
||||
CraftWorld world = (CraftWorld) block.getWorld();
|
||||
sign = (net.minecraft.tileentity.TileEntitySign) world.getTileEntityAt(getX(), getY(), getZ());
|
||||
// Spigot start
|
||||
if (sign == null) {
|
||||
lines = new String[]{"", "", "", ""};
|
||||
return;
|
||||
}
|
||||
// Spigot end
|
||||
lines = new String[sign.signText.length];
|
||||
System.arraycopy(sign.signText, 0, lines, 0, lines.length);
|
||||
}
|
||||
|
||||
public String[] getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public String getLine(int index) throws IndexOutOfBoundsException {
|
||||
return lines[index];
|
||||
}
|
||||
|
||||
public void setLine(int index, String line) throws IndexOutOfBoundsException {
|
||||
lines[index] = line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
sign.signText = sanitizeLines(lines);
|
||||
sign.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String[] sanitizeLines(String[] lines) {
|
||||
String[] astring = new String[4];
|
||||
|
||||
for(int i = 0; i < 4; i++) {
|
||||
if (i < lines.length && lines[i] != null) {
|
||||
astring[i] = lines[i];
|
||||
} else {
|
||||
astring[i] = "";
|
||||
}
|
||||
}
|
||||
|
||||
return TileEntitySign.sanitizeLines(astring);
|
||||
}
|
||||
}
|
205
src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java
Normal file
205
src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java
Normal file
@ -0,0 +1,205 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntitySkull;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.SkullType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
||||
public class CraftSkull extends CraftBlockState implements Skull {
|
||||
private static final int MAX_OWNER_LENGTH = 16;
|
||||
private final TileEntitySkull skull;
|
||||
private GameProfile profile;
|
||||
private SkullType skullType;
|
||||
private byte rotation;
|
||||
|
||||
public CraftSkull(final Block block) {
|
||||
super(block);
|
||||
|
||||
CraftWorld world = (CraftWorld) block.getWorld();
|
||||
skull = (TileEntitySkull) world.getTileEntityAt(getX(), getY(), getZ());
|
||||
profile = skull.func_152108_a();
|
||||
skullType = getSkullType(skull.func_145904_a());
|
||||
rotation = (byte) skull.getRotation();
|
||||
}
|
||||
|
||||
static SkullType getSkullType(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return SkullType.SKELETON;
|
||||
case 1:
|
||||
return SkullType.WITHER;
|
||||
case 2:
|
||||
return SkullType.ZOMBIE;
|
||||
case 3:
|
||||
return SkullType.PLAYER;
|
||||
case 4:
|
||||
return SkullType.CREEPER;
|
||||
default:
|
||||
throw new AssertionError(id);
|
||||
}
|
||||
}
|
||||
|
||||
static int getSkullType(SkullType type) {
|
||||
switch(type) {
|
||||
case SKELETON:
|
||||
return 0;
|
||||
case WITHER:
|
||||
return 1;
|
||||
case ZOMBIE:
|
||||
return 2;
|
||||
case PLAYER:
|
||||
return 3;
|
||||
case CREEPER:
|
||||
return 4;
|
||||
default:
|
||||
throw new AssertionError(type);
|
||||
}
|
||||
}
|
||||
|
||||
static byte getBlockFace(BlockFace rotation) {
|
||||
switch (rotation) {
|
||||
case NORTH:
|
||||
return 0;
|
||||
case NORTH_NORTH_EAST:
|
||||
return 1;
|
||||
case NORTH_EAST:
|
||||
return 2;
|
||||
case EAST_NORTH_EAST:
|
||||
return 3;
|
||||
case EAST:
|
||||
return 4;
|
||||
case EAST_SOUTH_EAST:
|
||||
return 5;
|
||||
case SOUTH_EAST:
|
||||
return 6;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return 7;
|
||||
case SOUTH:
|
||||
return 8;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return 9;
|
||||
case SOUTH_WEST:
|
||||
return 10;
|
||||
case WEST_SOUTH_WEST:
|
||||
return 11;
|
||||
case WEST:
|
||||
return 12;
|
||||
case WEST_NORTH_WEST:
|
||||
return 13;
|
||||
case NORTH_WEST:
|
||||
return 14;
|
||||
case NORTH_NORTH_WEST:
|
||||
return 15;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid BlockFace rotation: " + rotation);
|
||||
}
|
||||
}
|
||||
|
||||
static BlockFace getBlockFace(byte rotation) {
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
return BlockFace.NORTH;
|
||||
case 1:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
case 2:
|
||||
return BlockFace.NORTH_EAST;
|
||||
case 3:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
case 4:
|
||||
return BlockFace.EAST;
|
||||
case 5:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
case 6:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
case 7:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
case 8:
|
||||
return BlockFace.SOUTH;
|
||||
case 9:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 10:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
case 11:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
case 12:
|
||||
return BlockFace.WEST;
|
||||
case 13:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
case 14:
|
||||
return BlockFace.NORTH_WEST;
|
||||
case 15:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
default:
|
||||
throw new AssertionError(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasOwner() {
|
||||
return profile != null;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return hasOwner() ? profile.getName() : null;
|
||||
}
|
||||
|
||||
public boolean setOwner(String name) {
|
||||
if (name == null || name.length() > MAX_OWNER_LENGTH) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a (name);
|
||||
if (profile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (skullType != SkullType.PLAYER) {
|
||||
skullType = SkullType.PLAYER;
|
||||
}
|
||||
|
||||
this.profile = profile;
|
||||
return true;
|
||||
}
|
||||
|
||||
public BlockFace getRotation() {
|
||||
return getBlockFace(rotation);
|
||||
}
|
||||
|
||||
public void setRotation(BlockFace rotation) {
|
||||
this.rotation = getBlockFace(rotation);
|
||||
}
|
||||
|
||||
public SkullType getSkullType() {
|
||||
return skullType;
|
||||
}
|
||||
|
||||
public void setSkullType(SkullType skullType) {
|
||||
this.skullType = skullType;
|
||||
|
||||
if (skullType != SkullType.PLAYER) {
|
||||
profile = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force, boolean applyPhysics) {
|
||||
boolean result = super.update(force, applyPhysics);
|
||||
|
||||
if (result) {
|
||||
if (skullType == SkullType.PLAYER) {
|
||||
skull.func_152106_a(profile);
|
||||
} else {
|
||||
skull.func_152107_a(getSkullType(skullType));
|
||||
}
|
||||
|
||||
skull.func_145903_a(rotation);
|
||||
skull.markDirty();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user