mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 12:20:11 +00:00
Before calling "ItemStack.tryPlaceItemInWorld", a recording flag is turned on for setBlock to capture a blocksnapshot for each block that attempts to be placed. If 1 block is captured, a "BlockEvent.PlaceEvent" is fired to notify mods. If 2 or more blocks are captured, a "BlockEvent.PlaceEvent" is fired first with the first block captured followed by a "BlockEvent.MultiPlaceEvent" with all captured blocks. This extra event is required for items that have the ability to place 2 or more blocks such as a BlockBed. If either event is cancelled, the recorded block snapshot(s), item stacksize, and item meta will revert back to the captured snapshot(s). If the events are not cancelled, a notification will be sent to clients and block physics will be updated. What this means for mods is Forge will be able to capture all player block placement automatically and fire a PlaceEvent and/or MultiPlaceEvent. If for whatever reason your mod does not use the standard placement methods then you will need to fire the appropriate placement events in order to notify mods/servers. This commit also includes a new utility class called BlockSnapshot which is serializable. This new class is used in conjunction with both PlaceEvent and MultiPlaceEvent in order to record a snapshot of block space before it is altered. This allows us to restore the block(s) if an event is cancelled. The class also provides the ability to restore a snapshot to any location using the restoreToLocation method. This should be helpful to many mods that are looking to be able to capture block data then restore it to back to any location required.
172 lines
9.2 KiB
Diff
172 lines
9.2 KiB
Diff
--- ../src-base/minecraft/net/minecraft/network/NetHandlerPlayServer.java
|
|
+++ ../src-work/minecraft/net/minecraft/network/NetHandlerPlayServer.java
|
|
@@ -86,6 +86,14 @@
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
+import net.minecraftforge.common.ForgeHooks;
|
|
+import net.minecraftforge.common.MinecraftForge;
|
|
+import cpw.mods.fml.common.eventhandler.Event;
|
|
+import net.minecraftforge.event.ForgeEventFactory;
|
|
+import net.minecraftforge.event.ServerChatEvent;
|
|
+import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
+import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
|
+
|
|
public class NetHandlerPlayServer implements INetHandlerPlayServer
|
|
{
|
|
private static final Logger field_147370_c = LogManager.getLogger();
|
|
@@ -222,6 +230,11 @@
|
|
this.field_147369_b.field_70154_o.func_70043_V();
|
|
}
|
|
|
|
+ if (!this.field_147380_r) //Fixes teleportation kick while riding entities
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
this.field_147367_d.func_71203_ab().func_72358_d(this.field_147369_b);
|
|
|
|
if (this.field_147380_r)
|
|
@@ -299,9 +312,10 @@
|
|
d4 = d1 - this.field_147369_b.field_70165_t;
|
|
double d5 = d2 - this.field_147369_b.field_70163_u;
|
|
double d6 = d3 - this.field_147369_b.field_70161_v;
|
|
- double d7 = Math.min(Math.abs(d4), Math.abs(this.field_147369_b.field_70159_w));
|
|
- double d8 = Math.min(Math.abs(d5), Math.abs(this.field_147369_b.field_70181_x));
|
|
- double d9 = Math.min(Math.abs(d6), Math.abs(this.field_147369_b.field_70179_y));
|
|
+ //BUGFIX: min -> max, grabs the highest distance
|
|
+ double d7 = Math.max(Math.abs(d4), Math.abs(this.field_147369_b.field_70159_w));
|
|
+ double d8 = Math.max(Math.abs(d5), Math.abs(this.field_147369_b.field_70181_x));
|
|
+ double d9 = Math.max(Math.abs(d6), Math.abs(this.field_147369_b.field_70179_y));
|
|
double d10 = d7 * d7 + d8 * d8 + d9 * d9;
|
|
|
|
if (d10 > 100.0D && (!this.field_147367_d.func_71264_H() || !this.field_147367_d.func_71214_G().equals(this.field_147369_b.func_70005_c_())))
|
|
@@ -319,6 +333,11 @@
|
|
this.field_147369_b.func_70664_aZ();
|
|
}
|
|
|
|
+ if (!this.field_147380_r) //Fixes "Moved Too Fast" kick when being teleported while moving
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
this.field_147369_b.func_70091_d(d4, d5, d6);
|
|
this.field_147369_b.field_70122_E = p_147347_1_.func_149465_i();
|
|
this.field_147369_b.func_71000_j(d4, d5, d6);
|
|
@@ -341,10 +360,15 @@
|
|
field_147370_c.warn(this.field_147369_b.func_70005_c_() + " moved wrongly!");
|
|
}
|
|
|
|
+ if (!this.field_147380_r) //Fixes "Moved Too Fast" kick when being teleported while moving
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
this.field_147369_b.func_70080_a(d1, d2, d3, f1, f2);
|
|
boolean flag2 = worldserver.func_72945_a(this.field_147369_b, this.field_147369_b.field_70121_D.func_72329_c().func_72331_e((double)f3, (double)f3, (double)f3)).isEmpty();
|
|
|
|
- if (flag && (flag1 || !flag2) && !this.field_147369_b.func_70608_bn())
|
|
+ if (flag && (flag1 || !flag2) && !this.field_147369_b.func_70608_bn() && !this.field_147369_b.field_70145_X)
|
|
{
|
|
this.func_147364_a(this.field_147373_o, this.field_147382_p, this.field_147381_q, f1, f2);
|
|
return;
|
|
@@ -352,7 +376,7 @@
|
|
|
|
AxisAlignedBB axisalignedbb = this.field_147369_b.field_70121_D.func_72329_c().func_72314_b((double)f3, (double)f3, (double)f3).func_72321_a(0.0D, -0.55D, 0.0D);
|
|
|
|
- if (!this.field_147367_d.func_71231_X() && !this.field_147369_b.field_71134_c.func_73083_d() && !worldserver.func_72829_c(axisalignedbb))
|
|
+ if (!this.field_147367_d.func_71231_X() && !this.field_147369_b.field_71134_c.func_73083_d() && !worldserver.func_72829_c(axisalignedbb) && !this.field_147369_b.field_71075_bZ.field_75101_c)
|
|
{
|
|
if (d11 >= -0.03125D)
|
|
{
|
|
@@ -371,6 +395,11 @@
|
|
this.field_147365_f = 0;
|
|
}
|
|
|
|
+ if (!this.field_147380_r) //Fixes "Moved Too Fast" kick when being teleported while moving
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
this.field_147369_b.field_70122_E = p_147347_1_.func_149465_i();
|
|
this.field_147367_d.func_71203_ab().func_72358_d(this.field_147369_b);
|
|
this.field_147369_b.func_71122_b(this.field_147369_b.field_70163_u - d0, p_147347_1_.func_149465_i());
|
|
@@ -439,7 +468,10 @@
|
|
double d2 = this.field_147369_b.field_70161_v - ((double)k + 0.5D);
|
|
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
|
|
|
|
- if (d3 > 36.0D)
|
|
+ double dist = field_147369_b.field_71134_c.getBlockReachDistance() + 1;
|
|
+ dist *= dist;
|
|
+
|
|
+ if (d3 > dist)
|
|
{
|
|
return;
|
|
}
|
|
@@ -487,6 +519,7 @@
|
|
WorldServer worldserver = this.field_147367_d.func_71218_a(this.field_147369_b.field_71093_bK);
|
|
ItemStack itemstack = this.field_147369_b.field_71071_by.func_70448_g();
|
|
boolean flag = false;
|
|
+ boolean placeResult = true;
|
|
int i = p_147346_1_.func_149576_c();
|
|
int j = p_147346_1_.func_149571_d();
|
|
int k = p_147346_1_.func_149570_e();
|
|
@@ -500,7 +533,11 @@
|
|
return;
|
|
}
|
|
|
|
- this.field_147369_b.field_71134_c.func_73085_a(this.field_147369_b, worldserver, itemstack);
|
|
+ PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(field_147369_b, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, 0, 0, 0, -1, worldserver);
|
|
+ if (event.useItem != Event.Result.DENY)
|
|
+ {
|
|
+ this.field_147369_b.field_71134_c.func_73085_a(this.field_147369_b, worldserver, itemstack);
|
|
+ }
|
|
}
|
|
else if (p_147346_1_.func_149571_d() >= this.field_147367_d.func_71207_Z() - 1 && (p_147346_1_.func_149568_f() == 1 || p_147346_1_.func_149571_d() >= this.field_147367_d.func_71207_Z()))
|
|
{
|
|
@@ -511,9 +548,15 @@
|
|
}
|
|
else
|
|
{
|
|
- if (this.field_147380_r && this.field_147369_b.func_70092_e((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D) < 64.0D && !this.field_147367_d.func_96290_a(worldserver, i, j, k, this.field_147369_b))
|
|
+ double dist = field_147369_b.field_71134_c.getBlockReachDistance() + 1;
|
|
+ dist *= dist;
|
|
+ if (this.field_147380_r && this.field_147369_b.func_70092_e((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D) < dist && !this.field_147367_d.func_96290_a(worldserver, i, j, k, this.field_147369_b))
|
|
{
|
|
- this.field_147369_b.field_71134_c.func_73078_a(this.field_147369_b, worldserver, itemstack, i, j, k, l, p_147346_1_.func_149573_h(), p_147346_1_.func_149569_i(), p_147346_1_.func_149575_j());
|
|
+ // record block place result so we can update client itemstack size if place event was cancelled.
|
|
+ if (!this.field_147369_b.field_71134_c.func_73078_a(this.field_147369_b, worldserver, itemstack, i, j, k, l, p_147346_1_.func_149573_h(), p_147346_1_.func_149569_i(), p_147346_1_.func_149575_j()))
|
|
+ {
|
|
+ placeResult = false;
|
|
+ }
|
|
}
|
|
|
|
flag = true;
|
|
@@ -572,7 +615,7 @@
|
|
this.field_147369_b.field_71070_bA.func_75142_b();
|
|
this.field_147369_b.field_71137_h = false;
|
|
|
|
- if (!ItemStack.func_77989_b(this.field_147369_b.field_71071_by.func_70448_g(), p_147346_1_.func_149574_g()))
|
|
+ if (!ItemStack.func_77989_b(this.field_147369_b.field_71071_by.func_70448_g(), p_147346_1_.func_149574_g()) || !placeResult) // force client itemstack update if place event was cancelled
|
|
{
|
|
this.func_147359_a(new S2FPacketSetSlot(this.field_147369_b.field_71070_bA.field_75152_c, slot.field_75222_d, this.field_147369_b.field_71071_by.func_70448_g()));
|
|
}
|
|
@@ -677,6 +720,8 @@
|
|
else
|
|
{
|
|
ChatComponentTranslation chatcomponenttranslation1 = new ChatComponentTranslation("chat.type.text", new Object[] {this.field_147369_b.func_145748_c_(), s});
|
|
+ chatcomponenttranslation1 = ForgeHooks.onServerChatEvent(this, s, chatcomponenttranslation1);
|
|
+ if (chatcomponenttranslation1 == null) return;
|
|
this.field_147367_d.func_71203_ab().func_148544_a(chatcomponenttranslation1, false);
|
|
}
|
|
|
|
@@ -812,7 +857,7 @@
|
|
return;
|
|
}
|
|
|
|
- this.field_147369_b = this.field_147367_d.func_71203_ab().func_72368_a(this.field_147369_b, 0, false);
|
|
+ this.field_147369_b = this.field_147367_d.func_71203_ab().func_72368_a(this.field_147369_b, field_147369_b.field_71093_bK, false);
|
|
}
|
|
|
|
break;
|