Refactor ItemDoor place so that the physics update routing is called as part of the post event clenup rather than during the event. Fixes issues with the door triggering block updates / physics for cancelled events.

This commit is contained in:
md_5 2014-09-30 21:44:15 +10:00
parent ca0f1ca84d
commit 323798c25c
2 changed files with 115 additions and 1 deletions

View file

@ -1,4 +1,4 @@
From e7cd34f8686245a0af3ea79cc66ede494ca0420c Mon Sep 17 00:00:00 2001
From 4a1da136bafc6ced28b6a9219cbc26f1ed371cd1 Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Sun, 1 Dec 2013 15:10:48 +1100
Subject: [PATCH] mc-dev imports
@ -2015,6 +2015,91 @@ index 0000000..9858720
+ return "cache: " + d.size() + ", tcache: " + b.size() + ", allocated: " + e.size() + ", tallocated: " + c.size();
+ }
+}
diff --git a/src/main/java/net/minecraft/server/ItemDoor.java b/src/main/java/net/minecraft/server/ItemDoor.java
new file mode 100644
index 0000000..ee8568b
--- /dev/null
+++ b/src/main/java/net/minecraft/server/ItemDoor.java
@@ -0,0 +1,79 @@
+package net.minecraft.server;
+
+public class ItemDoor extends Item {
+
+ private Material a;
+
+ public ItemDoor(Material material) {
+ this.a = material;
+ this.maxStackSize = 1;
+ this.a(CreativeModeTab.d);
+ }
+
+ public boolean interactWith(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l, float f, float f1, float f2) {
+ if (l != 1) {
+ return false;
+ } else {
+ ++j;
+ Block block;
+
+ if (this.a == Material.WOOD) {
+ block = Blocks.WOODEN_DOOR;
+ } else {
+ block = Blocks.IRON_DOOR_BLOCK;
+ }
+
+ if (entityhuman.a(i, j, k, l, itemstack) && entityhuman.a(i, j + 1, k, l, itemstack)) {
+ if (!block.canPlace(world, i, j, k)) {
+ return false;
+ } else {
+ int i1 = MathHelper.floor((double) ((entityhuman.yaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
+
+ place(world, i, j, k, i1, block);
+ --itemstack.count;
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public static void place(World world, int i, int j, int k, int l, Block block) {
+ byte b0 = 0;
+ byte b1 = 0;
+
+ if (l == 0) {
+ b1 = 1;
+ }
+
+ if (l == 1) {
+ b0 = -1;
+ }
+
+ if (l == 2) {
+ b1 = -1;
+ }
+
+ if (l == 3) {
+ b0 = 1;
+ }
+
+ int i1 = (world.getType(i - b0, j, k - b1).r() ? 1 : 0) + (world.getType(i - b0, j + 1, k - b1).r() ? 1 : 0);
+ int j1 = (world.getType(i + b0, j, k + b1).r() ? 1 : 0) + (world.getType(i + b0, j + 1, k + b1).r() ? 1 : 0);
+ boolean flag = world.getType(i - b0, j, k - b1) == block || world.getType(i - b0, j + 1, k - b1) == block;
+ boolean flag1 = world.getType(i + b0, j, k + b1) == block || world.getType(i + b0, j + 1, k + b1) == block;
+ boolean flag2 = false;
+
+ if (flag && !flag1) {
+ flag2 = true;
+ } else if (j1 > i1) {
+ flag2 = true;
+ }
+
+ world.setTypeAndData(i, j, k, block, l, 2);
+ world.setTypeAndData(i, j + 1, k, block, 8 | (flag2 ? 1 : 0), 2);
+ world.applyPhysics(i, j, k, block);
+ world.applyPhysics(i, j + 1, k, block);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/ItemSkull.java b/src/main/java/net/minecraft/server/ItemSkull.java
new file mode 100644
index 0000000..4a40068

View file

@ -0,0 +1,29 @@
From 1baf0b8ef94760b7e0dc1807a1f0f446231808f7 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Tue, 30 Sep 2014 21:43:15 +1000
Subject: [PATCH] Refactor ItemDoor Place
diff --git a/src/main/java/net/minecraft/server/ItemDoor.java b/src/main/java/net/minecraft/server/ItemDoor.java
index ee8568b..f585aa8 100644
--- a/src/main/java/net/minecraft/server/ItemDoor.java
+++ b/src/main/java/net/minecraft/server/ItemDoor.java
@@ -71,9 +71,11 @@ public class ItemDoor extends Item {
flag2 = true;
}
- world.setTypeAndData(i, j, k, block, l, 2);
- world.setTypeAndData(i, j + 1, k, block, 8 | (flag2 ? 1 : 0), 2);
- world.applyPhysics(i, j, k, block);
- world.applyPhysics(i, j + 1, k, block);
+ // Spigot start - update physics after the block multi place event
+ world.setTypeAndData(i, j, k, block, l, 3);
+ world.setTypeAndData(i, j + 1, k, block, 8 | (flag2 ? 1 : 0), 3);
+ // world.applyPhysics(i, j, k, block);
+ // world.applyPhysics(i, j + 1, k, block);
+ // Spigot end
}
}
--
1.9.1