Update CraftBukkit to Minecraft 1.7.2

By: mbax <matt@phozop.net>
This commit is contained in:
CraftBukkit/Spigot
2013-11-04 07:07:38 -06:00
parent 5961c3b788
commit 5783df9d13
63 changed files with 1137 additions and 429 deletions

View File

@@ -7,8 +7,9 @@ import java.util.List;
import net.minecraft.server.BiomeBase;
import net.minecraft.server.BlockRedstoneWire;
import net.minecraft.server.Direction;
import net.minecraft.server.Blocks;
import net.minecraft.server.EnumSkyBlock;
import net.minecraft.server.Item;
import net.minecraft.server.NBTTagCompound;
import net.minecraft.server.TileEntitySkull;
@@ -23,6 +24,7 @@ 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;
@@ -43,6 +45,14 @@ public class CraftBlock implements Block {
this.chunk = chunk;
}
private net.minecraft.server.Block getNMSBlock() {
return CraftMagicNumbers.getBlock(this); // TODO: UPDATE THIS
}
private static net.minecraft.server.Block getNMSBlock(int type) {
return CraftMagicNumbers.getBlock(type);
}
public World getWorld() {
return chunk.getWorld();
}
@@ -105,22 +115,18 @@ public class CraftBlock implements Block {
}
public boolean setTypeId(final int type) {
return chunk.getHandle().world.setTypeIdAndData(x, y, z, type, getData(), 3);
return setTypeId(type, true);
}
public boolean setTypeId(final int type, final boolean applyPhysics) {
if (applyPhysics) {
return setTypeId(type);
} else {
return chunk.getHandle().world.setTypeIdAndData(x, y, z, type, getData(), 2);
}
return setTypeIdAndData(type, getData(), applyPhysics);
}
public boolean setTypeIdAndData(final int type, final byte data, final boolean applyPhysics) {
if (applyPhysics) {
return chunk.getHandle().world.setTypeIdAndData(x, y, z, type, data, 3);
return chunk.getHandle().world.setTypeAndData(x, y, z, getNMSBlock(type), data, 3);
} else {
boolean success = chunk.getHandle().world.setTypeIdAndData(x, y, z, type, data, 2);
boolean success = chunk.getHandle().world.setTypeAndData(x, y, z, getNMSBlock(type), data, 2);
if (success) {
chunk.getHandle().world.notify(x, y, z);
}
@@ -132,8 +138,10 @@ public class CraftBlock implements Block {
return Material.getMaterial(getTypeId());
}
@Deprecated
@Override
public int getTypeId() {
return chunk.getHandle().getTypeId(this.x & 0xF, this.y & 0xFF, this.z & 0xF);
return CraftMagicNumbers.getId(chunk.getHandle().getType(this.x & 0xF, this.y & 0xFF, this.z & 0xF));
}
public byte getLightLevel() {
@@ -342,7 +350,7 @@ public class CraftBlock implements Block {
public int getBlockPower(BlockFace face) {
int power = 0;
BlockRedstoneWire wire = net.minecraft.server.Block.REDSTONE_WIRE;
BlockRedstoneWire wire = Blocks.REDSTONE_WIRE;
net.minecraft.server.World world = chunk.getHandle().world;
if ((face == BlockFace.DOWN || face == BlockFace.SELF) && world.isBlockFacePowered(x, y - 1, z, 0)) power = wire.getPower(world, x, y - 1, z, power);
if ((face == BlockFace.UP || face == BlockFace.SELF) && world.isBlockFacePowered(x, y + 1, z, 1)) power = wire.getPower(world, x, y + 1, z, power);
@@ -366,22 +374,22 @@ public class CraftBlock implements Block {
}
public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.getById(net.minecraft.server.Block.byId[this.getTypeId()].material.getPushReaction());
return PistonMoveReaction.getById(getNMSBlock().getMaterial().getPushReaction());
}
private boolean itemCausesDrops(ItemStack item) {
net.minecraft.server.Block block = net.minecraft.server.Block.byId[this.getTypeId()];
net.minecraft.server.Item itemType = item != null ? net.minecraft.server.Item.byId[item.getTypeId()] : null;
return block != null && (block.material.isAlwaysDestroyable() || (itemType != null && itemType.canDestroySpecialBlock(block)));
net.minecraft.server.Block block = this.getNMSBlock();
net.minecraft.server.Item itemType = item != null ? net.minecraft.server.Item.d(item.getTypeId()) : null;
return block != null && (block.getMaterial().isAlwaysDestroyable() || (itemType != null && itemType.canDestroySpecialBlock(block)));
}
public boolean breakNaturally() {
// Order matters here, need to drop before setting to air so skulls can get their data
net.minecraft.server.Block block = net.minecraft.server.Block.byId[this.getTypeId()];
net.minecraft.server.Block block = this.getNMSBlock();
byte data = getData();
boolean result = false;
if (block != null) {
if (block != null && block != Blocks.AIR) {
block.dropNaturally(chunk.getHandle().world, x, y, z, data, 1.0F, 0);
result = true;
}
@@ -401,16 +409,16 @@ public class CraftBlock implements Block {
public Collection<ItemStack> getDrops() {
List<ItemStack> drops = new ArrayList<ItemStack>();
net.minecraft.server.Block block = net.minecraft.server.Block.byId[this.getTypeId()];
if (block != null) {
net.minecraft.server.Block block = this.getNMSBlock();
if (block != Blocks.AIR) {
byte data = getData();
// based on nms.Block.dropNaturally
int count = block.getDropCount(0, chunk.getHandle().world.random);
for (int i = 0; i < count; ++i) {
int item = block.getDropType(data, chunk.getHandle().world.random, 0);
if (item > 0) {
Item item = block.getDropType(data, chunk.getHandle().world.random, 0);
if (item != null) {
// Skulls are special, their data is based on the tile entity
if (net.minecraft.server.Block.SKULL.id == this.getTypeId()) {
if (Blocks.SKULL == block) {
net.minecraft.server.ItemStack nmsStack = new net.minecraft.server.ItemStack(item, 1, block.getDropData(chunk.getHandle().world, x, y, z));
TileEntitySkull tileentityskull = (TileEntitySkull) chunk.getHandle().world.getTileEntity(x, y, z);
@@ -421,7 +429,7 @@ public class CraftBlock implements Block {
drops.add(CraftItemStack.asBukkitCopy(nmsStack));
} else {
drops.add(new ItemStack(item, 1, (short) block.getDropData(data)));
drops.add(new ItemStack(org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(item), 1, (short) block.getDropData(data)));
}
}
}
@@ -439,18 +447,18 @@ public class CraftBlock implements Block {
/* Build biome index based lookup table for BiomeBase to Biome mapping */
static {
BIOME_MAPPING = new Biome[BiomeBase.biomes.length];
BIOME_MAPPING = new Biome[BiomeBase.n().length];
BIOMEBASE_MAPPING = new BiomeBase[Biome.values().length];
BIOME_MAPPING[BiomeBase.SWAMPLAND.id] = Biome.SWAMPLAND;
BIOME_MAPPING[BiomeBase.OCEAN.id] = Biome.OCEAN;
BIOME_MAPPING[BiomeBase.PLAINS.id] = Biome.PLAINS;
BIOME_MAPPING[BiomeBase.DESERT.id] = Biome.DESERT;
BIOME_MAPPING[BiomeBase.EXTREME_HILLS.id] = Biome.EXTREME_HILLS;
BIOME_MAPPING[BiomeBase.FOREST.id] = Biome.FOREST;
BIOME_MAPPING[BiomeBase.TAIGA.id] = Biome.TAIGA;
BIOME_MAPPING[BiomeBase.DESERT.id] = Biome.DESERT;
BIOME_MAPPING[BiomeBase.PLAINS.id] = Biome.PLAINS;
BIOME_MAPPING[BiomeBase.SWAMPLAND.id] = Biome.SWAMPLAND;
BIOME_MAPPING[BiomeBase.RIVER.id] = Biome.RIVER;
BIOME_MAPPING[BiomeBase.HELL.id] = Biome.HELL;
BIOME_MAPPING[BiomeBase.SKY.id] = Biome.SKY;
BIOME_MAPPING[BiomeBase.RIVER.id] = Biome.RIVER;
BIOME_MAPPING[BiomeBase.EXTREME_HILLS.id] = Biome.EXTREME_HILLS;
BIOME_MAPPING[BiomeBase.OCEAN.id] = Biome.OCEAN;
BIOME_MAPPING[BiomeBase.FROZEN_OCEAN.id] = Biome.FROZEN_OCEAN;
BIOME_MAPPING[BiomeBase.FROZEN_RIVER.id] = Biome.FROZEN_RIVER;
BIOME_MAPPING[BiomeBase.ICE_PLAINS.id] = Biome.ICE_PLAINS;
@@ -464,14 +472,55 @@ public class CraftBlock implements Block {
BIOME_MAPPING[BiomeBase.SMALL_MOUNTAINS.id] = Biome.SMALL_MOUNTAINS;
BIOME_MAPPING[BiomeBase.JUNGLE.id] = Biome.JUNGLE;
BIOME_MAPPING[BiomeBase.JUNGLE_HILLS.id] = Biome.JUNGLE_HILLS;
BIOME_MAPPING[BiomeBase.JUNGLE_EDGE.id] = Biome.JUNGLE_EDGE;
BIOME_MAPPING[BiomeBase.DEEP_OCEAN.id] = Biome.DEEP_OCEAN;
BIOME_MAPPING[BiomeBase.STONE_BEACH.id] = Biome.STONE_BEACH;
BIOME_MAPPING[BiomeBase.COLD_BEACH.id] = Biome.COLD_BEACH;
BIOME_MAPPING[BiomeBase.BIRCH_FOREST.id] = Biome.BIRCH_FOREST;
BIOME_MAPPING[BiomeBase.BIRCH_FOREST_HILLS.id] = Biome.BIRCH_FOREST_HILLS;
BIOME_MAPPING[BiomeBase.ROOFED_FOREST.id] = Biome.ROOFED_FOREST;
BIOME_MAPPING[BiomeBase.COLD_TAIGA.id] = Biome.COLD_TAIGA;
BIOME_MAPPING[BiomeBase.COLD_TAIGA_HILLS.id] = Biome.COLD_TAIGA_HILLS;
BIOME_MAPPING[BiomeBase.MEGA_TAIGA.id] = Biome.MEGA_TAIGA;
BIOME_MAPPING[BiomeBase.MEGA_TAIGA_HILLS.id] = Biome.MEGA_TAIGA_HILLS;
BIOME_MAPPING[BiomeBase.EXTREME_HILLS_PLUS.id] = Biome.EXTREME_HILLS_PLUS;
BIOME_MAPPING[BiomeBase.SAVANNA.id] = Biome.SAVANNA;
BIOME_MAPPING[BiomeBase.SAVANNA_PLATEAU.id] = Biome.SAVANNA_PLATEAU;
BIOME_MAPPING[BiomeBase.MESA.id] = Biome.MESA;
BIOME_MAPPING[BiomeBase.MESA_PLATEAU_F.id] = Biome.MESA_PLATEAU_FOREST;
BIOME_MAPPING[BiomeBase.MESA_PLATEAU.id] = Biome.MESA_PLATEAU;
// Extended Biomes
BIOME_MAPPING[BiomeBase.PLAINS.id + 128] = Biome.SUNFLOWER_PLAINS;
BIOME_MAPPING[BiomeBase.DESERT.id + 128] = Biome.DESERT_MOUNTAINS;
BIOME_MAPPING[BiomeBase.FOREST.id + 128] = Biome.FLOWER_FOREST;
BIOME_MAPPING[BiomeBase.TAIGA.id + 128] = Biome.TAIGA_MOUNTAINS;
BIOME_MAPPING[BiomeBase.SWAMPLAND.id + 128] = Biome.SWAMPLAND_MOUNTAINS;
BIOME_MAPPING[BiomeBase.ICE_PLAINS.id + 128] = Biome.ICE_PLAINS_SPIKES;
BIOME_MAPPING[BiomeBase.JUNGLE.id + 128] = Biome.JUNGLE_MOUNTAINS;
BIOME_MAPPING[BiomeBase.JUNGLE_EDGE.id + 128] = Biome.JUNGLE_EDGE_MOUNTAINS;
BIOME_MAPPING[BiomeBase.COLD_TAIGA.id + 128] = Biome.COLD_TAIGA_MOUNTAINS;
BIOME_MAPPING[BiomeBase.SAVANNA.id + 128] = Biome.SAVANNA_MOUNTAINS;
BIOME_MAPPING[BiomeBase.SAVANNA_PLATEAU.id + 128] = Biome.SAVANNA_PLATEAU_MOUNTAINS;
BIOME_MAPPING[BiomeBase.MESA.id + 128] = Biome.MESA_BRYCE;
BIOME_MAPPING[BiomeBase.MESA_PLATEAU_F.id + 128] = Biome.MESA_PLATEAU_FOREST_MOUNTAINS;
BIOME_MAPPING[BiomeBase.MESA_PLATEAU.id + 128] = Biome.MESA_PLATEAU_MOUNTAINS;
BIOME_MAPPING[BiomeBase.BIRCH_FOREST.id + 128] = Biome.BIRCH_FOREST_MOUNTAINS;
BIOME_MAPPING[BiomeBase.BIRCH_FOREST_HILLS.id + 128] = Biome.BIRCH_FOREST_HILLS_MOUNTAINS;
BIOME_MAPPING[BiomeBase.ROOFED_FOREST.id + 128] = Biome.ROOFED_FOREST_MOUNTAINS;
BIOME_MAPPING[BiomeBase.MEGA_TAIGA.id + 128] = Biome.MEGA_SPRUCE_TAIGA;
BIOME_MAPPING[BiomeBase.EXTREME_HILLS.id + 128] = Biome.EXTREME_HILLS_MOUNTAINS;
BIOME_MAPPING[BiomeBase.EXTREME_HILLS_PLUS.id + 128] = Biome.EXTREME_HILLS_PLUS_MOUNTAINS;
BIOME_MAPPING[BiomeBase.MEGA_TAIGA_HILLS.id + 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 ((BiomeBase.biomes[i] != null) && (BIOME_MAPPING[i] == null)) {
throw new IllegalArgumentException("Missing Biome mapping for BiomeBase[" + i + "]");
if ((BiomeBase.getBiome(i) != null) && (BIOME_MAPPING[i] == null)) {
throw new IllegalArgumentException("Missing Biome mapping for BiomeBase[" + i + ", " + BiomeBase.getBiome(i) + "]");
}
if (BIOME_MAPPING[i] != null) { /* Build reverse mapping for setBiome */
BIOMEBASE_MAPPING[BIOME_MAPPING[i].ordinal()] = BiomeBase.biomes[i];
BIOMEBASE_MAPPING[BIOME_MAPPING[i].ordinal()] = BiomeBase.getBiome(i);
}
}
}

View File

@@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntityChest;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;

View File

@@ -1,48 +1,48 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntityCommand;
import org.bukkit.block.Block;
import org.bukkit.block.CommandBlock;
import org.bukkit.craftbukkit.CraftWorld;
public class CraftCommandBlock extends CraftBlockState implements CommandBlock {
private final TileEntityCommand commandBlock;
private String command;
private String name;
public CraftCommandBlock(Block block) {
super(block);
CraftWorld world = (CraftWorld) block.getWorld();
commandBlock = (TileEntityCommand) world.getTileEntityAt(getX(), getY(), getZ());
command = commandBlock.b;
name = commandBlock.getName();
}
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.a(command);
commandBlock.b(name);
}
return result;
}
}
package org.bukkit.craftbukkit.block;
import net.minecraft.server.TileEntityCommand;
import org.bukkit.block.Block;
import org.bukkit.block.CommandBlock;
import org.bukkit.craftbukkit.CraftWorld;
public class CraftCommandBlock extends CraftBlockState implements CommandBlock {
private final TileEntityCommand commandBlock;
private String command;
private String name;
public CraftCommandBlock(Block block) {
super(block);
CraftWorld world = (CraftWorld) block.getWorld();
commandBlock = (TileEntityCommand) world.getTileEntityAt(getX(), getY(), getZ());
command = commandBlock.a().e;
name = commandBlock.a().getName();
}
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.a().a(command);
commandBlock.a().b(name);
}
return result;
}
}

View File

@@ -1,7 +1,7 @@
package org.bukkit.craftbukkit.block;
import java.util.Random;
import net.minecraft.server.BlockDispenser;
import net.minecraft.server.Blocks;
import net.minecraft.server.TileEntityDispenser;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -29,7 +29,7 @@ public class CraftDispenser extends CraftBlockState implements Dispenser {
Block block = getBlock();
if (block.getType() == Material.DISPENSER) {
BlockDispenser dispense = (BlockDispenser) net.minecraft.server.Block.DISPENSER;
BlockDispenser dispense = (BlockDispenser) Blocks.DISPENSER;
dispense.dispense(world.getHandle(), getX(), getY(), getZ());
return true;

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.BlockDropper;
import net.minecraft.server.Blocks;
import net.minecraft.server.TileEntityDropper;
import org.bukkit.Material;
@@ -29,7 +30,7 @@ public class CraftDropper extends CraftBlockState implements Dropper {
Block block = getBlock();
if (block.getType() == Material.DROPPER) {
BlockDropper drop = (BlockDropper) net.minecraft.server.Block.DROPPER;
BlockDropper drop = (BlockDropper) Blocks.DROPPER;
drop.dispense(world.getHandle(), getX(), getY(), getZ());
}

View File

@@ -1,15 +1,15 @@
package org.bukkit.craftbukkit.block;
import net.minecraft.server.Item;
import net.minecraft.server.BlockJukeBox;
import net.minecraft.server.Blocks;
import net.minecraft.server.ItemStack;
import net.minecraft.server.TileEntityRecordPlayer;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Jukebox;
import org.bukkit.craftbukkit.CraftWorld;
import net.minecraft.server.BlockJukeBox;
import net.minecraft.server.TileEntityRecordPlayer;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
public class CraftJukebox extends CraftBlockState implements Jukebox {
private final CraftWorld world;
@@ -22,20 +22,22 @@ public class CraftJukebox extends CraftBlockState implements Jukebox {
jukebox = (TileEntityRecordPlayer) world.getTileEntityAt(getX(), getY(), getZ());
}
@Override
public Material getPlaying() {
ItemStack record = jukebox.getRecord();
if (record == null) {
return Material.AIR;
}
return Material.getMaterial(record.id);
return CraftMagicNumbers.getMaterial(record.getItem());
}
@Override
public void setPlaying(Material record) {
if (record == null || Item.byId[record.getId()] == null) {
if (record == null || CraftMagicNumbers.getItem(record) == null) {
record = Material.AIR;
jukebox.setRecord(null);
} else {
jukebox.setRecord(new ItemStack(Item.byId[record.getId()], 1));
jukebox.setRecord(new ItemStack(CraftMagicNumbers.getItem(record), 1));
}
jukebox.update();
if (record == Material.AIR) {
@@ -52,7 +54,7 @@ public class CraftJukebox extends CraftBlockState implements Jukebox {
public boolean eject() {
boolean result = isPlaying();
((BlockJukeBox) net.minecraft.server.Block.JUKEBOX).dropRecord(world.getHandle(), getX(), getY(), getZ());
((BlockJukeBox) Blocks.JUKEBOX).dropRecord(world.getHandle(), getX(), getY(), getZ());
return result;
}
}

View File

@@ -8,6 +8,7 @@ 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;
@@ -47,22 +48,24 @@ public class CraftNoteBlock extends CraftBlockState implements NoteBlock {
}
}
@Override
public boolean play(byte instrument, byte note) {
Block block = getBlock();
if (block.getType() == Material.NOTE_BLOCK) {
world.getHandle().playNote(getX(), getY(), getZ(), block.getTypeId(), instrument, note);
world.getHandle().playNote(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().playNote(getX(), getY(), getZ(), block.getTypeId(), instrument.getType(), note.getId());
world.getHandle().playNote(getX(), getY(), getZ(), CraftMagicNumbers.getBlock(block), instrument.getType(), note.getId());
return true;
} else {
return false;