ForgePatch/patches/minecraft/net/minecraft/network/NetServerHandler.java.patch

160 lines
7.6 KiB
Diff

--- ../src_base/minecraft/net/minecraft/network/NetServerHandler.java
+++ ../src_work/minecraft/net/minecraft/network/NetServerHandler.java
@@ -65,6 +65,13 @@
import net.minecraft.util.ReportedException;
import net.minecraft.world.WorldServer;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.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 NetServerHandler extends NetHandler
{
/** The underlying network manager for this server handler. */
@@ -238,6 +245,11 @@
if (this.playerEntity.ridingEntity != null)
{
this.playerEntity.ridingEntity.updateRiderPosition();
+ }
+
+ if (!this.hasMoved) //Fixes teleportation kick while riding entities
+ {
+ return;
}
this.mcServer.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity);
@@ -310,9 +322,9 @@
d4 = d1 - this.playerEntity.posX;
double d6 = d2 - this.playerEntity.posY;
double d7 = d3 - this.playerEntity.posZ;
- double d8 = Math.min(Math.abs(d4), Math.abs(this.playerEntity.motionX));
- double d9 = Math.min(Math.abs(d6), Math.abs(this.playerEntity.motionY));
- double d10 = Math.min(Math.abs(d7), Math.abs(this.playerEntity.motionZ));
+ double d8 = Math.max(Math.abs(d4), Math.abs(this.playerEntity.motionX));
+ double d9 = Math.max(Math.abs(d6), Math.abs(this.playerEntity.motionY));
+ double d10 = Math.max(Math.abs(d7), Math.abs(this.playerEntity.motionZ));
double d11 = d8 * d8 + d9 * d9 + d10 * d10;
if (d11 > 100.0D && (!this.mcServer.isSinglePlayer() || !this.mcServer.getServerOwner().equals(this.playerEntity.username)))
@@ -328,6 +340,11 @@
if (this.playerEntity.onGround && !par1Packet10Flying.onGround && d6 > 0.0D)
{
this.playerEntity.addExhaustion(0.2F);
+ }
+
+ if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
+ {
+ return;
}
this.playerEntity.moveEntity(d4, d6, d7);
@@ -352,10 +369,15 @@
this.mcServer.func_98033_al().func_98236_b(this.playerEntity.username + " moved wrongly!");
}
+ if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
+ {
+ return;
+ }
+
this.playerEntity.setPositionAndRotation(d1, d2, d3, f2, f3);
boolean flag2 = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)f4, (double)f4, (double)f4)).isEmpty();
- if (flag && (flag1 || !flag2) && !this.playerEntity.isPlayerSleeping())
+ if (flag && (flag1 || !flag2) && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.noClip)
{
this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, f2, f3);
return;
@@ -363,7 +385,7 @@
AxisAlignedBB axisalignedbb = this.playerEntity.boundingBox.copy().expand((double)f4, (double)f4, (double)f4).addCoord(0.0D, -0.55D, 0.0D);
- if (!this.mcServer.isFlightAllowed() && !this.playerEntity.theItemInWorldManager.isCreative() && !worldserver.isAABBNonEmpty(axisalignedbb))
+ if (!this.mcServer.isFlightAllowed() && !this.playerEntity.theItemInWorldManager.isCreative() && !worldserver.isAABBNonEmpty(axisalignedbb) && !this.playerEntity.capabilities.allowFlying)
{
if (d12 >= -0.03125D)
{
@@ -382,6 +404,11 @@
this.ticksForFloatKick = 0;
}
+ if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
+ {
+ return;
+ }
+
this.playerEntity.onGround = par1Packet10Flying.onGround;
this.mcServer.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity);
this.playerEntity.updateFlyingState(this.playerEntity.posY - d0, par1Packet10Flying.onGround);
@@ -448,7 +475,10 @@
double d2 = this.playerEntity.posZ - ((double)k + 0.5D);
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
- if (d3 > 36.0D)
+ double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1;
+ dist *= dist;
+
+ if (d3 > dist)
{
return;
}
@@ -508,7 +538,11 @@
return;
}
- this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack);
+ PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(playerEntity, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, 0, 0, 0, -1);
+ if (event.useItem != Event.Result.DENY)
+ {
+ this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack);
+ }
}
else if (par1Packet15Place.getYPosition() >= this.mcServer.getBuildLimit() - 1 && (par1Packet15Place.getDirection() == 1 || par1Packet15Place.getYPosition() >= this.mcServer.getBuildLimit()))
{
@@ -517,7 +551,9 @@
}
else
{
- if (this.hasMoved && this.playerEntity.getDistanceSq((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D) < 64.0D && !this.mcServer.func_96290_a(worldserver, i, j, k, this.playerEntity))
+ double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1;
+ dist *= dist;
+ if (this.hasMoved && this.playerEntity.getDistanceSq((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D) < dist && !this.mcServer.func_96290_a(worldserver, i, j, k, this.playerEntity))
{
this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, i, j, k, l, par1Packet15Place.getXOffset(), par1Packet15Place.getYOffset(), par1Packet15Place.getZOffset());
}
@@ -696,7 +732,14 @@
return;
}
+ String old = s;
s = "<" + this.playerEntity.func_96090_ax() + "> " + s;
+ ServerChatEvent event = new ServerChatEvent(this.playerEntity, old, s);
+ if (MinecraftForge.EVENT_BUS.post(event))
+ {
+ return;
+ }
+ s = event.line;
this.mcServer.func_98033_al().func_98233_a(s);
this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet3Chat(s, false));
}
@@ -827,7 +870,7 @@
return;
}
- this.playerEntity = this.mcServer.getConfigurationManager().respawnPlayer(this.playerEntity, 0, false);
+ this.playerEntity = this.mcServer.getConfigurationManager().respawnPlayer(this.playerEntity, playerEntity.dimension, false);
}
}
}
@@ -1225,7 +1268,6 @@
}
}
}
-
@Override