Update CraftBukkit to Minecraft 1.3.1
This commit is contained in:
committed by
Travis Watkins
parent
08e2923bd4
commit
a43d621c01
@@ -11,9 +11,9 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
public class ItemInWorldManager {
|
||||
|
||||
public World world;
|
||||
public EntityHuman player;
|
||||
private int c = -1;
|
||||
private float d = 0.0F;
|
||||
public EntityPlayer player;
|
||||
private EnumGamemode gamemode;
|
||||
private boolean d;
|
||||
private int lastDigTick;
|
||||
private int f;
|
||||
private int g;
|
||||
@@ -24,65 +24,86 @@ public class ItemInWorldManager {
|
||||
private int l;
|
||||
private int m;
|
||||
private int n;
|
||||
private int o;
|
||||
|
||||
public ItemInWorldManager(World world) {
|
||||
this.gamemode = EnumGamemode.NONE;
|
||||
this.o = -1;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
// CraftBukkit start - keep this for backwards compatibility
|
||||
public ItemInWorldManager(WorldServer world) {
|
||||
this.world = world;
|
||||
this((World) world);
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
public void setGameMode(int i) {
|
||||
this.c = i;
|
||||
if (i == 0) {
|
||||
this.player.abilities.canFly = false;
|
||||
this.player.abilities.isFlying = false;
|
||||
this.player.abilities.canInstantlyBuild = false;
|
||||
this.player.abilities.isInvulnerable = false;
|
||||
} else {
|
||||
this.player.abilities.canFly = true;
|
||||
this.player.abilities.canInstantlyBuild = true;
|
||||
this.player.abilities.isInvulnerable = true;
|
||||
}
|
||||
|
||||
public void setGameMode(EnumGamemode enumgamemode) {
|
||||
this.gamemode = enumgamemode;
|
||||
enumgamemode.a(this.player.abilities);
|
||||
this.player.updateAbilities();
|
||||
}
|
||||
|
||||
public int getGameMode() {
|
||||
return this.c;
|
||||
public EnumGamemode getGameMode() {
|
||||
return this.gamemode;
|
||||
}
|
||||
|
||||
public boolean isCreative() {
|
||||
return this.c == 1;
|
||||
return this.gamemode.d();
|
||||
}
|
||||
|
||||
public void b(int i) {
|
||||
if (this.c == -1) {
|
||||
this.c = i;
|
||||
public void b(EnumGamemode enumgamemode) {
|
||||
if (this.gamemode == EnumGamemode.NONE) {
|
||||
this.gamemode = enumgamemode;
|
||||
}
|
||||
|
||||
this.setGameMode(this.c);
|
||||
this.setGameMode(this.gamemode);
|
||||
}
|
||||
|
||||
public void c() {
|
||||
public void a() {
|
||||
this.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
if (this.j) {
|
||||
int i = this.currentTick - this.n;
|
||||
int j = this.world.getTypeId(this.k, this.l, this.m);
|
||||
int i;
|
||||
float f;
|
||||
int j;
|
||||
|
||||
if (j != 0) {
|
||||
Block block = Block.byId[j];
|
||||
float f = block.getDamage(this.player) * (float) (i + 1);
|
||||
if (this.j) {
|
||||
i = this.currentTick - this.n;
|
||||
int k = this.world.getTypeId(this.k, this.l, this.m);
|
||||
|
||||
if (k == 0) {
|
||||
this.j = false;
|
||||
} else {
|
||||
Block block = Block.byId[k];
|
||||
|
||||
f = block.getDamage(this.player, this.player.world, this.k, this.l, this.m) * (float) (i + 1);
|
||||
j = (int) (f * 10.0F);
|
||||
if (j != this.o) {
|
||||
this.world.f(this.player.id, this.k, this.l, this.m, j);
|
||||
this.o = j;
|
||||
}
|
||||
|
||||
if (f >= 1.0F) {
|
||||
this.j = false;
|
||||
this.breakBlock(this.k, this.l, this.m);
|
||||
}
|
||||
}
|
||||
} else if (this.d) {
|
||||
i = this.world.getTypeId(this.f, this.g, this.h);
|
||||
Block block1 = Block.byId[i];
|
||||
|
||||
if (block1 == null) {
|
||||
this.world.f(this.player.id, this.f, this.g, this.h, -1);
|
||||
this.o = -1;
|
||||
this.d = false;
|
||||
} else {
|
||||
this.j = false;
|
||||
int l = this.currentTick - this.lastDigTick;
|
||||
|
||||
f = block1.getDamage(this.player, this.player.world, this.f, this.g, this.h) * (float) (l + 1);
|
||||
j = (int) (f * 10.0F);
|
||||
if (j != this.o) {
|
||||
this.world.f(this.player.id, this.f, this.g, this.h, j);
|
||||
this.o = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,7 +113,7 @@ public class ItemInWorldManager {
|
||||
// CraftBukkit
|
||||
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, i, j, k, l, this.player.inventory.getItemInHand());
|
||||
|
||||
if (this.isCreative()) {
|
||||
if (!this.gamemode.isAdventure()) {
|
||||
// CraftBukkit start
|
||||
if (event.isCancelled()) {
|
||||
// Let the client know the block still exists
|
||||
@@ -100,62 +121,70 @@ public class ItemInWorldManager {
|
||||
return;
|
||||
}
|
||||
// CraftBukkit end
|
||||
if (!this.world.douseFire((EntityHuman) null, i, j, k, l)) {
|
||||
this.breakBlock(i, j, k);
|
||||
}
|
||||
} else {
|
||||
this.lastDigTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
|
||||
int i1 = this.world.getTypeId(i, j, k);
|
||||
|
||||
// CraftBukkit start - Swings at air do *NOT* exist.
|
||||
if (i1 <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.useInteractedBlock() == Event.Result.DENY) {
|
||||
// If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
|
||||
if (i1 == Block.WOODEN_DOOR.id) {
|
||||
// For some reason *BOTH* the bottom/top part have to be marked updated.
|
||||
boolean bottom = (this.world.getData(i, j, k) & 8) == 0;
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j + (bottom ? 1 : -1), k, this.world));
|
||||
} else if (i1 == Block.TRAP_DOOR.id) {
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
if (this.isCreative()) {
|
||||
if (!this.world.douseFire((EntityHuman) null, i, j, k, l)) {
|
||||
this.breakBlock(i, j, k);
|
||||
}
|
||||
} else {
|
||||
Block.byId[i1].attack(this.world, i, j, k, this.player);
|
||||
// Allow fire punching to be blocked
|
||||
this.world.douseFire((EntityHuman) null, i, j, k, l);
|
||||
}
|
||||
|
||||
// Handle hitting a block
|
||||
float toolDamage = Block.byId[i1].getDamage(this.player);
|
||||
if (event.useItemInHand() == Event.Result.DENY) {
|
||||
// If we 'insta destroyed' then the client needs to be informed.
|
||||
if (toolDamage > 1.0f) {
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
this.world.douseFire(this.player, i, j, k, l);
|
||||
this.lastDigTick = this.currentTick;
|
||||
float f = 1.0F;
|
||||
int i1 = this.world.getTypeId(i, j, k);
|
||||
// CraftBukkit start - Swings at air do *NOT* exist.
|
||||
if (i1 <= 0) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, i, j, k, this.player.inventory.getItemInHand(), toolDamage >= 1.0f);
|
||||
|
||||
if (blockEvent.isCancelled()) {
|
||||
// Let the client know the block still exists
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
return;
|
||||
}
|
||||
if (event.useInteractedBlock() == Event.Result.DENY) {
|
||||
// If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
|
||||
if (i1 == Block.WOODEN_DOOR.id) {
|
||||
// For some reason *BOTH* the bottom/top part have to be marked updated.
|
||||
boolean bottom = (this.world.getData(i, j, k) & 8) == 0;
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j + (bottom ? 1 : -1), k, this.world));
|
||||
} else if (i1 == Block.TRAP_DOOR.id) {
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
}
|
||||
} else {
|
||||
Block.byId[i1].attack(this.world, i, j, k, this.player);
|
||||
// Allow fire punching to be blocked
|
||||
this.world.douseFire((EntityHuman) null, i, j, k, l);
|
||||
}
|
||||
|
||||
if (blockEvent.getInstaBreak()) {
|
||||
toolDamage = 2.0f;
|
||||
}
|
||||
// Handle hitting a block
|
||||
float toolDamage = Block.byId[i1].getDamage(this.player, this.world, i, j, k);
|
||||
if (event.useItemInHand() == Event.Result.DENY) {
|
||||
// If we 'insta destroyed' then the client needs to be informed.
|
||||
if (toolDamage > 1.0f) {
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
}
|
||||
return;
|
||||
}
|
||||
org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, i, j, k, this.player.inventory.getItemInHand(), toolDamage >= 1.0f);
|
||||
|
||||
if (toolDamage >= 1.0F) {
|
||||
// CraftBukkit end
|
||||
this.breakBlock(i, j, k);
|
||||
} else {
|
||||
this.f = i;
|
||||
this.g = j;
|
||||
this.h = k;
|
||||
if (blockEvent.isCancelled()) {
|
||||
// Let the client know the block still exists
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
return;
|
||||
}
|
||||
|
||||
if (blockEvent.getInstaBreak()) {
|
||||
toolDamage = 2.0f;
|
||||
}
|
||||
|
||||
if (toolDamage >= 1.0F) {
|
||||
// CraftBukkit end
|
||||
this.breakBlock(i, j, k);
|
||||
} else {
|
||||
this.d = true;
|
||||
this.f = i;
|
||||
this.g = j;
|
||||
this.h = k;
|
||||
int j1 = (int) (f * 10.0F);
|
||||
|
||||
this.world.f(this.player.id, i, j, k, j1);
|
||||
this.o = j1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,11 +197,14 @@ public class ItemInWorldManager {
|
||||
|
||||
if (i1 != 0) {
|
||||
Block block = Block.byId[i1];
|
||||
float f = block.getDamage(this.player) * (float) (l + 1);
|
||||
float f = block.getDamage(this.player, this.player.world, i, j, k) * (float) (l + 1);
|
||||
|
||||
if (f >= 0.7F) {
|
||||
this.d = false;
|
||||
this.world.f(this.player.id, i, j, k, -1);
|
||||
this.breakBlock(i, j, k);
|
||||
} else if (!this.j) {
|
||||
this.d = false;
|
||||
this.j = true;
|
||||
this.k = i;
|
||||
this.l = j;
|
||||
@@ -185,13 +217,21 @@ public class ItemInWorldManager {
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
// CraftBukkit end
|
||||
}
|
||||
|
||||
this.d = 0.0F;
|
||||
}
|
||||
|
||||
public boolean b(int i, int j, int k) {
|
||||
public void c(int i, int j, int k) {
|
||||
this.d = false;
|
||||
this.world.f(this.player.id, this.f, this.g, this.h, -1);
|
||||
}
|
||||
|
||||
private boolean d(int i, int j, int k) {
|
||||
Block block = Block.byId[this.world.getTypeId(i, j, k)];
|
||||
int l = this.world.getData(i, j, k);
|
||||
|
||||
if (block != null) {
|
||||
block.a(this.world, i, j, k, l, this.player);
|
||||
}
|
||||
|
||||
boolean flag = this.world.setTypeId(i, j, k, 0);
|
||||
|
||||
if (block != null && flag) {
|
||||
@@ -216,6 +256,7 @@ public class ItemInWorldManager {
|
||||
}
|
||||
|
||||
BlockBreakEvent event = new BlockBreakEvent(block, (org.bukkit.entity.Player) this.player.getBukkitEntity());
|
||||
event.setCancelled(this.gamemode.isAdventure()); // Adventure mode pre-cancel
|
||||
this.world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
@@ -224,34 +265,37 @@ public class ItemInWorldManager {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
int l = this.world.getTypeId(i, j, k);
|
||||
int i1 = this.world.getData(i, j, k);
|
||||
|
||||
this.world.a(this.player, 2001, i, j, k, l + (this.world.getData(i, j, k) << 12));
|
||||
boolean flag = this.b(i, j, k);
|
||||
|
||||
if (this.isCreative()) {
|
||||
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
if (false) { // Never trigger
|
||||
// CraftBukkit end
|
||||
return false;
|
||||
} else {
|
||||
ItemStack itemstack = this.player.U();
|
||||
boolean flag1 = this.player.b(Block.byId[l]);
|
||||
int l = this.world.getTypeId(i, j, k);
|
||||
int i1 = this.world.getData(i, j, k);
|
||||
|
||||
if (itemstack != null) {
|
||||
itemstack.a(l, i, j, k, this.player);
|
||||
if (itemstack.count == 0) {
|
||||
itemstack.a(this.player);
|
||||
this.player.V();
|
||||
this.world.a(this.player, 2001, i, j, k, l + (this.world.getData(i, j, k) << 12));
|
||||
boolean flag = this.d(i, j, k);
|
||||
|
||||
if (this.isCreative()) {
|
||||
this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
|
||||
} else {
|
||||
ItemStack itemstack = this.player.bC();
|
||||
boolean flag1 = this.player.b(Block.byId[l]);
|
||||
|
||||
if (itemstack != null) {
|
||||
itemstack.a(this.world, l, i, j, k, this.player);
|
||||
if (itemstack.count == 0) {
|
||||
this.player.bD();
|
||||
}
|
||||
}
|
||||
|
||||
if (flag && flag1) {
|
||||
Block.byId[l].a(this.world, this.player, i, j, k, i1);
|
||||
}
|
||||
}
|
||||
|
||||
if (flag && flag1) {
|
||||
Block.byId[l].a(this.world, this.player, i, j, k, i1);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
public boolean useItem(EntityHuman entityhuman, World world, ItemStack itemstack) {
|
||||
@@ -259,7 +303,7 @@ public class ItemInWorldManager {
|
||||
int j = itemstack.getData();
|
||||
ItemStack itemstack1 = itemstack.a(world, entityhuman);
|
||||
|
||||
if (itemstack1 == itemstack && (itemstack1 == null || itemstack1.count == i) && (itemstack1 == null || itemstack1.l() <= 0)) {
|
||||
if (itemstack1 == itemstack && (itemstack1 == null || itemstack1.count == i) && (itemstack1 == null || itemstack1.m() <= 0)) {
|
||||
return false;
|
||||
} else {
|
||||
entityhuman.inventory.items[entityhuman.inventory.itemInHandIndex] = itemstack1;
|
||||
@@ -277,7 +321,7 @@ public class ItemInWorldManager {
|
||||
}
|
||||
|
||||
// CraftBukkit - TODO: Review this code, it changed in 1.8 but I'm not sure if we need to update or not
|
||||
public boolean interact(EntityHuman entityhuman, World world, ItemStack itemstack, int i, int j, int k, int l) {
|
||||
public boolean interact(EntityHuman entityhuman, World world, ItemStack itemstack, int i, int j, int k, int l, float f, float f1, float f2) {
|
||||
int i1 = world.getTypeId(i, j, k);
|
||||
|
||||
// CraftBukkit start - Interact
|
||||
@@ -292,14 +336,14 @@ public class ItemInWorldManager {
|
||||
}
|
||||
result = (event.useItemInHand() != Event.Result.ALLOW);
|
||||
} else {
|
||||
result = Block.byId[i1].interact(world, i, j, k, entityhuman);
|
||||
result = Block.byId[i1].interact(world, i, j, k, entityhuman, l, f, f1, f2);
|
||||
}
|
||||
|
||||
if (itemstack != null && !result) {
|
||||
int j1 = itemstack.getData();
|
||||
int k1 = itemstack.count;
|
||||
|
||||
result = itemstack.placeItem(entityhuman, world, i, j, k, l);
|
||||
result = itemstack.placeItem(entityhuman, world, i, j, k, l, f, f1, f2);
|
||||
|
||||
// The item count should not decrement in Creative mode.
|
||||
if (this.isCreative()) {
|
||||
|
||||
Reference in New Issue
Block a user