Update to Minecraft 1.9

This commit is contained in:
md_5
2016-03-01 08:32:46 +11:00
parent e1ebe524a7
commit aa008dff0f
305 changed files with 6684 additions and 6105 deletions

View File

@@ -23,9 +23,7 @@ public class CraftChunk implements Chunk {
private static final byte[] emptySkyLight = new byte[2048];
public CraftChunk(net.minecraft.server.Chunk chunk) {
if (!(chunk instanceof EmptyChunk)) {
this.weakChunk = new WeakReference<net.minecraft.server.Chunk>(chunk);
}
this.weakChunk = new WeakReference<net.minecraft.server.Chunk>(chunk);
worldServer = (WorldServer) getHandle().world;
x = getHandle().locX;
@@ -46,9 +44,7 @@ public class CraftChunk implements Chunk {
if (c == null) {
c = worldServer.getChunkAt(x, z);
if (!(c instanceof EmptyChunk)) {
weakChunk = new WeakReference<net.minecraft.server.Chunk>(c);
}
weakChunk = new WeakReference<net.minecraft.server.Chunk>(c);
}
return c;
@@ -164,22 +160,16 @@ public class CraftChunk implements Chunk {
sectionEmpty[i] = true;
} else { // Not empty
short[] blockids = new short[4096];
char[] baseids = cs[i].getIdArray();
byte[] dataValues = sectionBlockData[i] = new byte[2048];
byte[] rawIds = new byte[4096];
NibbleArray data = new NibbleArray();
cs[i].getBlocks().exportData(rawIds, data);
byte[] dataValues = sectionBlockData[i] = data.asBytes();
// Copy base IDs
for (int j = 0; j < 4096; j++) {
if (baseids[j] == 0) continue;
IBlockData blockData = (IBlockData) net.minecraft.server.Block.d.a(baseids[j]);
if (blockData == null) continue;
blockids[j] = (short) net.minecraft.server.Block.getId(blockData.getBlock());
int data = blockData.getBlock().toLegacyData(blockData);
int jj = j >> 1;
if ((j & 1) == 0) {
dataValues[jj] = (byte) ((dataValues[jj] & 0xF0) | (data & 0xF));
} else {
dataValues[jj] = (byte) ((dataValues[jj] & 0xF) | ((data & 0xF) << 4));
}
blockids[j] = (short) (rawIds[j] & 0xFF);
}
sectionBlockIDs[i] = blockids;
@@ -188,10 +178,10 @@ public class CraftChunk implements Chunk {
sectionSkyLights[i] = emptyData;
} else {
sectionSkyLights[i] = new byte[2048];
System.arraycopy(cs[i].getSkyLightArray().a(), 0, sectionSkyLights[i], 0, 2048);
System.arraycopy(cs[i].getSkyLightArray().asBytes(), 0, sectionSkyLights[i], 0, 2048);
}
sectionEmitLights[i] = new byte[2048];
System.arraycopy(cs[i].getEmittedLightArray().a(), 0, sectionEmitLights[i], 0, 2048);
System.arraycopy(cs[i].getEmittedLightArray().asBytes(), 0, sectionEmitLights[i], 0, 2048);
}
}
@@ -225,11 +215,13 @@ public class CraftChunk implements Chunk {
biomeTemp[i] = dat[i];
}
/* Removed 15w46a
dat = wcm.getWetness(null, getX() << 4, getZ() << 4, 16, 16);
for (int i = 0; i < 256; i++) {
biomeRain[i] = dat[i];
}
*/
}
}
@@ -261,11 +253,13 @@ public class CraftChunk implements Chunk {
biomeTemp[i] = dat[i];
}
/* Removed 15w46a
dat = wcm.getWetness(null, x << 4, z << 4, 16, 16);
for (int i = 0; i < 256; i++) {
biomeRain[i] = dat[i];
}
*/
}
}
@@ -293,7 +287,7 @@ public class CraftChunk implements Chunk {
float[] temps = new float[biomes.length];
for (int i = 0; i < biomes.length; i++) {
float temp = biomes[i].temperature; // Vanilla of olde: ((int) biomes[i].temperature * 65536.0F) / 65536.0F
float temp = biomes[i].getTemperature(); // Vanilla of olde: ((int) biomes[i].temperature * 65536.0F) / 65536.0F
if (temp > 1F) {
temp = 1F;

View File

@@ -1,35 +1,32 @@
package org.bukkit.craftbukkit;
import net.minecraft.server.EnumItemSlot;
import org.bukkit.inventory.EquipmentSlot;
public class CraftEquipmentSlot {
private static final int[] slots = new int[EquipmentSlot.values().length];
private static final EquipmentSlot[] enums = new EquipmentSlot[EquipmentSlot.values().length];
private static final EnumItemSlot[] slots = new EnumItemSlot[EquipmentSlot.values().length];
private static final EquipmentSlot[] enums = new EquipmentSlot[EnumItemSlot.values().length];
static {
set(EquipmentSlot.HAND, 0);
set(EquipmentSlot.FEET, 1);
set(EquipmentSlot.LEGS, 2);
set(EquipmentSlot.CHEST, 3);
set(EquipmentSlot.HEAD, 4);
set(EquipmentSlot.HAND, EnumItemSlot.MAINHAND);
set(EquipmentSlot.OFF_HAND, EnumItemSlot.OFFHAND);
set(EquipmentSlot.FEET, EnumItemSlot.FEET);
set(EquipmentSlot.LEGS, EnumItemSlot.LEGS);
set(EquipmentSlot.CHEST, EnumItemSlot.CHEST);
set(EquipmentSlot.HEAD, EnumItemSlot.HEAD);
}
private static void set(EquipmentSlot type, int value) {
private static void set(EquipmentSlot type, EnumItemSlot value) {
slots[type.ordinal()] = value;
if (value < enums.length) {
enums[value] = type;
}
enums[value.ordinal()] = type;
}
public static EquipmentSlot getSlot(int magic) {
if (magic > 0 && magic < enums.length) {
return enums[magic];
}
return null;
public static EquipmentSlot getSlot(EnumItemSlot nms) {
return enums[nms.ordinal()];
}
public static int getSlotIndex(EquipmentSlot slot) {
public static EnumItemSlot getNMS(EquipmentSlot slot) {
return slots[slot.ordinal()];
}
}

View File

@@ -0,0 +1,42 @@
package org.bukkit.craftbukkit;
import net.minecraft.server.Block;
import net.minecraft.server.EnumParticle;
import net.minecraft.server.IBlockData;
import org.bukkit.Particle;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
public class CraftParticle {
public static EnumParticle toNMS(Particle bukkit) {
return EnumParticle.valueOf(bukkit.name());
}
public static Particle toBukkit(EnumParticle nms) {
return Particle.valueOf(nms.name());
}
public static int[] toData(Particle particle, Object obj) {
if (particle.getDataType().equals(Void.class)) {
return new int[0];
}
if (particle.getDataType().equals(ItemStack.class)) {
if (obj == null) {
return new int[]{0, 0};
}
ItemStack itemStack = (ItemStack) obj;
return new int[]{itemStack.getType().getId(), itemStack.getDurability()};
}
if (particle.getDataType().equals(MaterialData.class)) {
if (obj == null) {
return new int[]{0};
}
MaterialData data = (MaterialData) obj;
IBlockData nms = CraftMagicNumbers.getBlock(data.getItemType()).fromLegacyData(data.getData());
return new int[]{Block.REGISTRY_ID.getId(nms)};
}
throw new IllegalArgumentException(particle.getDataType().toString());
}
}

View File

@@ -36,6 +36,10 @@ import org.bukkit.Warning.WarningState;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarFlag;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
@@ -46,6 +50,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.conversations.Conversable;
import org.bukkit.craftbukkit.boss.CraftBossBar;
import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.generator.CraftChunkData;
@@ -74,7 +79,6 @@ import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.help.HelpMap;
@@ -188,11 +192,11 @@ public final class CraftServer implements Server {
Bukkit.setServer(this);
// Register all the Enchantments and PotionTypes now so we can stop new registration immediately after
Enchantment.DAMAGE_ALL.getClass();
Enchantments.DAMAGE_ALL.getClass();
org.bukkit.enchantments.Enchantment.stopAcceptingRegistrations();
Potion.setPotionBrewer(new CraftPotionBrewer());
MobEffectList.BLINDNESS.getClass();
MobEffects.BLINDNESS.getClass();
PotionEffectType.stopAcceptingRegistrations();
// Ugly hack :(
@@ -331,7 +335,7 @@ public final class CraftServer implements Server {
}
private void setVanillaCommands() {
Map<String, ICommand> commands = new CommandDispatcher().getCommands();
Map<String, ICommand> commands = new CommandDispatcher(console).getCommands();
for (ICommand cmd : commands.values()) {
commandMap.register("minecraft", new VanillaCommandWrapper((CommandAbstract) cmd, LocaleI18n.get(cmd.getUsage(null))));
}
@@ -467,7 +471,7 @@ public final class CraftServer implements Server {
return playerList.getMaxPlayers();
}
// NOTE: These are dependent on the corrisponding call in MinecraftServer
// NOTE: These are dependent on the corresponding call in MinecraftServer
// so if that changes this will need to as well
@Override
public int getPort() {
@@ -823,7 +827,7 @@ public final class CraftServer implements Server {
generator = getGenerator(name);
}
Convertable converter = new WorldLoaderServer(getWorldContainer());
Convertable converter = new WorldLoaderServer(getWorldContainer(), getHandle().getServer().getDataConverterManager());
if (converter.isConvertable(name)) {
getLogger().info("Converting world '" + name + "'");
converter.convert(name, new IProgressUpdate() {
@@ -856,7 +860,7 @@ public final class CraftServer implements Server {
} while(used);
boolean hardcore = false;
IDataManager sdm = new ServerNBTManager(getWorldContainer(), name, true);
IDataManager sdm = new ServerNBTManager(getWorldContainer(), name, true, getHandle().getServer().getDataConverterManager());
WorldData worlddata = sdm.getWorldData();
if (worlddata == null) {
WorldSettings worldSettings = new WorldSettings(creator.seed(), WorldSettings.EnumGamemode.getById(getDefaultGameMode().getValue()), generateStructures, hardcore, type);
@@ -905,7 +909,7 @@ public final class CraftServer implements Server {
}
BlockPosition chunkcoordinates = internal.getSpawn();
internal.chunkProviderServer.getChunkAt(chunkcoordinates.getX() + j >> 4, chunkcoordinates.getZ() + k >> 4);
internal.getChunkProviderServer().getChunkAt(chunkcoordinates.getX() + j >> 4, chunkcoordinates.getZ() + k >> 4);
}
}
}
@@ -1084,6 +1088,7 @@ public final class CraftServer implements Server {
CraftingManager.getInstance().recipes.clear();
RecipesFurnace.getInstance().recipes.clear();
RecipesFurnace.getInstance().customRecipes.clear();
RecipesFurnace.getInstance().customExperience.clear();
}
@Override
@@ -1091,6 +1096,7 @@ public final class CraftServer implements Server {
CraftingManager.getInstance().recipes = new CraftingManager().recipes;
RecipesFurnace.getInstance().recipes = new RecipesFurnace().recipes;
RecipesFurnace.getInstance().customRecipes.clear();
RecipesFurnace.getInstance().customExperience.clear();
}
@Override
@@ -1250,7 +1256,7 @@ public final class CraftServer implements Server {
OfflinePlayer result = getPlayerExact(name);
if (result == null) {
// This is potentially blocking :(
GameProfile profile = MinecraftServer.getServer().getUserCache().getProfile(name);
GameProfile profile = console.getUserCache().getProfile(name);
if (profile == null) {
// Make an OfflinePlayer using an offline mode UUID since the name has no profile
result = getOfflinePlayer(new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name));
@@ -1637,6 +1643,11 @@ public final class CraftServer implements Server {
return new CraftChunkData(world);
}
@Override
public BossBar createBossBar(String title, BarColor color, BarStyle style, BarFlag... flags) {
return new CraftBossBar(title, color, style, flags);
}
@Deprecated
@Override
public UnsafeValues getUnsafe() {

View File

@@ -1,230 +1,25 @@
package org.bukkit.craftbukkit;
import static org.bukkit.Sound.*;
import com.google.common.base.Preconditions;
import net.minecraft.server.MinecraftKey;
import net.minecraft.server.SoundEffect;
import org.apache.commons.lang.Validate;
import org.bukkit.Sound;
public class CraftSound {
private static final String[] sounds = new String[Sound.values().length];
static {
// Ambient
set(AMBIENCE_CAVE, "ambient.cave.cave");
set(AMBIENCE_RAIN, "ambient.weather.rain");
set(AMBIENCE_THUNDER, "ambient.weather.thunder");
// Damage
set(HURT_FLESH, "game.neutral.hurt");
set(FALL_BIG, "game.neutral.hurt.fall.big");
set(FALL_SMALL, "game.neutral.hurt.fall.small");
// Dig Sounds
set(DIG_WOOL, "dig.cloth");
set(DIG_GRASS, "dig.grass");
set(DIG_GRAVEL, "dig.gravel");
set(DIG_SAND, "dig.sand");
set(DIG_SNOW, "dig.snow");
set(DIG_STONE, "dig.stone");
set(DIG_WOOD, "dig.wood");
// Fire
set(FIRE, "fire.fire");
set(FIRE_IGNITE, "fire.ignite");
// Fireworks
set(FIREWORK_BLAST, "fireworks.blast");
set(FIREWORK_BLAST2, "fireworks.blast_far");
set(FIREWORK_LARGE_BLAST, "fireworks.largeBlast");
set(FIREWORK_LARGE_BLAST2, "fireworks.largeBlast_far");
set(FIREWORK_TWINKLE, "fireworks.twinkle");
set(FIREWORK_TWINKLE2, "fireworks.twinkle_far");
set(FIREWORK_LAUNCH, "fireworks.launch");
// Liquid
set(SPLASH2, "game.neutral.swim.splash");
set(SWIM, "game.neutral.swim");
set(WATER, "liquid.water");
set(LAVA, "liquid.lava");
set(LAVA_POP, "liquid.lavapop");
// Minecart
set(MINECART_BASE, "minecart.base");
set(MINECART_INSIDE, "minecart.inside");
// Mob
set(BAT_DEATH, "mob.bat.death");
set(BAT_HURT, "mob.bat.hurt");
set(BAT_IDLE, "mob.bat.idle");
set(BAT_LOOP, "mob.bat.loop");
set(BAT_TAKEOFF, "mob.bat.takeoff");
set(BLAZE_BREATH, "mob.blaze.breathe");
set(BLAZE_DEATH, "mob.blaze.death");
set(BLAZE_HIT, "mob.blaze.hit");
set(CAT_HISS, "mob.cat.hiss");
set(CAT_HIT, "mob.cat.hitt");
set(CAT_MEOW, "mob.cat.meow");
set(CAT_PURR, "mob.cat.purr");
set(CAT_PURREOW, "mob.cat.purreow");
set(CHICKEN_IDLE, "mob.chicken.say");
set(CHICKEN_HURT, "mob.chicken.hurt");
set(CHICKEN_EGG_POP, "mob.chicken.plop");
set(CHICKEN_WALK, "mob.chicken.step");
set(COW_HURT, "mob.cow.hurt");
set(COW_IDLE, "mob.cow.say");
set(COW_WALK, "mob.cow.step");
set(CREEPER_DEATH, "mob.creeper.death");
set(CREEPER_HISS, "mob.creeper.say");
set(ENDERDRAGON_DEATH, "mob.enderdragon.end");
set(ENDERDRAGON_GROWL, "mob.enderdragon.growl");
set(ENDERDRAGON_HIT, "mob.enderdragon.hit");
set(ENDERDRAGON_WINGS, "mob.enderdragon.wings");
set(ENDERMAN_DEATH, "mob.endermen.death");
set(ENDERMAN_HIT, "mob.endermen.hit");
set(ENDERMAN_IDLE, "mob.endermen.idle");
set(ENDERMAN_TELEPORT, "mob.endermen.portal");
set(ENDERMAN_SCREAM, "mob.endermen.scream");
set(ENDERMAN_STARE, "mob.endermen.stare");
set(GHAST_SCREAM2, "mob.ghast.affectionate_scream");
set(GHAST_CHARGE, "mob.ghast.charge");
set(GHAST_DEATH, "mob.ghast.death");
set(GHAST_FIREBALL, "mob.ghast.fireball");
set(GHAST_MOAN, "mob.ghast.moan");
set(GHAST_SCREAM, "mob.ghast.scream");
set(HORSE_ANGRY, "mob.horse.angry");
set(HORSE_ARMOR, "mob.horse.armor");
set(HORSE_BREATHE, "mob.horse.breathe");
set(HORSE_DEATH, "mob.horse.death");
set(HORSE_GALLOP, "mob.horse.gallop");
set(HORSE_HIT, "mob.horse.hit");
set(HORSE_IDLE, "mob.horse.idle");
set(HORSE_JUMP, "mob.horse.jump");
set(HORSE_LAND, "mob.horse.land");
set(HORSE_SADDLE, "mob.horse.leather");
set(HORSE_SOFT, "mob.horse.soft");
set(HORSE_WOOD, "mob.horse.wood");
set(DONKEY_ANGRY, "mob.horse.donkey.angry");
set(DONKEY_DEATH, "mob.horse.donkey.death");
set(DONKEY_HIT, "mob.horse.donkey.hit");
set(DONKEY_IDLE, "mob.horse.donkey.idle");
set(HORSE_SKELETON_DEATH, "mob.horse.skeleton.death");
set(HORSE_SKELETON_HIT, "mob.horse.skeleton.hit");
set(HORSE_SKELETON_IDLE, "mob.horse.skeleton.idle");
set(HORSE_ZOMBIE_DEATH, "mob.horse.zombie.death");
set(HORSE_ZOMBIE_HIT, "mob.horse.zombie.hit");
set(HORSE_ZOMBIE_IDLE, "mob.horse.zombie.idle");
set(IRONGOLEM_DEATH, "mob.irongolem.death");
set(IRONGOLEM_HIT, "mob.irongolem.hit");
set(IRONGOLEM_THROW, "mob.irongolem.throw");
set(IRONGOLEM_WALK, "mob.irongolem.walk");
set(MAGMACUBE_WALK, "mob.magmacube.small");
set(MAGMACUBE_WALK2, "mob.magmacube.big");
set(MAGMACUBE_JUMP, "mob.magmacube.jump");
set(PIG_IDLE, "mob.pig.say");
set(PIG_DEATH, "mob.pig.death");
set(PIG_WALK, "mob.pig.step");
set(SHEEP_IDLE, "mob.sheep.say");
set(SHEEP_SHEAR, "mob.sheep.shear");
set(SHEEP_WALK, "mob.sheep.step");
set(SILVERFISH_HIT, "mob.silverfish.hit");
set(SILVERFISH_KILL, "mob.silverfish.kill");
set(SILVERFISH_IDLE, "mob.silverfish.say");
set(SILVERFISH_WALK, "mob.silverfish.step");
set(SKELETON_IDLE, "mob.skeleton.say");
set(SKELETON_DEATH, "mob.skeleton.death");
set(SKELETON_HURT, "mob.skeleton.hurt");
set(SKELETON_WALK, "mob.skeleton.step");
set(SLIME_ATTACK, "mob.slime.attack");
set(SLIME_WALK, "mob.slime.small");
set(SLIME_WALK2, "mob.slime.big");
set(SPIDER_IDLE, "mob.spider.say");
set(SPIDER_DEATH, "mob.spider.death");
set(SPIDER_WALK, "mob.spider.step");
set(VILLAGER_DEATH, "mob.villager.death");
set(VILLAGER_HAGGLE, "mob.villager.haggle");
set(VILLAGER_HIT, "mob.villager.hit");
set(VILLAGER_IDLE, "mob.villager.idle");
set(VILLAGER_NO, "mob.villager.no");
set(VILLAGER_YES, "mob.villager.yes");
set(WITHER_DEATH, "mob.wither.death");
set(WITHER_HURT, "mob.wither.hurt");
set(WITHER_IDLE, "mob.wither.idle");
set(WITHER_SHOOT, "mob.wither.shoot");
set(WITHER_SPAWN, "mob.wither.spawn");
set(WOLF_BARK, "mob.wolf.bark");
set(WOLF_DEATH, "mob.wolf.death");
set(WOLF_GROWL, "mob.wolf.growl");
set(WOLF_HOWL, "mob.wolf.howl");
set(WOLF_HURT, "mob.wolf.hurt");
set(WOLF_PANT, "mob.wolf.panting");
set(WOLF_SHAKE, "mob.wolf.shake");
set(WOLF_WALK, "mob.wolf.step");
set(WOLF_WHINE, "mob.wolf.whine");
set(ZOMBIE_METAL, "mob.zombie.metal");
set(ZOMBIE_WOOD, "mob.zombie.wood");
set(ZOMBIE_WOODBREAK, "mob.zombie.woodbreak");
set(ZOMBIE_IDLE, "mob.zombie.say");
set(ZOMBIE_DEATH, "mob.zombie.death");
set(ZOMBIE_HURT, "mob.zombie.hurt");
set(ZOMBIE_INFECT, "mob.zombie.infect");
set(ZOMBIE_UNFECT, "mob.zombie.unfect");
set(ZOMBIE_REMEDY, "mob.zombie.remedy");
set(ZOMBIE_WALK, "mob.zombie.step");
set(ZOMBIE_PIG_IDLE, "mob.zombiepig.zpig");
set(ZOMBIE_PIG_ANGRY, "mob.zombiepig.zpigangry");
set(ZOMBIE_PIG_DEATH, "mob.zombiepig.zpigdeath");
set(ZOMBIE_PIG_HURT, "mob.zombiepig.zpighurt");
// Note (blocks)
set(NOTE_BASS_GUITAR, "note.bassattack");
set(NOTE_SNARE_DRUM, "note.snare");
set(NOTE_PLING, "note.pling");
set(NOTE_BASS, "note.bass");
set(NOTE_PIANO, "note.harp");
set(NOTE_BASS_DRUM, "note.bd");
set(NOTE_STICKS, "note.hat");
// Portal
set(PORTAL, "portal.portal");
set(PORTAL_TRAVEL, "portal.travel");
set(PORTAL_TRIGGER, "portal.trigger");
// Random
set(ANVIL_BREAK, "random.anvil_break");
set(ANVIL_LAND, "random.anvil_land");
set(ANVIL_USE, "random.anvil_use");
set(SHOOT_ARROW, "random.bow");
set(ARROW_HIT, "random.bowhit");
set(ITEM_BREAK, "random.break");
set(BURP, "random.burp");
set(CHEST_CLOSE, "random.chestclosed");
set(CHEST_OPEN, "random.chestopen");
set(CLICK, "random.click");
set(DOOR_CLOSE, "random.door_close");
set(DOOR_OPEN, "random.door_open");
set(DRINK, "random.drink");
set(EAT, "random.eat");
set(EXPLODE, "random.explode");
set(FIZZ, "random.fizz");
set(FUSE, "creeper.primed");
set(GLASS, "dig.glass");
set(LEVEL_UP, "random.levelup");
set(ORB_PICKUP, "random.orb");
set(ITEM_PICKUP, "random.pop");
set(SPLASH, "random.splash");
set(SUCCESSFUL_HIT, "random.successful_hit");
set(WOOD_CLICK, "random.wood_click");
// Step
set(STEP_WOOL, "step.cloth");
set(STEP_GRASS, "step.grass");
set(STEP_GRAVEL, "step.gravel");
set(STEP_LADDER, "step.ladder");
set(STEP_SAND, "step.sand");
set(STEP_SNOW, "step.snow");
set(STEP_STONE, "step.stone");
set(STEP_WOOD, "step.wood");
// Tile
set(PISTON_EXTEND, "tile.piston.out");
set(PISTON_RETRACT, "tile.piston.in");
}
private static void set(Sound sound, String key) {
sounds[sound.ordinal()] = key;
}
public static String getSound(final Sound sound) {
Validate.notNull(sound, "Sound cannot be null");
return sounds[sound.ordinal()];
return sound.name().replace('_', '.').toLowerCase();
}
public static SoundEffect getSoundEffect(String s) {
SoundEffect effect = SoundEffect.a.get(new MinecraftKey(s));
Preconditions.checkArgument(effect != null, "Sound effect %s does not exist", s);
return effect;
}
private CraftSound() {}

View File

@@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableMap;
import net.minecraft.server.Block;
import net.minecraft.server.Item;
import net.minecraft.server.MinecraftKey;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
public class CraftStatistic {
private static final BiMap<String, org.bukkit.Statistic> statistics;
@@ -69,24 +70,30 @@ public class CraftStatistic {
}
public static org.bukkit.Statistic getBukkitStatisticByName(String name) {
if (name.startsWith("stat.killEntity")) {
if (name.startsWith("stat.killEntity.")) {
name = "stat.killEntity";
}
if (name.startsWith("stat.entityKilledBy")) {
if (name.startsWith("stat.entityKilledBy.")) {
name = "stat.entityKilledBy";
}
if (name.startsWith("stat.breakItem")) {
if (name.startsWith("stat.breakItem.")) {
name = "stat.breakItem";
}
if (name.startsWith("stat.useItem")) {
if (name.startsWith("stat.useItem.")) {
name = "stat.useItem";
}
if (name.startsWith("stat.mineBlock")) {
if (name.startsWith("stat.mineBlock.")) {
name = "stat.mineBlock";
}
if (name.startsWith("stat.craftItem")) {
if (name.startsWith("stat.craftItem.")) {
name = "stat.craftItem";
}
if (name.startsWith("stat.drop.")) {
name = "stat.drop";
}
if (name.startsWith("stat.pickup.")) {
name = "stat.pickup";
}
return statistics.get(name);
}
@@ -101,16 +108,16 @@ public class CraftStatistic {
public static net.minecraft.server.Statistic getMaterialStatistic(org.bukkit.Statistic stat, Material material) {
try {
if (stat == Statistic.MINE_BLOCK) {
return StatisticList.MINE_BLOCK_COUNT[material.getId()];
return StatisticList.a(CraftMagicNumbers.getBlock(material)); // PAIL: getMineBlockStatistic
}
if (stat == Statistic.CRAFT_ITEM) {
return StatisticList.CRAFT_BLOCK_COUNT[material.getId()];
return StatisticList.a(CraftMagicNumbers.getItem(material)); // PAIL: getCraftItemStatistic
}
if (stat == Statistic.USE_ITEM) {
return StatisticList.USE_ITEM_COUNT[material.getId()];
return StatisticList.b(CraftMagicNumbers.getItem(material)); // PAIL: getUseItemStatistic
}
if (stat == Statistic.BREAK_ITEM) {
return StatisticList.BREAK_ITEM_COUNT[material.getId()];
return StatisticList.c(CraftMagicNumbers.getItem(material)); // PAIL: getBreakItemStatistic
}
} catch (ArrayIndexOutOfBoundsException e) {
return null;

View File

@@ -25,8 +25,6 @@ public class CraftTravelAgent extends PortalTravelAgent implements TravelAgent {
@Override
public Location findOrCreate(Location target) {
WorldServer worldServer = ((CraftWorld) target.getWorld()).getHandle();
boolean before = worldServer.chunkProviderServer.forceChunkLoad;
worldServer.chunkProviderServer.forceChunkLoad = true;
Location found = this.findPortal(target);
if (found == null) {
@@ -37,7 +35,6 @@ public class CraftTravelAgent extends PortalTravelAgent implements TravelAgent {
}
}
worldServer.chunkProviderServer.forceChunkLoad = before;
return found;
}

View File

@@ -22,6 +22,7 @@ import org.bukkit.ChunkSnapshot;
import org.bukkit.Difficulty;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.TreeType;
import org.bukkit.World;
@@ -45,8 +46,6 @@ import org.bukkit.entity.minecart.PoweredMinecart;
import org.bukkit.entity.minecart.SpawnerMinecart;
import org.bukkit.entity.minecart.StorageMinecart;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.world.SpawnChangeEvent;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
@@ -123,7 +122,7 @@ public class CraftWorld implements World {
}
public Chunk getChunkAt(int x, int z) {
return this.world.chunkProviderServer.getChunkAt(x, z).bukkitChunk;
return this.world.getChunkProviderServer().getChunkAt(x, z).bukkitChunk;
}
public Chunk getChunkAt(Block block) {
@@ -131,11 +130,11 @@ public class CraftWorld implements World {
}
public boolean isChunkLoaded(int x, int z) {
return world.chunkProviderServer.isChunkLoaded(x, z);
return world.getChunkProviderServer().isChunkLoaded(x, z);
}
public Chunk[] getLoadedChunks() {
Object[] chunks = world.chunkProviderServer.chunks.values().toArray();
Object[] chunks = world.getChunkProviderServer().chunks.values().toArray();
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
for (int i = 0; i < chunks.length; i++) {
@@ -171,7 +170,7 @@ public class CraftWorld implements World {
return false;
}
world.chunkProviderServer.queueUnload(x, z);
world.getChunkProviderServer().queueUnload(x, z);
return true;
}
@@ -181,20 +180,20 @@ public class CraftWorld implements World {
return false;
}
net.minecraft.server.Chunk chunk = world.chunkProviderServer.getOrCreateChunk(x, z);
net.minecraft.server.Chunk chunk = world.getChunkProviderServer().getChunkAt(x, z);
if (chunk.mustSave) { // If chunk had previously been queued to save, must do save to avoid loss of that data
save = true;
}
chunk.removeEntities(); // Always remove entities - even if discarding, need to get them out of world table
if (save && !(chunk instanceof EmptyChunk)) {
world.chunkProviderServer.saveChunk(chunk);
world.chunkProviderServer.saveChunkNOP(chunk);
if (save) {
world.getChunkProviderServer().saveChunk(chunk);
world.getChunkProviderServer().saveChunkNOP(chunk);
}
world.chunkProviderServer.unloadQueue.remove(x, z);
world.chunkProviderServer.chunks.remove(LongHash.toLong(x, z));
world.getChunkProviderServer().unloadQueue.remove(x, z);
world.getChunkProviderServer().chunks.remove(LongHash.toLong(x, z));
return true;
}
@@ -202,15 +201,11 @@ public class CraftWorld implements World {
public boolean regenerateChunk(int x, int z) {
unloadChunk(x, z, false, false);
world.chunkProviderServer.unloadQueue.remove(x, z);
world.getChunkProviderServer().unloadQueue.remove(x, z);
net.minecraft.server.Chunk chunk = null;
if (world.chunkProviderServer.chunkProvider == null) {
chunk = world.chunkProviderServer.emptyChunk;
} else {
chunk = world.chunkProviderServer.chunkProvider.getOrCreateChunk(x, z);
}
chunk = world.getChunkProviderServer().chunkGenerator.getOrCreateChunk(x, z);
chunkLoadPostProcess(chunk, x, z);
@@ -232,9 +227,9 @@ public class CraftWorld implements World {
// This flags 65 blocks distributed across all the sections of the chunk, so that everything is sent, including biomes
int height = getMaxHeight() / 16;
for (int idx = 0; idx < 64; idx++) {
world.notify(new BlockPosition(px + (idx / height), ((idx % height) * 16), pz));
world.notify(new BlockPosition(px + (idx / height), ((idx % height) * 16), pz), Blocks.AIR.getBlockData(), Blocks.STONE.getBlockData(), 3);
}
world.notify(new BlockPosition(px + 15, (height * 16) - 1, pz + 15));
world.notify(new BlockPosition(px + 15, (height * 16) - 1, pz + 15), Blocks.AIR.getBlockData(), Blocks.STONE.getBlockData(), 3);
return true;
}
@@ -247,23 +242,21 @@ public class CraftWorld implements World {
chunkLoadCount++;
if (generate) {
// Use the default variant of loadChunk when generate == true.
return world.chunkProviderServer.getChunkAt(x, z) != null;
return world.getChunkProviderServer().getChunkAt(x, z) != null;
}
world.chunkProviderServer.unloadQueue.remove(x, z);
net.minecraft.server.Chunk chunk = world.chunkProviderServer.chunks.get(LongHash.toLong(x, z));
world.getChunkProviderServer().unloadQueue.remove(x, z);
net.minecraft.server.Chunk chunk = world.getChunkProviderServer().chunks.get(LongHash.toLong(x, z));
if (chunk == null) {
chunk = world.chunkProviderServer.loadChunk(x, z);
chunkLoadPostProcess(chunk, x, z);
chunk = world.getChunkProviderServer().getOrLoadChunkAt(x, z);
}
return chunk != null;
}
private void chunkLoadPostProcess(net.minecraft.server.Chunk chunk, int cx, int cz) {
if (chunk != null) {
world.chunkProviderServer.chunks.put(LongHash.toLong(cx, cz), chunk);
world.getChunkProviderServer().chunks.put(LongHash.toLong(cx, cz), chunk);
chunk.addEntities();
@@ -274,7 +267,7 @@ public class CraftWorld implements World {
continue;
}
net.minecraft.server.Chunk neighbor = world.chunkProviderServer.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z);
net.minecraft.server.Chunk neighbor = world.getChunkProviderServer().getChunkIfLoaded(chunk.locX + x, chunk.locZ + z);
if (neighbor != null) {
neighbor.setNeighborLoaded(-x, -z);
chunk.setNeighborLoaded(x, z);
@@ -283,7 +276,7 @@ public class CraftWorld implements World {
}
// CraftBukkit end
chunk.loadNearby(world.chunkProviderServer, world.chunkProviderServer, cx, cz);
chunk.loadNearby(world.getChunkProviderServer(), world.getChunkProviderServer().chunkGenerator);
}
}
@@ -351,30 +344,19 @@ public class CraftWorld implements World {
Validate.notNull(loc, "Can not spawn arrow with a null location");
Validate.notNull(velocity, "Can not spawn arrow with a null velocity");
EntityArrow arrow = new EntityArrow(world);
EntityArrow arrow = new EntityTippedArrow(world);
arrow.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
arrow.shoot(velocity.getX(), velocity.getY(), velocity.getZ(), speed, spread);
world.addEntity(arrow);
return (Arrow) arrow.getBukkitEntity();
}
@Deprecated
public LivingEntity spawnCreature(Location loc, CreatureType creatureType) {
return spawnCreature(loc, creatureType.toEntityType());
}
@Deprecated
public LivingEntity spawnCreature(Location loc, EntityType creatureType) {
Validate.isTrue(creatureType.isAlive(), "EntityType not instance of LivingEntity");
return (LivingEntity) spawnEntity(loc, creatureType);
}
public Entity spawnEntity(Location loc, EntityType entityType) {
return spawn(loc, entityType.getEntityClass());
}
public LightningStrike strikeLightning(Location loc) {
EntityLightning lightning = new EntityLightning(world, loc.getX(), loc.getY(), loc.getZ());
EntityLightning lightning = new EntityLightning(world, loc.getX(), loc.getY(), loc.getZ(), false);
world.strikeLightning(lightning);
return new CraftLightningStrike(server, lightning);
}
@@ -462,12 +444,12 @@ public class CraftWorld implements World {
int y = blockstate.getY();
int z = blockstate.getZ();
BlockPosition position = new BlockPosition(x, y, z);
net.minecraft.server.Block oldBlock = world.getType(position).getBlock();
net.minecraft.server.IBlockData oldBlock = world.getType(position);
int typeId = blockstate.getTypeId();
int data = blockstate.getRawData();
int flag = ((CraftBlockState)blockstate).getFlag();
delegate.setTypeIdAndData(x, y, z, typeId, data);
net.minecraft.server.Block newBlock = world.getType(position).getBlock();
net.minecraft.server.IBlockData newBlock = world.getType(position);
world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, flag);
}
world.capturedBlockStates.clear();
@@ -555,7 +537,17 @@ public class CraftWorld implements World {
public void setEnvironment(Environment env) {
if (environment != env) {
environment = env;
world.worldProvider = WorldProvider.byDimension(environment.getId());
switch (env) {
case NORMAL:
world.worldProvider = new WorldProviderNormal();
break;
case NETHER:
world.worldProvider = new WorldProviderHell();
break;
case THE_END:
world.worldProvider = new WorldProviderTheEnd();
break;
}
}
}
@@ -602,17 +594,17 @@ public class CraftWorld implements World {
if (chunk != null) {
byte[] biomevals = chunk.getBiomeIndex();
biomevals[((z & 0xF) << 4) | (x & 0xF)] = (byte)bb.id;
biomevals[((z & 0xF) << 4) | (x & 0xF)] = (byte) BiomeBase.REGISTRY_ID.a(bb);
}
}
}
public double getTemperature(int x, int z) {
return this.world.getBiome(new BlockPosition(x, 0, z)).temperature;
return this.world.getBiome(new BlockPosition(x, 0, z)).getTemperature();
}
public double getHumidity(int x, int z) {
return this.world.getBiome(new BlockPosition(x, 0, z)).humidity;
return this.world.getBiome(new BlockPosition(x, 0, z)).getHumidity();
}
public List<Entity> getEntities() {
@@ -911,7 +903,7 @@ public class CraftWorld implements World {
} else if (Egg.class.isAssignableFrom(clazz)) {
entity = new EntityEgg(world, x, y, z);
} else if (Arrow.class.isAssignableFrom(clazz)) {
entity = new EntityArrow(world);
entity = new EntityTippedArrow(world);
entity.setPositionRotation(x, y, z, 0, 0);
} else if (ThrownExpBottle.class.isAssignableFrom(clazz)) {
entity = new EntityThrownExpBottle(world);
@@ -926,12 +918,17 @@ public class CraftWorld implements World {
entity = new EntitySmallFireball(world);
} else if (WitherSkull.class.isAssignableFrom(clazz)) {
entity = new EntityWitherSkull(world);
} else {
} else if (DragonFireball.class.isAssignableFrom(clazz)){
entity = new EntityDragonFireball(world);
}else{
entity = new EntityLargeFireball(world);
}
entity.setPositionRotation(x, y, z, yaw, pitch);
Vector direction = location.getDirection().multiply(10);
((EntityFireball) entity).setDirection(direction.getX(), direction.getY(), direction.getZ());
} else if (ShulkerBullet.class.isAssignableFrom(clazz)) {
entity = new EntityShulkerBullet(world);
entity.setPositionRotation(x, y, z, yaw, pitch);
}
} else if (Minecart.class.isAssignableFrom(clazz)) {
if (PoweredMinecart.class.isAssignableFrom(clazz)) {
@@ -966,6 +963,8 @@ public class CraftWorld implements World {
entity = new EntitySnowman(world);
} else if (IronGolem.class.isAssignableFrom(clazz)) {
entity = new EntityIronGolem(world);
} else if (Shulker.class.isAssignableFrom(clazz)) {
entity = new EntityShulker(world);
}
} else if (Creeper.class.isAssignableFrom(clazz)) {
entity = new EntityCreeper(world);
@@ -1059,9 +1058,9 @@ public class CraftWorld implements World {
final BlockPosition pos = new BlockPosition((int) x, (int) y, (int) z);
for (BlockFace dir : faces) {
net.minecraft.server.Block nmsBlock = CraftMagicNumbers.getBlock(block.getRelative(dir));
if (nmsBlock.getMaterial().isBuildable() || BlockDiodeAbstract.d(nmsBlock)) {
if (nmsBlock.getBlockData().getMaterial().isBuildable() || BlockDiodeAbstract.isDiode(nmsBlock.getBlockData())) {
boolean taken = false;
AxisAlignedBB bb = EntityHanging.calculateBoundingBox(pos,CraftBlock.blockFaceToNotch(dir).opposite(),width,height);
AxisAlignedBB bb = EntityHanging.calculateBoundingBox(null, pos,CraftBlock.blockFaceToNotch(dir).opposite(),width,height);
List<net.minecraft.server.Entity> list = (List<net.minecraft.server.Entity>) world.getEntities(null, bb);
for (Iterator<net.minecraft.server.Entity> it = list.iterator(); !taken && it.hasNext();) {
net.minecraft.server.Entity e = it.next();
@@ -1098,11 +1097,13 @@ public class CraftWorld implements World {
} else if (Weather.class.isAssignableFrom(clazz)) {
// not sure what this can do
if (LightningStrike.class.isAssignableFrom(clazz)) {
entity = new EntityLightning(world, x, y, z);
entity = new EntityLightning(world, x, y, z, false);
// what is this, I don't even
}
} else if (Firework.class.isAssignableFrom(clazz)) {
entity = new EntityFireworks(world, x, y, z, null);
} else if (AreaEffectCloud.class.isAssignableFrom(clazz)) {
entity = new EntityAreaEffectCloud(world, x, y, z);
}
if (entity != null) {
@@ -1117,7 +1118,7 @@ public class CraftWorld implements World {
Preconditions.checkArgument(entity != null, "Cannot spawn null entity");
if (entity instanceof EntityInsentient) {
((EntityInsentient) entity).prepare(getHandle().E(new BlockPosition(entity)), (GroupDataEntity) null);
((EntityInsentient) entity).prepare(getHandle().D(new BlockPosition(entity)), (GroupDataEntity) null);
}
world.addEntity(entity, reason);
@@ -1171,11 +1172,7 @@ public class CraftWorld implements World {
loadChunk(chunkCoordX + x, chunkCoordZ + z);
} else {
if (isChunkLoaded(chunkCoordX + x, chunkCoordZ + z)) {
if (this.getHandle().getChunkAt(chunkCoordX + x, chunkCoordZ + z) instanceof EmptyChunk) {
unloadChunk(chunkCoordX + x, chunkCoordZ + z, false);
} else {
unloadChunk(chunkCoordX + x, chunkCoordZ + z);
}
unloadChunk(chunkCoordX + x, chunkCoordZ + z);
}
}
}
@@ -1319,7 +1316,7 @@ public class CraftWorld implements World {
double y = loc.getY();
double z = loc.getZ();
getHandle().makeSound(x, y, z, CraftSound.getSound(sound), volume, pitch);
getHandle().a(null, x, y, z, CraftSound.getSoundEffect(CraftSound.getSound(sound)), SoundCategory.MASTER, volume, pitch); // PAIL: rename
}
public String getGameRuleValue(String rule) {
@@ -1353,6 +1350,80 @@ public class CraftWorld implements World {
return this.worldBorder;
}
@Override
public void spawnParticle(Particle particle, Location location, int count) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count);
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count) {
spawnParticle(particle, x, y, z, count, null);
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, T data) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, data);
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, T data) {
spawnParticle(particle, x, y, z, count, 0, 0, 0);
}
@Override
public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ);
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, null);
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, T data) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, data);
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, T data) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, 1, data);
}
@Override
public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra);
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, null);
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra, data);
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) {
if (data != null && !particle.getDataType().isInstance(data)) {
throw new IllegalArgumentException("data should be " + particle.getDataType() + " got " + data.getClass());
}
getHandle().sendParticles(
null, // Sender
CraftParticle.toNMS(particle), // Particle
true, // Extended range
x, y, z, // Position
count, // Count
offsetX, offsetY, offsetZ, // Random offset
extra, // Speed?
CraftParticle.toData(particle, data)
);
}
public void processChunkGC() {
chunkGCTickCount++;
@@ -1364,7 +1435,7 @@ public class CraftWorld implements World {
return;
}
ChunkProviderServer cps = world.chunkProviderServer;
ChunkProviderServer cps = world.getChunkProviderServer();
for (net.minecraft.server.Chunk chunk : cps.chunks.values()) {
// If in use, skip it
if (isChunkInUse(chunk.locX, chunk.locZ)) {

View File

@@ -0,0 +1,70 @@
package org.bukkit.craftbukkit.attribute;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
public class CraftAttributeInstance implements AttributeInstance {
private final net.minecraft.server.AttributeInstance handle;
private final Attribute attribute;
public CraftAttributeInstance(net.minecraft.server.AttributeInstance handle, Attribute attribute) {
this.handle = handle;
this.attribute = attribute;
}
@Override
public Attribute getAttribute() {
return attribute;
}
@Override
public double getBaseValue() {
return handle.b();
}
@Override
public void setBaseValue(double d) {
handle.setValue(d);
}
@Override
public Collection<AttributeModifier> getModifiers() {
List<AttributeModifier> result = new ArrayList<AttributeModifier>();
for (net.minecraft.server.AttributeModifier nms : handle.c()) {
result.add(convert(nms));
}
return result;
}
@Override
public void addModifier(AttributeModifier modifier) {
Preconditions.checkArgument(modifier != null, "modifier");
handle.b(convert(modifier));
}
@Override
public void removeModifier(AttributeModifier modifier) {
Preconditions.checkArgument(modifier != null, "modifier");
handle.c(convert(modifier));
}
@Override
public double getValue() {
return handle.getValue();
}
private static net.minecraft.server.AttributeModifier convert(AttributeModifier bukkit) {
return new net.minecraft.server.AttributeModifier(bukkit.getUniqueId(), bukkit.getName(), bukkit.getAmount(), bukkit.getOperation().ordinal());
}
private static AttributeModifier convert(net.minecraft.server.AttributeModifier nms) {
return new AttributeModifier(nms.a(), nms.b(), nms.d(), AttributeModifier.Operation.values()[nms.c()]);
}
}

View File

@@ -0,0 +1,37 @@
package org.bukkit.craftbukkit.attribute;
import com.google.common.base.Preconditions;
import net.minecraft.server.AttributeMapBase;
import org.bukkit.attribute.Attributable;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
public class CraftAttributeMap implements Attributable {
private final AttributeMapBase handle;
public CraftAttributeMap(AttributeMapBase handle) {
this.handle = handle;
}
@Override
public AttributeInstance getAttribute(Attribute attribute) {
Preconditions.checkArgument(attribute != null, "attribute");
net.minecraft.server.AttributeInstance nms = handle.a(toMinecraft(attribute.name()));
return (nms == null) ? null : new CraftAttributeInstance(nms, attribute);
}
static String toMinecraft(String bukkit) {
int first = bukkit.indexOf('_');
int second = bukkit.indexOf('_', first + 1);
StringBuilder sb = new StringBuilder(bukkit.toLowerCase());
sb.setCharAt(first, '.');
sb.deleteCharAt(second);
sb.setCharAt(second, bukkit.charAt(second + 1));
return sb.toString();
}
}

View File

@@ -29,8 +29,6 @@ public class CraftBlock implements Block {
private final int x;
private final int y;
private final int z;
private static final Biome BIOME_MAPPING[];
private static final BiomeBase BIOMEBASE_MAPPING[];
public CraftBlock(CraftChunk chunk, int x, int y, int z) {
this.x = x;
@@ -107,6 +105,10 @@ public class CraftBlock implements Block {
world.setTypeAndData(position, blockData.getBlock().fromLegacyData(data), flag);
}
private IBlockData getData0() {
return chunk.getHandle().getBlockData(new BlockPosition(x, y, z));
}
public byte getData() {
IBlockData blockData = chunk.getHandle().getBlockData(new BlockPosition(x, y, z));
return (byte) blockData.getBlock().toLegacyData(blockData);
@@ -136,9 +138,15 @@ public class CraftBlock implements Block {
if (applyPhysics) {
return chunk.getHandle().getWorld().setTypeAndData(position, blockData, 3);
} else {
IBlockData old = chunk.getHandle().getBlockData(position);
boolean success = chunk.getHandle().getWorld().setTypeAndData(position, blockData, 2);
if (success) {
chunk.getHandle().getWorld().notify(position);
chunk.getHandle().getWorld().notify(
position,
old,
blockData,
3
);
}
return success;
}
@@ -151,7 +159,7 @@ public class CraftBlock implements Block {
@Deprecated
@Override
public int getTypeId() {
return CraftMagicNumbers.getId(chunk.getHandle().getType(new BlockPosition(this.x, this.y, this.z)));
return CraftMagicNumbers.getId(chunk.getHandle().getBlockData(new BlockPosition(this.x, this.y, this.z)).getBlock());
}
public byte getLightLevel() {
@@ -302,14 +310,15 @@ public class CraftBlock implements Block {
return null;
}
return BIOME_MAPPING[base.id];
return Biome.valueOf(BiomeBase.REGISTRY_ID.b(base).a().toUpperCase());
}
public static BiomeBase biomeToBiomeBase(Biome bio) {
if (bio == null) {
return null;
}
return BIOMEBASE_MAPPING[bio.ordinal()];
return BiomeBase.REGISTRY_ID.get(new MinecraftKey(bio.name().toLowerCase()));
}
public double getTemperature() {
@@ -383,13 +392,13 @@ public class CraftBlock implements Block {
}
public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.getById(getNMSBlock().getMaterial().getPushReaction());
return PistonMoveReaction.getById(getNMSBlock().getBlockData().getMaterial().getPushReaction().ordinal());
}
private boolean itemCausesDrops(ItemStack item) {
net.minecraft.server.Block block = this.getNMSBlock();
net.minecraft.server.Item itemType = item != null ? net.minecraft.server.Item.getById(item.getTypeId()) : null;
return block != null && (block.getMaterial().isAlwaysDestroyable() || (itemType != null && itemType.canDestroySpecialBlock(block)));
return block != null && (block.getBlockData().getMaterial().isAlwaysDestroyable() || (itemType != null && itemType.canDestroySpecialBlock(block.getBlockData())));
}
public boolean breakNaturally() {
@@ -420,15 +429,15 @@ public class CraftBlock implements Block {
net.minecraft.server.Block block = this.getNMSBlock();
if (block != Blocks.AIR) {
byte data = getData();
IBlockData data = getData0();
// based on nms.Block.dropNaturally
int count = block.getDropCount(0, chunk.getHandle().getWorld().random);
for (int i = 0; i < count; ++i) {
Item item = block.getDropType(block.fromLegacyData(data), chunk.getHandle().getWorld().random, 0);
Item item = block.getDropType(data, chunk.getHandle().getWorld().random, 0);
if (item != null) {
// Skulls are special, their data is based on the tile entity
if (Blocks.SKULL == block) {
net.minecraft.server.ItemStack nmsStack = new net.minecraft.server.ItemStack(item, 1, block.getDropData(chunk.getHandle().getWorld(), new BlockPosition(x, y, z)));
net.minecraft.server.ItemStack nmsStack = new net.minecraft.server.ItemStack(item, 1, block.getDropData(data));
TileEntitySkull tileentityskull = (TileEntitySkull) chunk.getHandle().getWorld().getTileEntity(new BlockPosition(x, y, z));
if (tileentityskull.getSkullType() == 3 && tileentityskull.getGameProfile() != null) {
@@ -442,13 +451,13 @@ public class CraftBlock implements Block {
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 age = (Integer) block.fromLegacyData(data).get(BlockCocoa.AGE);
int age = (Integer) data.get(BlockCocoa.AGE);
int dropAmount = (age >= 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.getDropData(block.fromLegacyData(data))));
drops.add(new ItemStack(org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(item), 1, (short) block.getDropData(data)));
}
}
}
@@ -464,86 +473,6 @@ public class CraftBlock implements Block {
}
}
/* Build biome index based lookup table for BiomeBase to Biome mapping */
static {
BIOME_MAPPING = new Biome[BiomeBase.getBiomes().length];
BIOMEBASE_MAPPING = new BiomeBase[Biome.values().length];
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.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.FROZEN_OCEAN.id] = Biome.FROZEN_OCEAN;
BIOME_MAPPING[BiomeBase.FROZEN_RIVER.id] = Biome.FROZEN_RIVER;
BIOME_MAPPING[BiomeBase.ICE_PLAINS.id] = Biome.ICE_PLAINS;
BIOME_MAPPING[BiomeBase.ICE_MOUNTAINS.id] = Biome.ICE_MOUNTAINS;
BIOME_MAPPING[BiomeBase.MUSHROOM_ISLAND.id] = Biome.MUSHROOM_ISLAND;
BIOME_MAPPING[BiomeBase.MUSHROOM_SHORE.id] = Biome.MUSHROOM_SHORE;
BIOME_MAPPING[BiomeBase.BEACH.id] = Biome.BEACH;
BIOME_MAPPING[BiomeBase.DESERT_HILLS.id] = Biome.DESERT_HILLS;
BIOME_MAPPING[BiomeBase.FOREST_HILLS.id] = Biome.FOREST_HILLS;
BIOME_MAPPING[BiomeBase.TAIGA_HILLS.id] = Biome.TAIGA_HILLS;
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.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.getBiome(i);
}
}
}
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
chunk.getCraftWorld().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue);
}

View File

@@ -9,6 +9,7 @@ import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.material.MaterialData;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
@@ -159,7 +160,12 @@ public class CraftBlockState implements BlockState {
}
block.setTypeIdAndData(getTypeId(), getRawData(), applyPhysics);
world.getHandle().notify(new BlockPosition(x, y, z));
world.getHandle().notify(
new BlockPosition(x, y, z),
CraftMagicNumbers.getBlock(block).fromLegacyData(block.getData()),
CraftMagicNumbers.getBlock(getType()).fromLegacyData(getRawData()),
3
);
return true;
}

View File

@@ -38,15 +38,25 @@ public class CraftBrewingStand extends CraftBlockState implements BrewingStand {
}
public int getBrewingTime() {
return brewingStand.brewTime;
return brewingStand.getProperty(0);
}
public void setBrewingTime(int brewTime) {
brewingStand.brewTime = brewTime;
brewingStand.setProperty(0, brewTime);
}
@Override
public TileEntityBrewingStand getTileEntity() {
return brewingStand;
}
@Override
public int getFuelLevel() {
return brewingStand.getProperty(1);
}
@Override
public void setFuelLevel(int level) {
brewingStand.setProperty(1, level);
}
}

View File

@@ -6,7 +6,6 @@ import org.bukkit.Material;
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 {
@@ -23,20 +22,10 @@ public class CraftCreatureSpawner extends CraftBlockState implements CreatureSpa
spawner = te;
}
@Deprecated
public CreatureType getCreatureType() {
return CreatureType.fromName(spawner.getSpawner().getMobName());
}
public EntityType getSpawnedType() {
return EntityType.fromName(spawner.getSpawner().getMobName());
}
@Deprecated
public void setCreatureType(CreatureType creatureType) {
spawner.getSpawner().setMobName(creatureType.getName());
}
public void setSpawnedType(EntityType entityType) {
if (entityType == null || entityType.getName() == null) {
throw new IllegalArgumentException("Can't spawn EntityType " + entityType + " from mobspawners!");

View File

@@ -38,19 +38,19 @@ public class CraftFurnace extends CraftBlockState implements Furnace {
}
public short getBurnTime() {
return (short) furnace.burnTime;
return (short) furnace.getProperty(0);
}
public void setBurnTime(short burnTime) {
furnace.burnTime = burnTime;
furnace.setProperty(0, burnTime);
}
public short getCookTime() {
return (short) furnace.cookTime;
return (short) furnace.getProperty(2);
}
public void setCookTime(short cookTime) {
furnace.cookTime = cookTime;
furnace.setProperty(2, cookTime);
}
@Override

View File

@@ -0,0 +1,165 @@
package org.bukkit.craftbukkit.boss;
import com.google.common.collect.ImmutableList;
import net.minecraft.server.BossBattle;
import net.minecraft.server.BossBattleServer;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.PacketPlayOutBoss;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarFlag;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.entity.Player;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
public class CraftBossBar implements BossBar {
private final BossBattleServer handle;
private final Set<BarFlag> flags;
private BarColor color;
private BarStyle style;
public CraftBossBar(String title, BarColor color, BarStyle style, BarFlag... flags) {
this.flags = flags.length > 0 ? EnumSet.of(flags[0], flags) : EnumSet.noneOf(BarFlag.class);
this.color = color;
this.style = style;
handle = new BossBattleServer(
CraftChatMessage.fromString(title, true)[0],
convertColor(color),
convertStyle(style)
);
updateFlags();
}
private BossBattle.BarColor convertColor(BarColor color) {
BossBattle.BarColor nmsColor = BossBattle.BarColor.valueOf(color.name());
return (nmsColor == null) ? BossBattle.BarColor.WHITE : nmsColor;
}
private BossBattle.BarStyle convertStyle(BarStyle style) {
switch (style) {
default:
case SOLID:
return BossBattle.BarStyle.PROGRESS;
case SEGMENTED_6:
return BossBattle.BarStyle.NOTCHED_6;
case SEGMENTED_10:
return BossBattle.BarStyle.NOTCHED_10;
case SEGMENTED_12:
return BossBattle.BarStyle.NOTCHED_12;
case SEGMENTED_20:
return BossBattle.BarStyle.NOTCHED_20;
}
}
private void updateFlags() {
handle.a(hasFlag(BarFlag.DARKEN_SKY));
handle.b(hasFlag(BarFlag.PLAY_BOSS_MUSIC));
handle.c(hasFlag(BarFlag.CREATE_FOG));
}
@Override
public String getTitle() {
return CraftChatMessage.fromComponent(handle.e());
}
@Override
public void setTitle(String title) {
handle.title = CraftChatMessage.fromString(title, true)[0];
handle.sendUpdate(PacketPlayOutBoss.Action.UPDATE_NAME);
}
@Override
public BarColor getColor() {
return color;
}
@Override
public void setColor(BarColor color) {
this.color = color;
handle.color = convertColor(color);
handle.sendUpdate(PacketPlayOutBoss.Action.UPDATE_STYLE);
}
@Override
public BarStyle getStyle() {
return style;
}
@Override
public void setStyle(BarStyle style) {
this.style = style;
handle.style = convertStyle(style);
handle.sendUpdate(PacketPlayOutBoss.Action.UPDATE_STYLE);
}
@Override
public void addFlag(BarFlag flag) {
flags.remove(flag);
updateFlags();
}
@Override
public void removeFlag(BarFlag flag) {
flags.add(flag);
updateFlags();
}
@Override
public boolean hasFlag(BarFlag flag) {
return flags.contains(flag);
}
@Override
public void setProgress(double progress) {
handle.setProgress((float) progress);
}
@Override
public double getProgress() {
return handle.getProgress();
}
@Override
public void addPlayer(Player player) {
handle.addPlayer(((CraftPlayer) player).getHandle());
}
@Override
public void removePlayer(Player player) {
handle.removePlayer(((CraftPlayer) player).getHandle());
}
@Override
public List<Player> getPlayers() {
ImmutableList.Builder<Player> players = ImmutableList.builder();
for (EntityPlayer p : handle.getPlayers()) {
players.add(p.getBukkitEntity());
}
return players.build();
}
@Override
public void show() {
handle.setVisible(true);
}
@Override
public void hide() {
handle.setVisible(false);
}
@Override
public void removeAll() {
for (Player player : getPlayers()) {
removePlayer(player);
}
}
}

View File

@@ -10,10 +10,6 @@ import org.bukkit.craftbukkit.util.AsynchronousExecutor;
import org.bukkit.craftbukkit.util.LongHash;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.Entity;
import net.minecraft.server.EntitySlice;
class ChunkIOProvider implements AsynchronousExecutor.CallBackProvider<QueuedChunk, Chunk, Runnable, RuntimeException> {
private final AtomicInteger threadNumber = new AtomicInteger(1);
@@ -48,8 +44,8 @@ class ChunkIOProvider implements AsynchronousExecutor.CallBackProvider<QueuedChu
queuedChunk.provider.chunks.put(LongHash.toLong(queuedChunk.x, queuedChunk.z), chunk);
chunk.addEntities();
if (queuedChunk.provider.chunkProvider != null) {
queuedChunk.provider.chunkProvider.recreateStructures(chunk, queuedChunk.x, queuedChunk.z);
if (queuedChunk.provider.chunkGenerator != null) {
queuedChunk.provider.chunkGenerator.recreateStructures(chunk, queuedChunk.x, queuedChunk.z);
}
Server server = queuedChunk.provider.world.getServer();
@@ -72,7 +68,7 @@ class ChunkIOProvider implements AsynchronousExecutor.CallBackProvider<QueuedChu
}
}
chunk.loadNearby(queuedChunk.provider, queuedChunk.provider, queuedChunk.x, queuedChunk.z);
chunk.loadNearby(queuedChunk.provider, queuedChunk.provider.chunkGenerator);
}
public void callStage3(QueuedChunk queuedChunk, Chunk chunk, Runnable runnable) throws RuntimeException {

View File

@@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.command;
import net.minecraft.server.ICommandListener;
import net.minecraft.server.CommandBlockListenerAbstract;
import net.minecraft.server.IChatBaseComponent;
import org.bukkit.block.Block;
@@ -12,20 +11,20 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
* Represents input from a command block
*/
public class CraftBlockCommandSender extends ServerCommandSender implements BlockCommandSender {
private final CommandBlockListenerAbstract commandBlock;
private final ICommandListener block;
public CraftBlockCommandSender(CommandBlockListenerAbstract commandBlockListenerAbstract) {
public CraftBlockCommandSender(ICommandListener commandBlockListenerAbstract) {
super();
this.commandBlock = commandBlockListenerAbstract;
this.block = commandBlockListenerAbstract;
}
public Block getBlock() {
return commandBlock.getWorld().getWorld().getBlockAt(commandBlock.getChunkCoordinates().getX(), commandBlock.getChunkCoordinates().getY(), commandBlock.getChunkCoordinates().getZ());
return block.getWorld().getWorld().getBlockAt(block.getChunkCoordinates().getX(), block.getChunkCoordinates().getY(), block.getChunkCoordinates().getZ());
}
public void sendMessage(String message) {
for (IChatBaseComponent component : CraftChatMessage.fromString(message)) {
commandBlock.sendMessage(component);
block.sendMessage(component);
}
}
@@ -36,7 +35,7 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
}
public String getName() {
return commandBlock.getName();
return block.getName();
}
public boolean isOp() {
@@ -48,6 +47,6 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
}
public ICommandListener getTileEntity() {
return commandBlock;
return block;
}
}

View File

@@ -5,13 +5,16 @@ import net.minecraft.server.RemoteControlCommandListener;
import org.bukkit.command.RemoteConsoleCommandSender;
public class CraftRemoteConsoleCommandSender extends ServerCommandSender implements RemoteConsoleCommandSender {
public CraftRemoteConsoleCommandSender() {
super();
private final RemoteControlCommandListener listener;
public CraftRemoteConsoleCommandSender(RemoteControlCommandListener listener) {
this.listener = listener;
}
@Override
public void sendMessage(String message) {
RemoteControlCommandListener.getInstance().sendMessage(new ChatComponentText(message + "\n")); // Send a newline after each message, to preserve formatting.
listener.sendMessage(new ChatComponentText(message + "\n")); // Send a newline after each message, to preserve formatting.
}
@Override

View File

@@ -49,7 +49,7 @@ public final class VanillaCommandWrapper extends VanillaCommand {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return (List<String>) vanillaCommand.tabComplete(getListener(sender), args, new BlockPosition(0, 0, 0));
return (List<String>) vanillaCommand.tabComplete(MinecraftServer.getServer(), getListener(sender), args, new BlockPosition(0, 0, 0));
}
public static CommandSender lastSender = null; // Nasty :(
@@ -75,7 +75,7 @@ public final class VanillaCommandWrapper extends VanillaCommand {
}
try {
if (vanillaCommand.canUse(icommandlistener)) {
if (vanillaCommand.canUse(server, icommandlistener)) {
if (i > -1) {
List<Entity> list = ((List<Entity>)PlayerSelector.getPlayers(icommandlistener, as[i], Entity.class));
String s2 = as[i];
@@ -90,14 +90,14 @@ public final class VanillaCommandWrapper extends VanillaCommand {
lastSender = bSender;
try {
as[i] = entity.getUniqueID().toString();
vanillaCommand.execute(icommandlistener, as);
vanillaCommand.execute(server, icommandlistener, as);
j++;
} catch (ExceptionUsage exceptionusage) {
ChatMessage chatmessage = new ChatMessage("commands.generic.usage", new Object[] { new ChatMessage(exceptionusage.getMessage(), exceptionusage.getArgs())});
chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
icommandlistener.sendMessage(chatmessage);
} catch (CommandException commandexception) {
CommandAbstract.a(icommandlistener, vanillaCommand, 1, commandexception.getMessage(), commandexception.getArgs());
CommandAbstract.a(icommandlistener, vanillaCommand, 0, commandexception.getMessage(), commandexception.getArgs());
} finally {
lastSender = oldSender;
}
@@ -105,7 +105,7 @@ public final class VanillaCommandWrapper extends VanillaCommand {
as[i] = s2;
} else {
icommandlistener.a(CommandObjectiveExecutor.EnumCommandResult.AFFECTED_ENTITIES, 1);
vanillaCommand.execute(icommandlistener, as);
vanillaCommand.execute(server, icommandlistener, as);
j++;
}
} else {
@@ -118,7 +118,7 @@ public final class VanillaCommandWrapper extends VanillaCommand {
chatmessage1.getChatModifier().setColor(EnumChatFormat.RED);
icommandlistener.sendMessage(chatmessage1);
} catch (CommandException commandexception) {
CommandAbstract.a(icommandlistener, vanillaCommand, 1, commandexception.getMessage(), commandexception.getArgs());
CommandAbstract.a(icommandlistener, vanillaCommand, 0, commandexception.getMessage(), commandexception.getArgs());
} catch (Throwable throwable) {
ChatMessage chatmessage3 = new ChatMessage("commands.generic.exception", new Object[0]);
chatmessage3.getChatModifier().setColor(EnumChatFormat.RED);
@@ -149,7 +149,7 @@ public final class VanillaCommandWrapper extends VanillaCommand {
return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock();
}
if (sender instanceof RemoteConsoleCommandSender) {
return RemoteControlCommandListener.getInstance();
return ((DedicatedServer)MinecraftServer.getServer()).remoteControlCommandListener;
}
if (sender instanceof ConsoleCommandSender) {
return ((CraftServer) sender.getServer()).getServer();

View File

@@ -10,7 +10,7 @@ public class CraftEnchantment extends Enchantment {
private final net.minecraft.server.Enchantment target;
public CraftEnchantment(net.minecraft.server.Enchantment target) {
super(target.id);
super(net.minecraft.server.Enchantment.getId(target));
this.target = target;
}
@@ -26,7 +26,7 @@ public class CraftEnchantment extends Enchantment {
@Override
public EnchantmentTarget getItemTarget() {
switch (target.slot) {
switch (target.itemTarget) {
case ALL:
return EnchantmentTarget.ALL;
case ARMOR:
@@ -37,7 +37,7 @@ public class CraftEnchantment extends Enchantment {
return EnchantmentTarget.ARMOR_HEAD;
case ARMOR_LEGS:
return EnchantmentTarget.ARMOR_LEGS;
case ARMOR_TORSO:
case ARMOR_CHEST:
return EnchantmentTarget.ARMOR_TORSO;
case DIGGER:
return EnchantmentTarget.TOOL;
@@ -59,7 +59,7 @@ public class CraftEnchantment extends Enchantment {
@Override
public String getName() {
switch (target.id) {
switch (getId()) {
case 0:
return "PROTECTION_ENVIRONMENTAL";
case 1:
@@ -111,7 +111,7 @@ public class CraftEnchantment extends Enchantment {
case 62:
return "LURE";
default:
return "UNKNOWN_ENCHANT_" + target.id;
return "UNKNOWN_ENCHANT_" + getId();
}
}
@@ -138,4 +138,8 @@ public class CraftEnchantment extends Enchantment {
CraftEnchantment ench = (CraftEnchantment) other;
return !target.a(ench.target);
}
public net.minecraft.server.Enchantment getHandle() {
return target;
}
}

View File

@@ -0,0 +1,138 @@
package org.bukkit.craftbukkit.entity;
import java.util.List;
import net.minecraft.server.EntityAreaEffectCloud;
import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.craftbukkit.CraftParticle;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionEffect;
public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud {
public CraftAreaEffectCloud(CraftServer server, EntityAreaEffectCloud entity) {
super(server, entity);
}
@Override
public EntityAreaEffectCloud getHandle() {
return (EntityAreaEffectCloud) super.getHandle();
}
@Override
public EntityType getType() {
return EntityType.AREA_EFFECT_CLOUD;
}
@Override
public int getDuration() {
return getHandle().getDuration();
}
@Override
public void setDuration(int duration) {
getHandle().setDuration(duration);
}
@Override
public int getWaitTime() {
return getHandle().waitTime;
}
@Override
public void setWaitTime(int waitTime) {
getHandle().setWaitTime(waitTime);
}
@Override
public int getReapplicationDelay() {
return getHandle().reapplicationDelay;
}
@Override
public void setReapplicationDelay(int delay) {
getHandle().reapplicationDelay = delay;
}
@Override
public int getDurationOnUse() {
return getHandle().durationOnUse;
}
@Override
public void setDurationOnUse(int duration) {
getHandle().durationOnUse = duration;
}
@Override
public float getRadius() {
return getHandle().getRadius();
}
@Override
public void setRadius(float radius) {
getHandle().setRadius(radius);
}
@Override
public float getRadiusOnUse() {
return getHandle().radiusOnUse;
}
@Override
public void setRadiusOnUse(float radius) {
getHandle().setRadiusOnUse(radius);
}
@Override
public float getRadiusPerTick() {
return getHandle().radiusPerTick;
}
@Override
public void setRadiusPerTick(float radius) {
getHandle().setRadiusPerTick(radius);
}
@Override
public Particle getParticle() {
return CraftParticle.toBukkit(getHandle().getParticle());
}
@Override
public void setParticle(Particle particle) {
getHandle().setParticle(CraftParticle.toNMS(particle));
}
@Override
public List<PotionEffect> getEffects() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void addEffect(PotionEffect effect) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void removeEffect(PotionEffect effect) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setEffects(List<PotionEffect> effects) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Color getColor() {
return Color.fromRGB(getHandle().getColor());
}
@Override
public void setColor(Color color) {
getHandle().setColor(color.asRGB());
}
}

View File

@@ -157,6 +157,7 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
@Override
public void setGravity(boolean gravity) {
getHandle().setGravity(!gravity);
getHandle().noclip = !gravity;
}
@Override
@@ -207,13 +208,11 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
@Override
public boolean isMarker() {
// PAIL
return getHandle().s();
return getHandle().isMarker();
}
@Override
public void setMarker(boolean marker) {
// PAIL
getHandle().n(marker);
getHandle().setMarker(marker);
}
}

View File

@@ -0,0 +1,17 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityDragonFireball;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.DragonFireball;
import org.bukkit.entity.EntityType;
public class CraftDragonFireball extends CraftFireball implements DragonFireball {
public CraftDragonFireball(CraftServer server, EntityDragonFireball entity) {
super(server, entity);
}
@Override
public EntityType getType() {
return EntityType.DRAGON_FIREBALL;
}
}

View File

@@ -1,8 +1,6 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -39,7 +37,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
});
protected final CraftServer server;
protected Entity entity;
private EntityDamageEvent lastDamageEvent;
@@ -108,6 +106,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
else if (entity instanceof EntityGolem) {
if (entity instanceof EntitySnowman) { return new CraftSnowman(server, (EntitySnowman) entity); }
else if (entity instanceof EntityIronGolem) { return new CraftIronGolem(server, (EntityIronGolem) entity); }
else if (entity instanceof EntityShulker) { return new CraftShulker(server, (EntityShulker) entity); }
}
else if (entity instanceof EntityVillager) { return new CraftVillager(server, (EntityVillager) entity); }
else { return new CraftCreature(server, (EntityCreature) entity); }
@@ -153,6 +152,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
if (entity instanceof EntitySmallFireball) { return new CraftSmallFireball(server, (EntitySmallFireball) entity); }
else if (entity instanceof EntityLargeFireball) { return new CraftLargeFireball(server, (EntityLargeFireball) entity); }
else if (entity instanceof EntityWitherSkull) { return new CraftWitherSkull(server, (EntityWitherSkull) entity); }
else if (entity instanceof EntityDragonFireball) { return new CraftDragonFireball(server, (EntityDragonFireball) entity); }
else { return new CraftFireball(server, (EntityFireball) entity); }
}
else if (entity instanceof EntityEnderSignal) { return new CraftEnderSignal(server, (EntityEnderSignal) entity); }
@@ -179,6 +179,8 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
else if (entity instanceof EntityTNTPrimed) { return new CraftTNTPrimed(server, (EntityTNTPrimed) entity); }
else if (entity instanceof EntityFireworks) { return new CraftFirework(server, (EntityFireworks) entity); }
else if (entity instanceof EntityShulkerBullet) { return new CraftShulkerBullet(server, (EntityShulkerBullet) entity); }
else if (entity instanceof EntityAreaEffectCloud) { return new CraftAreaEffectCloud(server, (EntityAreaEffectCloud) entity); }
throw new AssertionError("Unknown entity " + (entity == null ? null : entity.getClass()));
}
@@ -227,12 +229,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
public boolean teleport(Location location, TeleportCause cause) {
if (entity.passenger != null || entity.dead) {
if (entity.isVehicle() || entity.dead) {
return false;
}
// If this entity is riding another entity, we must dismount before teleporting.
entity.mount(null);
entity.stopRiding();
entity.world = ((CraftWorld) location.getWorld()).getHandle();
entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
@@ -299,13 +301,14 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
public org.bukkit.entity.Entity getPassenger() {
return isEmpty() ? null : getHandle().passenger.getBukkitEntity();
return isEmpty() ? null : getHandle().passengers.get(0).getBukkitEntity();
}
public boolean setPassenger(org.bukkit.entity.Entity passenger) {
Preconditions.checkArgument(!this.equals(passenger), "Entity cannot ride itself.");
if (passenger instanceof CraftEntity) {
((CraftEntity) passenger).getHandle().mount(getHandle());
eject();
((CraftEntity) passenger).getHandle().startRiding(getHandle());
return true;
} else {
return false;
@@ -313,15 +316,15 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
public boolean isEmpty() {
return getHandle().passenger == null;
return !getHandle().isVehicle();
}
public boolean eject() {
if (getHandle().passenger == null) {
if (isEmpty()) {
return false;
}
getHandle().passenger.mount(null);
getPassenger().leaveVehicle();
return true;
}
@@ -409,24 +412,24 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
public boolean isInsideVehicle() {
return getHandle().vehicle != null;
return getHandle().isPassenger();
}
public boolean leaveVehicle() {
if (getHandle().vehicle == null) {
if (!isInsideVehicle()) {
return false;
}
getHandle().mount(null);
getHandle().stopRiding();
return true;
}
public org.bukkit.entity.Entity getVehicle() {
if (getHandle().vehicle == null) {
if (!isInsideVehicle()) {
return null;
}
return getHandle().vehicle.getBukkitEntity();
return getHandle().getVehicle().getBukkitEntity();
}
@Override
@@ -538,4 +541,18 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public void setOp(boolean value) {
perm.setOp(value);
}
@Override
public void setGlowing(boolean flag) {
getHandle().glowing = flag;
Entity e = getHandle();
if (e.getFlag(6) != flag) {
e.setFlag(6, flag);
}
}
@Override
public boolean isGlowing() {
return getHandle().glowing;
}
}

View File

@@ -22,11 +22,11 @@ public class CraftFirework extends CraftEntity implements Firework {
public CraftFirework(CraftServer server, EntityFireworks entity) {
super(server, entity);
ItemStack item = getHandle().getDataWatcher().getItemStack(FIREWORK_ITEM_INDEX);
ItemStack item = getHandle().getDataWatcher().get(EntityFireworks.FIREWORK_ITEM).orNull();
if (item == null) {
item = new ItemStack(Items.FIREWORKS);
getHandle().getDataWatcher().watch(FIREWORK_ITEM_INDEX, item);
getHandle().getDataWatcher().register(EntityFireworks.FIREWORK_ITEM, item);
}
this.item = CraftItemStack.asCraftMirror(item);
@@ -64,7 +64,7 @@ public class CraftFirework extends CraftEntity implements Firework {
// Copied from EntityFireworks constructor, update firework lifetime/power
getHandle().expectedLifespan = 10 * (1 + meta.getPower()) + random.nextInt(6) + random.nextInt(7);
getHandle().getDataWatcher().update(FIREWORK_ITEM_INDEX);
getHandle().getDataWatcher().markDirty(EntityFireworks.FIREWORK_ITEM);
}
@Override

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityHorse;
import net.minecraft.server.EnumHorseType;
import org.apache.commons.lang.Validate;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftInventoryHorse;
@@ -23,12 +24,12 @@ public class CraftHorse extends CraftAnimals implements Horse {
}
public Variant getVariant() {
return Variant.values()[getHandle().getType()];
return Variant.values()[getHandle().getType().ordinal()];
}
public void setVariant(Variant variant) {
Validate.notNull(variant, "Variant cannot be null");
getHandle().setType(variant.ordinal());
getHandle().setType(EnumHorseType.values()[variant.ordinal()]);
}
public Color getColor() {
@@ -89,7 +90,7 @@ public class CraftHorse extends CraftAnimals implements Horse {
@Override
public boolean isTamed() {
return getHandle().isTame();
return getHandle().isTamed();
}
@Override
@@ -116,19 +117,11 @@ public class CraftHorse extends CraftAnimals implements Horse {
}
public UUID getOwnerUUID() {
try {
return UUID.fromString(getHandle().getOwnerUUID());
} catch (IllegalArgumentException ex) {
return null;
}
return getHandle().getOwnerUUID();
}
public void setOwnerUUID(UUID uuid) {
if (uuid == null) {
getHandle().setOwnerUUID("");
} else {
getHandle().setOwnerUUID(uuid.toString());
}
getHandle().setOwnerUUID(uuid);
}
public HorseInventory getInventory() {

View File

@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import java.util.Set;
import net.minecraft.server.*;
@@ -21,6 +22,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.Permission;
@@ -347,6 +349,23 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
player.activeContainer.addSlotListener(player);
}
@Override
public InventoryView openMerchant(Villager villager, boolean force) {
Preconditions.checkNotNull(villager, "villager cannot be null");
if (!force && villager.isTrading()) {
return null;
} else if (villager.isTrading()) {
// we're not supposed to have multiple people using the same villager, so we have to close it.
villager.getTrader().closeInventory();
}
EntityVillager ev = ((CraftVillager) villager).getHandle();
ev.setTradingPlayer(this.getHandle());
this.getHandle().openTrade(ev);
return this.getHandle().activeContainer.getBukkitView();
}
public void closeInventory() {
getHandle().closeInventory();
}

View File

@@ -9,9 +9,8 @@ import java.util.Set;
import net.minecraft.server.DamageSource;
import net.minecraft.server.EntityArmorStand;
import net.minecraft.server.EntityArrow;
import net.minecraft.server.EntityDragonFireball;
import net.minecraft.server.EntityEgg;
import net.minecraft.server.EntityEnderDragon;
import net.minecraft.server.EntityEnderPearl;
import net.minecraft.server.EntityFishingHook;
import net.minecraft.server.EntityHuman;
@@ -24,6 +23,7 @@ import net.minecraft.server.EntityPotion;
import net.minecraft.server.EntitySmallFireball;
import net.minecraft.server.EntitySnowball;
import net.minecraft.server.EntityThrownExpBottle;
import net.minecraft.server.EntityTippedArrow;
import net.minecraft.server.EntityWither;
import net.minecraft.server.EntityWitherSkull;
import net.minecraft.server.GenericAttributes;
@@ -33,12 +33,15 @@ import net.minecraft.server.MobEffectList;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.inventory.CraftEntityEquipment;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.DragonFireball;
import org.bukkit.entity.Egg;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Entity;
@@ -108,16 +111,6 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
setMaxHealth(getHandle().getMaxHealth());
}
@Deprecated
public Egg throwEgg() {
return launchProjectile(Egg.class);
}
@Deprecated
public Snowball throwSnowball() {
return launchProjectile(Snowball.class);
}
public double getEyeHeight() {
return getHandle().getHeadHeight();
}
@@ -204,11 +197,6 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return getLineOfSight(transparent, maxDistance, 2);
}
@Deprecated
public Arrow shootArrow() {
return launchProjectile(Arrow.class);
}
public int getRemainingAir() {
return getHandle().getAirTicks();
}
@@ -300,7 +288,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
}
removePotionEffect(effect.getType());
}
getHandle().addEffect(new MobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()));
getHandle().addEffect(new MobEffect(MobEffectList.fromId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()));
return true;
}
@@ -313,20 +301,17 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
}
public boolean hasPotionEffect(PotionEffectType type) {
return getHandle().hasEffect(MobEffectList.byId[type.getId()]);
return getHandle().hasEffect(MobEffectList.fromId(type.getId()));
}
public void removePotionEffect(PotionEffectType type) {
getHandle().removeEffect(type.getId());
getHandle().removeEffect(MobEffectList.fromId(type.getId()));
}
public Collection<PotionEffect> getActivePotionEffects() {
List<PotionEffect> effects = new ArrayList<PotionEffect>();
for (Object raw : getHandle().effects.values()) {
if (!(raw instanceof MobEffect))
continue;
MobEffect handle = (MobEffect) raw;
effects.add(new PotionEffect(PotionEffectType.getById(handle.getEffectId()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isShowParticles()));
for (MobEffect handle : getHandle().effects.values()) {
effects.add(new PotionEffect(PotionEffectType.getById(MobEffectList.getId(handle.getMobEffect())), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isShowParticles()));
}
return effects;
}
@@ -347,7 +332,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EntityEnderPearl(world, getHandle());
} else if (Arrow.class.isAssignableFrom(projectile)) {
launch = new EntityArrow(world, getHandle(), 1);
launch = new EntityTippedArrow(world, getHandle());
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
launch = new EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
@@ -362,6 +347,8 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
launch = new EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = new EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else if (DragonFireball.class.isAssignableFrom(projectile)) {
launch = new EntityDragonFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else {
launch = new EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
}
@@ -500,4 +487,9 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
public void _INVALID_setMaxHealth(int health) {
setMaxHealth(health);
}
@Override
public AttributeInstance getAttribute(Attribute attribute) {
return getHandle().craftAttributes.getAttribute(attribute);
}
}

View File

@@ -91,7 +91,7 @@ public abstract class CraftMinecart extends CraftVehicle implements Minecart {
}
public void setDisplayBlockOffset(int offset) {
getHandle().SetDisplayBlockOffset(offset);
getHandle().setDisplayBlockOffset(offset);
}
public int getDisplayBlockOffset() {

View File

@@ -36,6 +36,7 @@ import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
import org.bukkit.craftbukkit.CraftParticle;
import org.bukkit.craftbukkit.block.CraftSign;
import org.bukkit.craftbukkit.conversations.ConversationTracker;
import org.bukkit.craftbukkit.CraftEffect;
@@ -264,7 +265,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
float f = (float) Math.pow(2.0D, (note - 12.0D) / 12.0D);
getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect("note."+instrumentName, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f));
getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect("note." + instrumentName), SoundCategory.MUSIC, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f));
}
@Override
@@ -290,7 +291,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
break;
}
float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D);
getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect("note."+instrumentName, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f));
getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect("note." + instrumentName), SoundCategory.MUSIC, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f));
}
@Override
@@ -309,7 +310,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
double y = loc.getBlockY() + 0.5;
double z = loc.getBlockZ() + 0.5;
PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(sound, x, y, z, volume, pitch);
PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect(sound), SoundCategory.MASTER, x, y, z, volume, pitch);
getHandle().playerConnection.sendPacket(packet);
}
@@ -415,7 +416,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
}
PacketPlayOutMap packet = new PacketPlayOutMap(map.getId(), map.getScale().getValue(), icons, data.buffer, 0, 0, 0, 0);
PacketPlayOutMap packet = new PacketPlayOutMap(map.getId(), map.getScale().getValue(), true, icons, data.buffer, 0, 0, 0, 0);
getHandle().playerConnection.sendPacket(packet);
}
@@ -431,7 +432,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return false;
}
if (entity.passenger != null) {
if (entity.isVehicle()) {
return false;
}
@@ -449,7 +450,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
// If this player is riding another entity, we must dismount before teleporting.
entity.mount(null);
entity.stopRiding();
// Update the From Location
from = event.getFrom();
@@ -1288,7 +1289,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
injectScaledMaxHealth(set, true);
getHandle().getDataWatcher().watch(6, (float) getScaledHealth());
getHandle().getDataWatcher().set(EntityLiving.HEALTH, (float) getScaledHealth());
getHandle().playerConnection.sendPacket(new PacketPlayOutUpdateHealth(getScaledHealth(), getHandle().getFoodData().getFoodLevel(), getHandle().getFoodData().getSaturationLevel()));
getHandle().playerConnection.sendPacket(new PacketPlayOutUpdateAttributes(getHandle().getId(), set));
@@ -1312,7 +1313,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public org.bukkit.entity.Entity getSpectatorTarget() {
Entity followed = getHandle().C(); // PAIL
Entity followed = getHandle().getSpecatorTarget();
return followed == getHandle() ? null : followed.getBukkitEntity();
}
@@ -1340,4 +1341,69 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
PacketPlayOutTitle packetReset = new PacketPlayOutTitle(EnumTitleAction.RESET, null);
getHandle().playerConnection.sendPacket(packetReset);
}
@Override
public void spawnParticle(Particle particle, Location location, int count) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count);
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count) {
spawnParticle(particle, x, y, z, count, null);
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, T data) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, data);
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, T data) {
spawnParticle(particle, x, y, z, count, 0, 0, 0);
}
@Override
public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ);
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, null);
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, T data) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, data);
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, T data) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, 1, data);
}
@Override
public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra);
}
@Override
public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, null);
}
@Override
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) {
spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra, data);
}
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) {
if (data != null && !particle.getDataType().isInstance(data)) {
throw new IllegalArgumentException("data should be " + particle.getDataType() + " got " + data.getClass());
}
PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(CraftParticle.toNMS(particle), true, (float) x, (float) y, (float) z, (float) offsetX, (float) offsetY, (float) offsetZ, (float) extra, count, CraftParticle.toData(particle, data));
getHandle().playerConnection.sendPacket(packetplayoutworldparticles);
}
}

View File

@@ -0,0 +1,24 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityGolem;
import net.minecraft.server.EntityShulker;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Shulker;
public class CraftShulker extends CraftGolem implements Shulker {
public CraftShulker(CraftServer server, EntityShulker entity) {
super(server, entity);
}
@Override
public EntityType getType() {
return EntityType.SHULKER;
}
@Override
public EntityShulker getHandle() {
return (EntityShulker) entity;
}
}

View File

@@ -0,0 +1,51 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityShulkerBullet;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.ShulkerBullet;
import org.bukkit.projectiles.ProjectileSource;
public class CraftShulkerBullet extends CraftEntity implements ShulkerBullet {
public CraftShulkerBullet(CraftServer server, EntityShulkerBullet entity) {
super(server, entity);
}
@Override
public ProjectileSource getShooter() {
return getHandle().projectileSource;
}
@Override
public void setShooter(ProjectileSource shooter) {
if (shooter instanceof LivingEntity) {
getHandle().setShooter(((CraftLivingEntity) shooter).getHandle());
} else {
getHandle().setShooter(null);
}
getHandle().projectileSource = shooter;
}
@Override
public org.bukkit.entity.Entity getTarget() {
return getHandle().getTarget() != null ? getHandle().getTarget().getBukkitEntity() : null;
}
@Override
public void setTarget(org.bukkit.entity.Entity target) {
getHandle().setTarget(target == null ? null : ((CraftEntity) target).getHandle());
}
@Override
public EntityType getType() {
return EntityType.SHULKER_BULLET;
}
@Override
public EntityShulkerBullet getHandle() {
return (EntityShulkerBullet) entity;
}
}

View File

@@ -31,11 +31,11 @@ public class CraftTNTPrimed extends CraftEntity implements TNTPrimed {
}
public int getFuseTicks() {
return getHandle().fuseTicks;
return getHandle().getFuseTicks();
}
public void setFuseTicks(int fuseTicks) {
getHandle().fuseTicks = fuseTicks;
getHandle().setFuseTicks(fuseTicks);
}
@Override

View File

@@ -20,18 +20,14 @@ public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creat
public UUID getOwnerUUID() {
try {
return UUID.fromString(getHandle().getOwnerUUID());
return getHandle().getOwnerUUID();
} catch (IllegalArgumentException ex) {
return null;
}
}
public void setOwnerUUID(UUID uuid) {
if (uuid == null) {
getHandle().setOwnerUUID("");
} else {
getHandle().setOwnerUUID(uuid.toString());
}
getHandle().setOwnerUUID(uuid);
}
public AnimalTamer getOwner() {

View File

@@ -22,14 +22,11 @@ public class CraftThrownPotion extends CraftProjectile implements ThrownPotion {
// TODO: This one does not handle custom NBT potion effects does it?
// In that case this method could be said to be misleading or incorrect
public Collection<PotionEffect> getEffects() {
return Potion.getBrewer().getEffectsFromDamage(getHandle().getPotionValue());
return Potion.getBrewer().getEffectsFromDamage(getHandle().getItem().getData());
}
public ItemStack getItem() {
// We run this method once since it will set the item stack if there is none.
getHandle().getPotionValue();
return CraftItemStack.asBukkitCopy(getHandle().item);
return CraftItemStack.asBukkitCopy(getHandle().getItem());
}
public void setItem(ItemStack item) {
@@ -39,7 +36,7 @@ public class CraftThrownPotion extends CraftProjectile implements ThrownPotion {
// The ItemStack must be a potion.
Validate.isTrue(item.getType() == Material.POTION, "ItemStack must be a potion. This item stack was " + item.getType() + ".");
getHandle().item = CraftItemStack.asNMSCopy(item);
getHandle().setItem(CraftItemStack.asNMSCopy(item));
}
@Override

View File

@@ -1,15 +1,25 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityVillager;
import net.minecraft.server.MerchantRecipeList;
import org.apache.commons.lang.Validate;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.MerchantRecipe;
public class CraftVillager extends CraftAgeable implements Villager, InventoryHolder {
public CraftVillager(CraftServer server, EntityVillager entity) {
super(server, entity);
}
@@ -41,4 +51,59 @@ public class CraftVillager extends CraftAgeable implements Villager, InventoryHo
public Inventory getInventory() {
return new CraftInventory(getHandle().inventory);
}
@Override
public List<MerchantRecipe> getRecipes() {
return Collections.unmodifiableList(Lists.transform(getHandle().getOffers(null), new Function<net.minecraft.server.MerchantRecipe, MerchantRecipe>() {
@Override
public MerchantRecipe apply(net.minecraft.server.MerchantRecipe recipe) {
return recipe.asBukkit();
}
}));
}
@Override
public void setRecipes(List<MerchantRecipe> list) {
MerchantRecipeList recipes = getHandle().getOffers(null);
recipes.clear();
for (MerchantRecipe m : list) {
recipes.add(CraftMerchantRecipe.fromBukkit(m).toMinecraft());
}
}
@Override
public MerchantRecipe getRecipe(int i) {
return getHandle().getOffers(null).get(i).asBukkit();
}
@Override
public void setRecipe(int i, MerchantRecipe merchantRecipe) {
getHandle().getOffers(null).set(i, CraftMerchantRecipe.fromBukkit(merchantRecipe).toMinecraft());
}
@Override
public int getRecipeCount() {
return getHandle().getOffers(null).size();
}
@Override
public boolean isTrading() {
return getTrader() != null;
}
@Override
public HumanEntity getTrader() {
EntityHuman eh = getHandle().t_(); // PAIL: rename t_ -> getTrader
return eh == null ? null : eh.getBukkitEntity();
}
@Override
public int getRiches() {
return getHandle().riches;
}
@Override
public void setRiches(int riches) {
getHandle().riches = riches;
}
}

View File

@@ -4,6 +4,7 @@ import net.minecraft.server.EntityZombie;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Zombie;
public class CraftZombie extends CraftMonster implements Zombie {
@@ -39,6 +40,21 @@ public class CraftZombie extends CraftMonster implements Zombie {
}
public void setVillager(boolean flag) {
getHandle().setVillager(flag);
getHandle().setVillagerType(0);
}
@Override
public void setVillagerProfession(Villager.Profession profession) {
if (profession == null) {
getHandle().clearVillagerType();
} else {
getHandle().setVillagerType(profession.getId());
}
}
@Override
public Villager.Profession getVillagerProfession() {
if (!isVillager()) return null;
return Villager.Profession.getProfession(getHandle().getVillagerType());
}
}

View File

@@ -54,6 +54,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.server.ServerListPingEvent;
@@ -337,7 +338,7 @@ public class CraftEventFactory {
return event;
}
public static void handleBlockSpreadEvent(Block block, Block source, net.minecraft.server.Block type, int data) {
public static boolean handleBlockSpreadEvent(Block block, Block source, net.minecraft.server.Block type, int data) {
BlockState state = block.getState();
state.setTypeId(net.minecraft.server.Block.getId(type));
state.setRawData((byte) data);
@@ -348,6 +349,7 @@ public class CraftEventFactory {
if (!event.isCancelled()) {
state.update(true);
}
return !event.isCancelled();
}
public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim) {
@@ -414,7 +416,7 @@ public class CraftEventFactory {
EntityDamageEvent event;
if (damager == null) {
event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.BLOCK_EXPLOSION, modifiers, modifierFunctions);
} else if (entity instanceof EntityEnderDragon && ((EntityEnderDragon) entity).target == damager) {
} else if (entity instanceof EntityEnderDragon && /*PAIL FIXME ((EntityEnderDragon) entity).target == damager*/ false) {
event = new EntityDamageEvent(entity.getBukkitEntity(), DamageCause.ENTITY_EXPLOSION, modifiers, modifierFunctions);
} else {
if (damager instanceof org.bukkit.entity.TNTPrimed) {
@@ -483,6 +485,8 @@ public class CraftEventFactory {
cause = DamageCause.LIGHTNING;
} else if (source == DamageSource.FALL) {
cause = DamageCause.FALL;
} else if (source == DamageSource.DRAGON_BREATH) {
cause = DamageCause.DRAGON_BREATH;
} else {
throw new AssertionError(String.format("Unhandled damage of %s by %s from %s", entity, damager.getHandle(), source.translationIndex));
}
@@ -604,7 +608,7 @@ public class CraftEventFactory {
return event;
}
public static void handleBlockGrowEvent(World world, int x, int y, int z, net.minecraft.server.Block type, int data) {
public static boolean handleBlockGrowEvent(World world, int x, int y, int z, net.minecraft.server.Block type, int data) {
Block block = world.getWorld().getBlockAt(x, y, z);
CraftBlockState state = (CraftBlockState) block.getState();
state.setTypeId(net.minecraft.server.Block.getId(type));
@@ -616,6 +620,8 @@ public class CraftEventFactory {
if (!event.isCancelled()) {
state.update(true);
}
return !event.isCancelled();
}
public static FoodLevelChangeEvent callFoodLevelChangeEvent(EntityHuman entity, int level) {
@@ -930,6 +936,7 @@ public class CraftEventFactory {
case SPRINT_ONE_CM:
case CROUCH_ONE_CM:
case TIME_SINCE_DEATH:
case SNEAK_TIME:
// Do not process event for these - too spammy
return null;
default:
@@ -953,4 +960,11 @@ public class CraftEventFactory {
firework.world.getServer().getPluginManager().callEvent(event);
return event;
}
public static PrepareAnvilEvent callPrepareAnvilEvent(InventoryView view, ItemStack item) {
PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone());
event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
event.getInventory().setItem(2, event.getResult());
return event;
}
}

View File

@@ -19,10 +19,12 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
private static class CustomBiomeGrid implements BiomeGrid {
BiomeBase[] biome;
@Override
public Biome getBiome(int x, int z) {
return CraftBlock.biomeBaseToBiome(biome[(z << 4) | x]);
}
@Override
public void setBiome(int x, int z, Biome bio) {
biome[(z << 4) | x] = CraftBlock.biomeToBiomeBase(bio);
}
@@ -35,10 +37,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
this.random = new Random(seed);
}
public boolean isChunkLoaded(int x, int z) {
return true;
}
@Override
public Chunk getOrCreateChunk(int x, int z) {
random.setSeed((long) x * 341873128712L + (long) z * 132897987541L);
@@ -67,7 +66,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
char emptyTest = 0;
for (int i = 0; i < 4096; i++) {
// Filter invalid block id & data values.
if (Block.d.a(section[i]) == null) {
if (Block.REGISTRY_ID.fromId(section[i]) == null) {
section[i] = 0;
}
emptyTest |= section[i];
@@ -96,7 +95,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
short[] bdata = xbtypes[sec];
for (int i = 0; i < bdata.length; i++) {
Block b = Block.getById(bdata[i]);
secBlkID[i] = (char) Block.d.b(b.getBlockData());
secBlkID[i] = (char) Block.REGISTRY_ID.getId(b.getBlockData());
}
// Build chunk section
csect[sec] = new ChunkSection(sec << 4, true, secBlkID);
@@ -119,7 +118,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
char[] secBlkID = new char[4096]; // Allocate block ID bytes
for (int i = 0; i < secBlkID.length; i++) {
Block b = Block.getById(btypes[sec][i] & 0xFF);
secBlkID[i] = (char) Block.d.b(b.getBlockData());
secBlkID[i] = (char) Block.REGISTRY_ID.getId(b.getBlockData());
}
csect[sec] = new ChunkSection(sec << 4, true, secBlkID);
}
@@ -137,8 +136,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
scnt = Math.min(scnt, csect.length);
// Loop through sections
for (int sec = 0; sec < scnt; sec++) {
ChunkSection cs = null; // Add sections when needed
char[] csbytes = null;
char[] csbytes = null; // Add sections when needed
for (int cy = 0; cy < 16; cy++) {
int cyoff = cy | (sec << 4);
@@ -150,19 +148,19 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
byte blk = types[cxyoff + (cz * ydim)];
if (blk != 0) { // If non-empty
if (cs == null) { // If no section yet, get one
cs = csect[sec] = new ChunkSection(sec << 4, true);
csbytes = cs.getIdArray();
if (csbytes == null) { // If no section yet, get one
csbytes = new char[16*16*16];
}
Block b = Block.getById(blk & 0xFF);
csbytes[(cy << 8) | (cz << 4) | cx] = (char) Block.d.b(b.getBlockData());
csbytes[(cy << 8) | (cz << 4) | cx] = (char) Block.REGISTRY_ID.getId(b.getBlockData());
}
}
}
}
// If section built, finish prepping its state
if (cs != null) {
if (csbytes != null) {
ChunkSection cs = csect[sec] = new ChunkSection(sec << 4, true, csbytes);
cs.recalcBlockCounts();
}
}
@@ -172,7 +170,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
// Set biome grid
byte[] biomeIndex = chunk.getBiomeIndex();
for (int i = 0; i < biomeIndex.length; i++) {
biomeIndex[i] = (byte) (biomegrid.biome[i].id & 0xFF);
biomeIndex[i] = (byte) (BiomeBase.REGISTRY_ID.a(biomegrid.biome[i]) & 0xFF); // PAIL : rename
}
// Initialize lighting
chunk.initLighting();
@@ -181,40 +179,22 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
}
@Override
public Chunk getChunkAt(BlockPosition blockPosition) {
return getChunkAt(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
}
public void getChunkAt(IChunkProvider icp, int i, int i1) {
// Nothing!
}
@Override
public boolean a(IChunkProvider iChunkProvider, Chunk chunk, int i, int i1) {
public boolean a(Chunk chunk, int i, int i1) {
return false;
}
public boolean saveChunks(boolean bln, IProgressUpdate ipu) {
return true;
}
public boolean unloadChunks() {
return false;
}
public boolean canSave() {
return true;
}
@SuppressWarnings("deprecation")
@Override
public byte[] generate(org.bukkit.World world, Random random, int x, int z) {
return generator.generate(world, random, x, z);
}
@Override
public byte[][] generateBlockSections(org.bukkit.World world, Random random, int x, int z, BiomeGrid biomes) {
return generator.generateBlockSections(world, random, x, z, biomes);
}
@Override
public short[][] generateExtBlockSections(org.bukkit.World world, Random random, int x, int z, BiomeGrid biomes) {
return generator.generateExtBlockSections(world, random, x, z, biomes);
}
@@ -245,20 +225,11 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
return "Stronghold".equals(type) && this.strongholdGen != null ? this.strongholdGen.getNearestGeneratedFeature(world, position) : null;
}
@Override
public void recreateStructures(int i, int j) {}
public int getLoadedChunks() {
return 0;
}
@Override
public void recreateStructures(Chunk chunk, int i, int i1) {
}
public String getName() {
return "CustomChunkGenerator";
}
public void c() {}
}

View File

@@ -4,5 +4,5 @@ import net.minecraft.server.IChunkProvider;
import org.bukkit.generator.ChunkGenerator;
// Do not implement functions to this class, add to NormalChunkGenerator
public abstract class InternalChunkGenerator extends ChunkGenerator implements IChunkProvider {
public abstract class InternalChunkGenerator extends ChunkGenerator implements net.minecraft.server.ChunkGenerator {
}

View File

@@ -10,10 +10,10 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.generator.BlockPopulator;
public class NormalChunkGenerator extends InternalChunkGenerator {
private final IChunkProvider provider;
private final ChunkGenerator generator;
public NormalChunkGenerator(World world, long seed) {
provider = world.worldProvider.getChunkProvider();
generator = world.worldProvider.getChunkGenerator();
}
@Override
@@ -31,72 +31,33 @@ public class NormalChunkGenerator extends InternalChunkGenerator {
return new ArrayList<BlockPopulator>();
}
@Override
public boolean isChunkLoaded(int i, int i1) {
return provider.isChunkLoaded(i, i1);
}
@Override
public Chunk getOrCreateChunk(int i, int i1) {
return provider.getOrCreateChunk(i, i1);
return generator.getOrCreateChunk(i, i1);
}
@Override
public Chunk getChunkAt(BlockPosition blockPosition) {
return provider.getChunkAt(blockPosition);
public void recreateStructures(int i, int i1) {
generator.recreateStructures(i, i1);
}
@Override
public void getChunkAt(IChunkProvider icp, int i, int i1) {
provider.getChunkAt(icp, i, i1);
public boolean a(Chunk chunk, int i, int i1) {
return generator.a(chunk, i, i1);
}
@Override
public boolean a(IChunkProvider iChunkProvider, Chunk chunk, int i, int i1) {
return provider.a(provider, chunk, i, i1);
public List<BiomeBase.BiomeMeta> getMobsFor(EnumCreatureType enumCreatureType, BlockPosition blockPosition) {
return generator.getMobsFor(enumCreatureType, blockPosition);
}
@Override
public boolean saveChunks(boolean bln, IProgressUpdate ipu) {
return provider.saveChunks(bln, ipu);
}
@Override
public boolean unloadChunks() {
return provider.unloadChunks();
}
@Override
public boolean canSave() {
return provider.canSave();
}
@Override
public List<BiomeBase.BiomeMeta> getMobsFor(EnumCreatureType ect, BlockPosition position) {
return provider.getMobsFor(ect, position);
}
@Override
public BlockPosition findNearestMapFeature(World world, String string, BlockPosition position) {
return provider.findNearestMapFeature(world, string, position);
}
// n.m.s implementations always return 0. (The true implementation is in ChunkProviderServer)
@Override
public int getLoadedChunks() {
return 0;
public BlockPosition findNearestMapFeature(World world, String s, BlockPosition blockPosition) {
return generator.findNearestMapFeature(world, s, blockPosition);
}
@Override
public void recreateStructures(Chunk chunk, int i, int i1) {
provider.recreateStructures(chunk, i, i1);
generator.recreateStructures(chunk, i, i1);
}
@Override
public String getName() {
return "NormalWorldGenerator";
}
@Override
public void c() {}
}

View File

@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.EntityInsentient;
import net.minecraft.server.EnumItemSlot;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.entity.Entity;
@@ -8,12 +9,6 @@ import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
public class CraftEntityEquipment implements EntityEquipment {
private static final int WEAPON_SLOT = 0;
private static final int HELMET_SLOT = 4;
private static final int CHEST_SLOT = 3;
private static final int LEG_SLOT = 2;
private static final int BOOT_SLOT = 1;
private static final int INVENTORY_SLOTS = 5;
private final CraftLivingEntity entity;
@@ -21,72 +16,96 @@ public class CraftEntityEquipment implements EntityEquipment {
this.entity = entity;
}
public ItemStack getItemInHand() {
return getEquipment(WEAPON_SLOT);
@Override
public ItemStack getItemInMainHand() {
return getEquipment(EnumItemSlot.MAINHAND);
}
@Override
public void setItemInMainHand(ItemStack item) {
setEquipment(EnumItemSlot.MAINHAND, item);
}
@Override
public ItemStack getItemInOffHand() {
return getEquipment(EnumItemSlot.OFFHAND);
}
@Override
public void setItemInOffHand(ItemStack item) {
setEquipment(EnumItemSlot.OFFHAND, item);
}
@Override
public ItemStack getItemInHand() {
return getItemInMainHand();
}
@Override
public void setItemInHand(ItemStack stack) {
setEquipment(WEAPON_SLOT, stack);
setItemInMainHand(stack);
}
public ItemStack getHelmet() {
return getEquipment(HELMET_SLOT);
return getEquipment(EnumItemSlot.HEAD);
}
public void setHelmet(ItemStack helmet) {
setEquipment(HELMET_SLOT, helmet);
setEquipment(EnumItemSlot.HEAD, helmet);
}
public ItemStack getChestplate() {
return getEquipment(CHEST_SLOT);
return getEquipment(EnumItemSlot.CHEST);
}
public void setChestplate(ItemStack chestplate) {
setEquipment(CHEST_SLOT, chestplate);
setEquipment(EnumItemSlot.CHEST, chestplate);
}
public ItemStack getLeggings() {
return getEquipment(LEG_SLOT);
return getEquipment(EnumItemSlot.LEGS);
}
public void setLeggings(ItemStack leggings) {
setEquipment(LEG_SLOT, leggings);
setEquipment(EnumItemSlot.LEGS, leggings);
}
public ItemStack getBoots() {
return getEquipment(BOOT_SLOT);
return getEquipment(EnumItemSlot.FEET);
}
public void setBoots(ItemStack boots) {
setEquipment(BOOT_SLOT, boots);
setEquipment(EnumItemSlot.FEET, boots);
}
public ItemStack[] getArmorContents() {
ItemStack[] armor = new ItemStack[INVENTORY_SLOTS - 1];
for(int slot = WEAPON_SLOT + 1; slot < INVENTORY_SLOTS; slot++) {
armor[slot - 1] = getEquipment(slot);
}
ItemStack[] armor = new ItemStack[]{
getEquipment(EnumItemSlot.FEET),
getEquipment(EnumItemSlot.LEGS),
getEquipment(EnumItemSlot.CHEST),
getEquipment(EnumItemSlot.HEAD),
};
return armor;
}
public void setArmorContents(ItemStack[] items) {
for(int slot = WEAPON_SLOT + 1; slot < INVENTORY_SLOTS; slot++) {
ItemStack equipment = items != null && slot <= items.length ? items[slot - 1] : null;
setEquipment(slot, equipment);
}
setEquipment(EnumItemSlot.FEET, items.length >= 1 ? items[0] : null);
setEquipment(EnumItemSlot.LEGS, items.length >= 2 ? items[1] : null);
setEquipment(EnumItemSlot.CHEST, items.length >= 3 ? items[2] : null);
setEquipment(EnumItemSlot.HEAD, items.length >= 4 ? items[3] : null);
}
private ItemStack getEquipment(int slot) {
private ItemStack getEquipment(EnumItemSlot slot) {
return CraftItemStack.asBukkitCopy(entity.getHandle().getEquipment(slot));
}
private void setEquipment(int slot, ItemStack stack) {
entity.getHandle().setEquipment(slot, CraftItemStack.asNMSCopy(stack));
private void setEquipment(EnumItemSlot slot, ItemStack stack) {
entity.getHandle().setSlot(slot, CraftItemStack.asNMSCopy(stack));
}
public void clear() {
for(int i = 0; i < INVENTORY_SLOTS; i++) {
setEquipment(i, null);
for (EnumItemSlot slot : EnumItemSlot.values()) {
setEquipment(slot, null);
}
}
@@ -95,50 +114,58 @@ public class CraftEntityEquipment implements EntityEquipment {
}
public float getItemInHandDropChance() {
return getDropChance(WEAPON_SLOT);
return getDropChance(EnumItemSlot.MAINHAND);
}
public void setItemInHandDropChance(float chance) {
setDropChance(WEAPON_SLOT, chance);
setDropChance(EnumItemSlot.MAINHAND, chance);
}
public float getHelmetDropChance() {
return getDropChance(HELMET_SLOT);
return getDropChance(EnumItemSlot.HEAD);
}
public void setHelmetDropChance(float chance) {
setDropChance(HELMET_SLOT, chance);
setDropChance(EnumItemSlot.HEAD, chance);
}
public float getChestplateDropChance() {
return getDropChance(CHEST_SLOT);
return getDropChance(EnumItemSlot.CHEST);
}
public void setChestplateDropChance(float chance) {
setDropChance(CHEST_SLOT, chance);
setDropChance(EnumItemSlot.CHEST, chance);
}
public float getLeggingsDropChance() {
return getDropChance(LEG_SLOT);
return getDropChance(EnumItemSlot.LEGS);
}
public void setLeggingsDropChance(float chance) {
setDropChance(LEG_SLOT, chance);
setDropChance(EnumItemSlot.LEGS, chance);
}
public float getBootsDropChance() {
return getDropChance(BOOT_SLOT);
return getDropChance(EnumItemSlot.FEET);
}
public void setBootsDropChance(float chance) {
setDropChance(BOOT_SLOT, chance);
setDropChance(EnumItemSlot.FEET, chance);
}
private void setDropChance(int slot, float chance) {
((EntityInsentient) entity.getHandle()).dropChances[slot] = chance - 0.1F;
private void setDropChance(EnumItemSlot slot, float chance) {
if (slot == EnumItemSlot.MAINHAND || slot == EnumItemSlot.OFFHAND) {
((EntityInsentient) entity.getHandle()).dropChanceHand[slot.b()] = chance - 0.1F;
} else {
((EntityInsentient) entity.getHandle()).dropChanceArmor[slot.b()] = chance - 0.1F;
}
}
private float getDropChance(int slot) {
return ((EntityInsentient) entity.getHandle()).dropChances[slot] + 0.1F;
private float getDropChance(EnumItemSlot slot) {
if (slot == EnumItemSlot.MAINHAND || slot == EnumItemSlot.OFFHAND) {
return ((EntityInsentient) entity.getHandle()).dropChanceHand[slot.b()] + 0.1F;
} else {
return ((EntityInsentient) entity.getHandle()).dropChanceArmor[slot.b()] + 0.1F;
}
}
}

View File

@@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.RecipesFurnace;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
@@ -22,6 +21,6 @@ public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
public void addToCraftingManager() {
ItemStack result = this.getResult();
ItemStack input = this.getInput();
RecipesFurnace.getInstance().registerRecipe(CraftItemStack.asNMSCopy(input), CraftItemStack.asNMSCopy(result));
RecipesFurnace.getInstance().registerRecipe(CraftItemStack.asNMSCopy(input), CraftItemStack.asNMSCopy(result), getExperience());
}
}

View File

@@ -17,6 +17,7 @@ import net.minecraft.server.TileEntityDropper;
import net.minecraft.server.TileEntityFurnace;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
@@ -479,4 +480,9 @@ public class CraftInventory implements Inventory {
public boolean equals(final Object obj) {
return obj instanceof CraftInventory && ((CraftInventory) obj).inventory.equals(this.inventory);
}
@Override
public Location getLocation() {
return inventory.getLocation();
}
}

View File

@@ -1,15 +1,18 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.IInventory;
import org.bukkit.Location;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.ItemStack;
public class CraftInventoryAnvil extends CraftInventory implements AnvilInventory {
private final Location location;
private final IInventory resultInventory;
public CraftInventoryAnvil(IInventory inventory, IInventory resultInventory) {
public CraftInventoryAnvil(Location location, IInventory inventory, IInventory resultInventory) {
super(inventory);
this.location = location;
this.resultInventory = resultInventory;
}
@@ -45,4 +48,9 @@ public class CraftInventoryAnvil extends CraftInventory implements AnvilInventor
public int getSize() {
return getResultInventory().getSize() + getIngredientsInventory().getSize();
}
@Override
public Location getLocation() {
return location;
}
}

View File

@@ -23,4 +23,14 @@ public class CraftInventoryBrewer extends CraftInventory implements BrewerInvent
public BrewingStand getHolder() {
return (BrewingStand) inventory.getOwner();
}
@Override
public ItemStack getFuel() {
return getItem(4);
}
@Override
public void setFuel(ItemStack fuel) {
setItem(4, fuel);
}
}

View File

@@ -55,7 +55,7 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
for (int j = 0; j < mcItems.length; j++) {
items[i + j] = CraftItemStack.asCraftMirror(mcItems[j]);
}
return items;
}
@@ -85,10 +85,10 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
}
public ItemStack[] getMatrix() {
ItemStack[] items = new ItemStack[getSize()];
net.minecraft.server.ItemStack[] matrix = getMatrixInventory().getContents();
ItemStack[] items = new ItemStack[matrix.length];
for (int i = 0; i < matrix.length; i++ ) {
for (int i = 0; i < matrix.length; i++) {
items[i] = CraftItemStack.asCraftMirror(matrix[i]);
}
@@ -108,16 +108,16 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
net.minecraft.server.ItemStack[] mcItems = getMatrixInventory().getContents();
for (int i = 0; i < mcItems.length; i++ ) {
for (int i = 0; i < mcItems.length; i++) {
if (i < contents.length) {
ItemStack item = contents[i];
if (item == null || item.getTypeId() <= 0) {
mcItems[i] = null;
getMatrixInventory().setItem(i, null);
} else {
mcItems[i] = CraftItemStack.asNMSCopy(item);
getMatrixInventory().setItem(i, CraftItemStack.asNMSCopy(item));
}
} else {
mcItems[i] = null;
getMatrixInventory().setItem(i, null);
}
}
}

View File

@@ -14,6 +14,7 @@ import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.IInventory;
import net.minecraft.server.ItemStack;
import org.bukkit.Location;
public class CraftInventoryCustom extends CraftInventory {
public CraftInventoryCustom(InventoryHolder owner, InventoryType type) {
@@ -165,8 +166,7 @@ public class CraftInventoryCustom extends CraftInventory {
}
@Override
public void b(int i, int i1) {
public void setProperty(int i, int j) {
}
@Override
@@ -193,5 +193,10 @@ public class CraftInventoryCustom extends CraftInventory {
public IChatBaseComponent getScoreboardDisplayName() {
return new ChatComponentText(title);
}
@Override
public Location getLocation() {
return null;
}
}
}

View File

@@ -2,9 +2,26 @@ package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.InventoryMerchant;
import org.bukkit.inventory.MerchantInventory;
import org.bukkit.inventory.MerchantRecipe;
public class CraftInventoryMerchant extends CraftInventory implements MerchantInventory {
public CraftInventoryMerchant(InventoryMerchant merchant) {
super(merchant);
}
@Override
public int getSelectedRecipeIndex() {
return getInventory().e;
}
@Override
public MerchantRecipe getSelectedRecipe() {
return getInventory().getRecipe().asBukkit();
}
@Override
public InventoryMerchant getInventory() {
return (InventoryMerchant) inventory;
}
}

View File

@@ -22,16 +22,33 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
}
@Override
public int getSize() {
return super.getSize() - 4;
}
public ItemStack getItemInHand() {
public ItemStack getItemInMainHand() {
return CraftItemStack.asCraftMirror(getInventory().getItemInHand());
}
@Override
public void setItemInMainHand(ItemStack item) {
setItem(getHeldItemSlot(), item);
}
@Override
public ItemStack getItemInOffHand() {
return CraftItemStack.asCraftMirror(getInventory().extraSlots[0]);
}
@Override
public void setItemInOffHand(ItemStack item) {
getInventory().extraSlots[0] = CraftItemStack.asNMSCopy(item);
}
@Override
public ItemStack getItemInHand() {
return getItemInMainHand();
}
@Override
public void setItemInHand(ItemStack stack) {
setItem(getHeldItemSlot(), stack);
setItemInMainHand(stack);
}
@Override
@@ -86,35 +103,35 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
}
public ItemStack getHelmet() {
return getItem(getSize() + 3);
return getItem(getSize() - 2);
}
public ItemStack getChestplate() {
return getItem(getSize() + 2);
return getItem(getSize() - 3);
}
public ItemStack getLeggings() {
return getItem(getSize() + 1);
return getItem(getSize() - 4);
}
public ItemStack getBoots() {
return getItem(getSize() + 0);
return getItem(getSize() - 5);
}
public void setHelmet(ItemStack helmet) {
setItem(getSize() + 3, helmet);
setItem(getSize() - 2, helmet);
}
public void setChestplate(ItemStack chestplate) {
setItem(getSize() + 2, chestplate);
setItem(getSize() - 3, chestplate);
}
public void setLeggings(ItemStack leggings) {
setItem(getSize() + 1, leggings);
setItem(getSize() - 4, leggings);
}
public void setBoots(ItemStack boots) {
setItem(getSize() + 0, boots);
setItem(getSize() - 5, boots);
}
public ItemStack[] getArmorContents() {

View File

@@ -21,11 +21,14 @@ public final class CraftItemFactory implements ItemFactory {
instance = new CraftItemFactory();
ConfigurationSerialization.registerClass(CraftMetaItem.SerializableMeta.class);
KNOWN_NBT_ATTRIBUTE_NAMES = ImmutableSet.<String>builder()
.add("generic.armor")
.add("generic.attackDamage")
.add("generic.followRange")
.add("generic.knockbackResistance")
.add("generic.maxHealth")
.add("generic.movementSpeed")
.add("generic.attackSpeed")
.add("generic.luck")
.add("horse.jumpStrength")
.add("zombie.spawnReinforcements")
.build();
@@ -103,6 +106,7 @@ public final class CraftItemFactory implements ItemFactory {
case HOPPER:
case REDSTONE_COMPARATOR:
case FLOWER_POT_ITEM:
case SHIELD:
return new CraftMetaBlockState(meta, material);
default:
return new CraftMetaItem(meta);

View File

@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
import net.minecraft.server.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.Items;
import net.minecraft.server.NBTTagString;
import org.bukkit.craftbukkit.enchantments.CraftEnchantment;
import org.bukkit.craftbukkit.util.CraftChatMessage;
@DelegateDeserialization(ItemStack.class)
@@ -230,7 +231,7 @@ public final class CraftItemStack extends ItemStack {
if (handle == null) {
return 0;
}
return EnchantmentManager.getEnchantmentLevel(ench.getId(), handle);
return EnchantmentManager.getEnchantmentLevel(CraftEnchantment.getRaw(ench), handle);
}
@Override
@@ -367,6 +368,7 @@ public final class CraftItemStack extends ItemStack {
case HOPPER:
case REDSTONE_COMPARATOR:
case FLOWER_POT_ITEM:
case SHIELD:
return new CraftMetaBlockState(item.getTag(), CraftMagicNumbers.getMaterial(item.getItem()));
default:
return new CraftMetaItem(item.getTag());

View File

@@ -0,0 +1,79 @@
package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Preconditions;
import java.util.List;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
public class CraftMerchantRecipe extends MerchantRecipe {
private final net.minecraft.server.MerchantRecipe handle;
public CraftMerchantRecipe(net.minecraft.server.MerchantRecipe merchantRecipe) {
super(null, 0);
this.handle = merchantRecipe;
}
public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward) {
super(result, uses, maxUses, experienceReward);
this.handle = new net.minecraft.server.MerchantRecipe(
CraftItemStack.asNMSCopy(result),
null,
null,
uses,
maxUses,
this
);
}
@Override
public int getUses() {
return handle.uses;
}
@Override
public void setUses(int uses) {
handle.uses = uses;
}
@Override
public int getMaxUses() {
return handle.maxUses;
}
@Override
public void setMaxUses(int maxUses) {
handle.maxUses = maxUses;
}
@Override
public boolean hasExperienceReward() {
return handle.rewardExp;
}
@Override
public void setExperienceReward(boolean flag) {
handle.rewardExp = flag;
}
public net.minecraft.server.MerchantRecipe toMinecraft() {
List<ItemStack> ingredients = getIngredients();
Preconditions.checkState(!ingredients.isEmpty(), "No offered ingredients");
handle.buyingItem1 = CraftItemStack.asNMSCopy(ingredients.get(0));
if (ingredients.size() > 1) {
handle.buyingItem2 = CraftItemStack.asNMSCopy(ingredients.get(1));
}
return handle;
}
public static CraftMerchantRecipe fromBukkit(MerchantRecipe recipe) {
if (recipe instanceof CraftMerchantRecipe) {
return (CraftMerchantRecipe) recipe;
} else {
CraftMerchantRecipe craft = new CraftMerchantRecipe(recipe.getResult(), recipe.getUses(), recipe.getMaxUses(), recipe.hasExperienceReward());
craft.setIngredients(recipe.getIngredients());
return craft;
}
}
}

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import net.minecraft.server.BlockJukeBox;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.NBTBase;
import net.minecraft.server.NBTTagCompound;
import net.minecraft.server.TileEntity;
@@ -55,9 +56,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
this.material = material;
if (!(meta instanceof CraftMetaBlockState)
|| ((CraftMetaBlockState) meta).material != material
|| material == Material.SIGN
|| material == Material.COMMAND) {
|| ((CraftMetaBlockState) meta).material != material) {
blockEntityTag = null;
return;
}
@@ -153,7 +152,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
@Override
boolean applicableTo(Material type) {
switch(type){
switch(type){
case FURNACE:
case CHEST:
case TRAPPED_CHEST:
@@ -173,6 +172,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
case HOPPER:
case REDSTONE_COMPARATOR:
case FLOWER_POT_ITEM:
case SHIELD:
return true;
}
return false;
@@ -185,7 +185,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
@Override
public BlockState getBlockState() {
TileEntity te = blockEntityTag == null ? null : TileEntity.c(blockEntityTag);
TileEntity te = blockEntityTag == null ? null : TileEntity.a(MinecraftServer.getServer(), blockEntityTag);
switch (material) {
case SIGN:
@@ -257,6 +257,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
te = new TileEntityBeacon();
}
return new CraftBeacon(material, (TileEntityBeacon) te);
case SHIELD:
case BANNER:
case WALL_BANNER:
case STANDING_BANNER:
@@ -320,6 +321,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
case BEACON:
valid = te instanceof TileEntityBeacon;
break;
case SHIELD:
case BANNER:
case WALL_BANNER:
case STANDING_BANNER:
@@ -333,6 +335,6 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
Validate.isTrue(valid, "Invalid blockState for " + material);
blockEntityTag = new NBTTagCompound();
te.b(blockEntityTag);
te.save(blockEntityTag);
}
}

View File

@@ -6,6 +6,7 @@ import net.minecraft.server.EntityHuman;
import net.minecraft.server.IChatBaseComponent;
import net.minecraft.server.IInventory;
import net.minecraft.server.ItemStack;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.entity.HumanEntity;
@@ -106,7 +107,7 @@ public class InventoryWrapper implements IInventory {
}
@Override
public void b(int i, int j) {
public void setProperty(int i, int j) {
}
@Override
@@ -170,4 +171,9 @@ public class InventoryWrapper implements IInventory {
public IChatBaseComponent getScoreboardDisplayName() {
return CraftChatMessage.fromString(getName())[0];
}
@Override
public Location getLocation() {
return inventory.getLocation();
}
}

View File

@@ -5,8 +5,13 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.minecraft.server.ItemStack;
import net.minecraft.server.Items;
import net.minecraft.server.MobEffect;
import net.minecraft.server.MobEffectList;
import net.minecraft.server.PotionUtil;
import org.bukkit.Color;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionBrewer;
import org.bukkit.potion.PotionEffect;
@@ -20,7 +25,7 @@ public class CraftPotionBrewer implements PotionBrewer {
if (cache.containsKey(damage))
return cache.get(damage);
List<?> mcEffects = net.minecraft.server.PotionBrewer.getEffects(damage, false);
List<?> mcEffects = PotionUtil.getEffects(new ItemStack(Items.POTION, 1, damage));
List<PotionEffect> effects = new ArrayList<PotionEffect>();
if (mcEffects == null)
return effects;
@@ -29,8 +34,8 @@ public class CraftPotionBrewer implements PotionBrewer {
if (raw == null || !(raw instanceof MobEffect))
continue;
MobEffect mcEffect = (MobEffect) raw;
PotionEffect effect = new PotionEffect(PotionEffectType.getById(mcEffect.getEffectId()),
mcEffect.getDuration(), mcEffect.getAmplifier());
PotionEffect effect = new PotionEffect(PotionEffectType.getById(MobEffectList.getId(mcEffect.getMobEffect())),
mcEffect.getDuration(), mcEffect.getAmplifier(), true, true, Color.fromRGB(mcEffect.getMobEffect().getColor()));
// Minecraft PotionBrewer applies duration modifiers automatically.
effects.add(effect);
}

View File

@@ -8,13 +8,13 @@ public class CraftPotionEffectType extends PotionEffectType {
private final MobEffectList handle;
public CraftPotionEffectType(MobEffectList handle) {
super(handle.id);
super(MobEffectList.getId(handle));
this.handle = handle;
}
@Override
public double getDurationModifier() {
return handle.getDurationModifier();
return handle.durationModifier;
}
public MobEffectList getHandle() {
@@ -23,7 +23,7 @@ public class CraftPotionEffectType extends PotionEffectType {
@Override
public String getName() {
switch (handle.id) {
switch (getId()) {
case 1:
return "SPEED";
case 2:
@@ -70,8 +70,16 @@ public class CraftPotionEffectType extends PotionEffectType {
return "ABSORPTION";
case 23:
return "SATURATION";
case 24:
return "GLOWING";
case 25:
return "LEVITATION";
case 26:
return "LUCK";
case 27:
return "UNLUCK";
default:
return "UNKNOWN_EFFECT_TYPE_" + handle.id;
return "UNKNOWN_EFFECT_TYPE_" + getId();
}
}

View File

@@ -31,6 +31,7 @@ import net.minecraft.server.EntityProjectile;
import net.minecraft.server.EntitySmallFireball;
import net.minecraft.server.EntitySnowball;
import net.minecraft.server.EntityThrownExpBottle;
import net.minecraft.server.EntityTippedArrow;
import net.minecraft.server.EntityWitherSkull;
import net.minecraft.server.EnumDirection;
import net.minecraft.server.IPosition;
@@ -63,7 +64,7 @@ public class CraftBlockProjectileSource implements BlockProjectileSource {
SourceBlock isourceblock = new SourceBlock(dispenserBlock.getWorld(), dispenserBlock.getPosition());
// Copied from DispenseBehaviorProjectile
IPosition iposition = BlockDispenser.a(isourceblock);
EnumDirection enumdirection = BlockDispenser.b(isourceblock.f());
EnumDirection enumdirection = BlockDispenser.e(isourceblock.f());
net.minecraft.server.World world = dispenserBlock.getWorld();
net.minecraft.server.Entity launch = null;
@@ -79,8 +80,8 @@ public class CraftBlockProjectileSource implements BlockProjectileSource {
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
} else if (Arrow.class.isAssignableFrom(projectile)) {
launch = new EntityArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
((EntityArrow) launch).fromPlayer = 1;
launch = new EntityTippedArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
((EntityArrow) launch).fromPlayer = EntityArrow.PickupStatus.ALLOWED;
((EntityArrow) launch).projectileSource = this;
} else if (Fireball.class.isAssignableFrom(projectile)) {
double d0 = iposition.getX() + (double) ((float) enumdirection.getAdjacentX() * 0.3F);
@@ -92,7 +93,7 @@ public class CraftBlockProjectileSource implements BlockProjectileSource {
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ();
if (SmallFireball.class.isAssignableFrom(projectile)) {
launch = new EntitySmallFireball(world, d0, d1, d2, d3, d4, d5);
launch = new EntitySmallFireball(world, null, d0, d1, d2);
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = new EntityWitherSkull(world);
launch.setPosition(d0, d1, d2);

View File

@@ -112,7 +112,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
// CraftBukkit method
public void updateAllScoresForList(IScoreboardCriteria criteria, String name, List<EntityPlayer> of) {
for (ScoreboardScore score : getScoreboardScores(criteria, name, new ArrayList<ScoreboardScore>())) {
score.updateForList((List) of);
// PAIL: FIXME score.updateForList((List) of);
}
}
}

View File

@@ -82,6 +82,9 @@ public final class CraftMagicNumbers implements UnsafeValues {
}
public static Block getBlock(Material material) {
if (material == null) {
return null;
}
// TODO: Don't use ID
Block block = Block.getById(material.getId());

View File

@@ -4,7 +4,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
public abstract class LazyHashSet<E> implements Set<E> {
Set<E> reference = null;

View File

@@ -9,17 +9,22 @@ import org.bukkit.entity.Player;
public class LazyPlayerSet extends LazyHashSet<Player> {
private final MinecraftServer server;
public LazyPlayerSet(MinecraftServer server) {
this.server = server;
}
@Override
HashSet<Player> makeReference() {
if (reference != null) {
throw new IllegalStateException("Reference already created!");
}
List<EntityPlayer> players = MinecraftServer.getServer().getPlayerList().players;
List<EntityPlayer> players = server.getPlayerList().players;
HashSet<Player> reference = new HashSet<Player>(players.size());
for (EntityPlayer player : players) {
reference.add(player.getBukkitEntity());
}
return reference;
}
}

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="net.minecraft,com.mojang">
<Configuration status="WARN" packages="com.mojang.util">
<Appenders>
<Console name="WINDOWS_COMPAT" target="SYSTEM_OUT"></Console>
<Queue name="TerminalConsole">

View File

@@ -0,0 +1,24 @@
package org.bukkit;
import net.minecraft.server.BiomeBase;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.junit.Assert;
import org.junit.Test;
public class BiomeTest {
@Test
public void testBukkitToMinecraft() {
for (Biome biome : Biome.values()) {
Assert.assertNotNull("No NMS mapping for " + biome, CraftBlock.biomeToBiomeBase(biome));
}
}
@Test
public void testMinecraftToBukkit() {
for (BiomeBase biome : BiomeBase.REGISTRY_ID) {
Assert.assertNotNull("No Bukkit mapping for " + biome, CraftBlock.biomeBaseToBiome(biome));
}
}
}

View File

@@ -0,0 +1,19 @@
package org.bukkit;
import net.minecraft.server.EnumParticle;
import org.bukkit.craftbukkit.CraftParticle;
import org.junit.Assert;
import org.junit.Test;
public class ParticleTest {
@Test
public void verifyMapping() {
for (Particle bukkit : Particle.values()) {
Assert.assertNotNull("Missing Bukkit->NMS particle mapping", CraftParticle.toNMS(bukkit));
}
for (EnumParticle nms : EnumParticle.values()) {
Assert.assertNotNull("Missing NMS->Bukkit particle mapping", CraftParticle.toBukkit(nms));
}
}
}

View File

@@ -53,7 +53,7 @@ public class PerMaterialTest extends AbstractTestingBase {
if (material == Material.AIR) {
assertFalse(material.isSolid());
} else if (material.isBlock()) {
assertThat(material.isSolid(), is(CraftMagicNumbers.getBlock(material).getMaterial().isSolid()));
assertThat(material.isSolid(), is(CraftMagicNumbers.getBlock(material).getBlockData().getMaterial().isSolid()));
} else {
assertFalse(material.isSolid());
}
@@ -104,7 +104,7 @@ public class PerMaterialTest extends AbstractTestingBase {
if (material == Material.AIR) {
assertTrue(material.isTransparent());
} else if (material.isBlock()) {
assertThat(material.isTransparent(), is(not(CraftMagicNumbers.getBlock(material).getMaterial().blocksLight())));
assertThat(material.isTransparent(), is(not(CraftMagicNumbers.getBlock(material).getBlockData().getMaterial().blocksLight())));
} else {
assertFalse(material.isTransparent());
}
@@ -113,7 +113,7 @@ public class PerMaterialTest extends AbstractTestingBase {
@Test
public void isFlammable() {
if (material != Material.AIR && material.isBlock()) {
assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).getMaterial().isBurnable()));
assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).getBlockData().getMaterial().isBurnable()));
} else {
assertFalse(material.isFlammable());
}
@@ -132,7 +132,7 @@ public class PerMaterialTest extends AbstractTestingBase {
@Test
public void isOccluding() {
if (material.isBlock()) {
assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).isOccluding()));
assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).isOccluding(CraftMagicNumbers.getBlock(material).getBlockData())));
} else {
assertFalse(material.isOccluding());
}

View File

@@ -1,12 +1,14 @@
package org.bukkit;
import net.minecraft.server.MinecraftKey;
import net.minecraft.server.SoundEffect;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import org.bukkit.craftbukkit.CraftSound;
import org.junit.Test;
public class SoundTest {
@Test
@@ -15,4 +17,11 @@ public class SoundTest {
assertThat(sound.name(), CraftSound.getSound(sound), is(not(nullValue())));
}
}
@Test
public void testReverse() {
for (MinecraftKey effect : SoundEffect.a.keySet()) {
assertNotNull(effect + "", Sound.valueOf(effect.a().replace('.', '_').toUpperCase()));
}
}
}

View File

@@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import net.minecraft.server.Enchantment;
import net.minecraft.server.Enchantments;
import org.bukkit.inventory.ItemStack;
import org.bukkit.support.AbstractTestingBase;
@@ -14,7 +14,7 @@ public class NMSCraftItemStackTest extends AbstractTestingBase {
@Test
public void testCloneEnchantedItem() throws Exception {
net.minecraft.server.ItemStack nmsItemStack = new net.minecraft.server.ItemStack(net.minecraft.server.Items.POTION);
nmsItemStack.addEnchantment(Enchantment.DAMAGE_ALL, 1);
nmsItemStack.addEnchantment(Enchantments.DAMAGE_ALL, 1);
ItemStack itemStack = CraftItemStack.asCraftMirror(nmsItemStack);
ItemStack clone = itemStack.clone();
assertThat(clone.getType(), is(itemStack.getType()));

View File

@@ -4,10 +4,13 @@ import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import net.minecraft.server.MobEffect;
import net.minecraft.server.MobEffectList;
import net.minecraft.server.PotionRegistry;
import org.bukkit.support.AbstractTestingBase;
import org.bukkit.support.Util;
import org.junit.Test;
public class PotionTest extends AbstractTestingBase {
@@ -26,20 +29,20 @@ public class PotionTest extends AbstractTestingBase {
@Test
public void testEffectCompleteness() throws Throwable {
Map<Integer, ?> effectDurations = Util.getInternalState(net.minecraft.server.PotionBrewer.class, null, "effectDurations");
Map<PotionType, String> effects = new EnumMap(PotionType.class);
for (int id : effectDurations.keySet()) {
for (PotionRegistry reg : PotionRegistry.a) {
List<MobEffect> eff = reg.a();
if (eff.size() != 1) continue;
int id = MobEffectList.getId(eff.get(0).getMobEffect());
PotionEffectType type = PotionEffectType.getById(id);
assertNotNull(String.valueOf(id), PotionEffectType.getById(id));
PotionType enumType = PotionType.getByEffect(type);
assertNotNull(type.getName(), enumType);
assertThat(enumType.name(), effects.put(enumType, enumType.name()), is(nullValue()));
effects.put(enumType, enumType.name());
}
assertThat(effects.entrySet(), hasSize(effectDurations.size()));
assertThat(effectDurations.entrySet(), hasSize(PotionType.values().length - /* WATER */ 1));
assertEquals(effects.entrySet().size(), PotionType.values().length - /* WATER */ 1);
}
}

View File

@@ -64,7 +64,12 @@ public abstract class AbstractTestingBase {
Material.BIRCH_DOOR,
Material.JUNGLE_DOOR,
Material.ACACIA_DOOR,
Material.DARK_OAK_DOOR
Material.DARK_OAK_DOOR,
Material.PURPUR_DOUBLE_SLAB,
Material.BEETROOT_BLOCK,
Material.END_GATEWAY,
Material.STRUCTURE_BLOCK,
Material.BURNING_FURNACE
).build();
@BeforeClass

View File

@@ -1,10 +1,10 @@
package org.bukkit.support;
import net.minecraft.server.Enchantment;
import net.minecraft.server.Enchantments;
public class DummyEnchantments {
static {
Enchantment.getEffects();
Enchantments.DAMAGE_ALL.getClass();
org.bukkit.enchantments.Enchantment.stopAcceptingRegistrations();
}

View File

@@ -1,6 +1,6 @@
package org.bukkit.support;
import net.minecraft.server.MobEffectList;
import net.minecraft.server.MobEffects;
import org.bukkit.craftbukkit.potion.CraftPotionBrewer;
import org.bukkit.potion.Potion;
@@ -9,7 +9,7 @@ import org.bukkit.potion.PotionEffectType;
public class DummyPotions {
static {
Potion.setPotionBrewer(new CraftPotionBrewer());
MobEffectList.BLINDNESS.getClass();
MobEffects.BLINDNESS.getClass();
PotionEffectType.stopAcceptingRegistrations();
}