Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Commit

Permalink
Fix many issues with respawning + mini change to ChunkBlockHashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
robotia committed Mar 27, 2016
1 parent 7564381 commit 920b9f8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 36 deletions.
55 changes: 36 additions & 19 deletions patches/net/minecraft/network/NetHandlerPlayServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,15 @@
}
}
}
@@ -834,8 +1590,19 @@
@@ -828,14 +1584,26 @@
{
this.playerEntity.func_143004_u();
C16PacketClientStatus.EnumState enumstate = p_147342_1_.func_149435_c();
-
+
+ final boolean isDead = this.playerEntity.getHealth() <= 0.0F;
switch (NetHandlerPlayServer.SwitchEnumState.field_151290_a[enumstate.ordinal()])
{
case 1:
if (this.playerEntity.playerConqueredTheEnd)
{
Expand All @@ -1155,19 +1163,28 @@
+ if (this.playerEntity.dimension == 1) // coming from end
+ {
+ // We really should be calling transferPlayerToDimension since the player is coming in contact with a portal.
+ this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, 0, true); // set flag to indicate player is leaving end.
+ this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, 0, true, null, isDead); // set flag to indicate player is leaving end.
}
+ else
+ // not coming from end
+ {
+ this.playerEntity = this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, 0, false);
+ this.playerEntity = this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, 0, false, null, isDead);
+ }
+ // Cauldron end
+ }
else if (this.playerEntity.getServerForPlayer().getWorldInfo().isHardcoreModeEnabled())
{
if (this.serverController.isSinglePlayer() && this.playerEntity.getCommandSenderName().equals(this.serverController.getServerOwner()))
@@ -871,17 +1638,461 @@
@@ -857,7 +1625,7 @@
return;
}

- this.playerEntity = this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, playerEntity.dimension, false);
+ this.playerEntity = this.serverController.getConfigurationManager().respawnPlayer(this.playerEntity, playerEntity.dimension, false, null, isDead);
}

break;
@@ -871,17 +1639,461 @@

public void processCloseWindow(C0DPacketCloseWindow p_147356_1_)
{
Expand Down Expand Up @@ -1630,7 +1647,7 @@
if (ItemStack.areItemStacksEqual(p_147351_1_.func_149546_g(), itemstack))
{
this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(p_147351_1_.func_149548_c(), p_147351_1_.func_149547_f(), true));
@@ -903,6 +2114,12 @@
@@ -903,6 +2115,12 @@
}

this.playerEntity.sendContainerAndContentsToPlayer(this.playerEntity.openContainer, arraylist);
Expand All @@ -1643,7 +1660,7 @@
}
}
}
@@ -925,9 +2142,61 @@
@@ -925,9 +2143,61 @@
boolean flag = p_147344_1_.func_149627_c() < 0;
ItemStack itemstack = p_147344_1_.func_149625_d();
boolean flag1 = p_147344_1_.func_149627_c() >= 1 && p_147344_1_.func_149627_c() < 36 + InventoryPlayer.getHotbarSize();
Expand Down Expand Up @@ -1706,7 +1723,7 @@
if (flag1 && flag2 && flag3)
{
if (itemstack == null)
@@ -956,6 +2225,11 @@
@@ -956,6 +2226,11 @@

public void processConfirmTransaction(C0FPacketConfirmTransaction p_147339_1_)
{
Expand All @@ -1718,7 +1735,7 @@
Short oshort = (Short)this.field_147372_n.lookup(this.playerEntity.openContainer.windowId);

if (oshort != null && p_147339_1_.func_149533_d() == oshort.shortValue() && this.playerEntity.openContainer.windowId == p_147339_1_.func_149532_c() && !this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
@@ -966,6 +2240,11 @@
@@ -966,6 +2241,11 @@

public void processUpdateSign(C12PacketUpdateSign p_147343_1_)
{
Expand All @@ -1730,23 +1747,23 @@
this.playerEntity.func_143004_u();
WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);

@@ -980,6 +2259,7 @@
@@ -980,6 +2260,7 @@
if (!tileentitysign.func_145914_a() || tileentitysign.func_145911_b() != this.playerEntity)
{
this.serverController.logWarning("Player " + this.playerEntity.getCommandSenderName() + " just tried to change non-editable sign");
+ this.sendPacket(new S33PacketUpdateSign(p_147343_1_.func_149588_c(), p_147343_1_.func_149586_d(), p_147343_1_.func_149585_e(), tileentitysign.signText)); // CraftBukkit
return;
}
}
@@ -990,6 +2270,7 @@
@@ -990,6 +2271,7 @@
for (j = 0; j < 4; ++j)
{
boolean flag = true;
+ p_147343_1_.func_149589_f()[j] = p_147343_1_.func_149589_f()[j].replaceAll("\uF700", "").replaceAll("\uF701", ""); // Spigot - Mac OSX sends weird chars

if (p_147343_1_.func_149589_f()[j].length() > 15)
{
@@ -1018,7 +2299,29 @@
@@ -1018,7 +2300,29 @@
int k = p_147343_1_.func_149586_d();
i = p_147343_1_.func_149585_e();
TileEntitySign tileentitysign1 = (TileEntitySign)tileentity;
Expand Down Expand Up @@ -1777,7 +1794,7 @@
tileentitysign1.markDirty();
worldserver.markBlockForUpdate(j, k, i);
}
@@ -1041,7 +2344,22 @@
@@ -1041,7 +2345,22 @@

public void processPlayerAbilities(C13PacketPlayerAbilities p_147348_1_)
{
Expand All @@ -1801,7 +1818,7 @@
}

public void processTabComplete(C14PacketTabComplete p_147341_1_)
@@ -1093,16 +2411,18 @@
@@ -1093,16 +2412,18 @@
{
if (itemstack.getItem() == Items.writable_book && itemstack.getItem() == itemstack1.getItem())
{
Expand All @@ -1824,7 +1841,7 @@
}
finally
{
@@ -1135,19 +2455,18 @@
@@ -1135,19 +2456,18 @@

if (itemstack.getItem() == Items.written_book && itemstack1.getItem() == Items.writable_book)
{
Expand All @@ -1850,7 +1867,7 @@
}
finally
{
@@ -1174,9 +2493,12 @@
@@ -1174,9 +2494,12 @@
((ContainerMerchant)container).setCurrentRecipeIndex(i);
}
}
Expand All @@ -1864,7 +1881,7 @@
}
}
else if ("MC|AdvCdm".equals(p_147349_1_.func_149559_c()))
@@ -1222,9 +2544,12 @@
@@ -1222,9 +2545,12 @@
this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.setCommand.success", new Object[] {s1}));
}
}
Expand All @@ -1879,7 +1896,7 @@
}
finally
{
@@ -1257,9 +2582,12 @@
@@ -1257,9 +2583,12 @@
tileentitybeacon.markDirty();
}
}
Expand All @@ -1894,7 +1911,7 @@
}
}
}
@@ -1281,6 +2609,13 @@
@@ -1281,6 +2610,13 @@
containerrepair.updateItemName("");
}
}
Expand All @@ -1908,7 +1925,7 @@
}
}

@@ -1292,6 +2627,21 @@
@@ -1292,6 +2628,21 @@
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
public EntityPlayerMP createPlayerForUser(GameProfile p_148545_1_)
{
UUID uuid = EntityPlayer.func_146094_a(p_148545_1_);
@@ -410,80 +628,305 @@
@@ -410,80 +628,307 @@
return new EntityPlayerMP(this.mcServer, this.mcServer.worldServerForDimension(0), p_148545_1_, (ItemInWorldManager)object);
}

Expand Down Expand Up @@ -478,11 +478,9 @@
+ }
+
+ // Cauldron start - refactor entire method for sanity.
+ public EntityPlayerMP respawnPlayer(EntityPlayerMP par1EntityPlayerMP, int par2, boolean par3)
+ public EntityPlayerMP respawnPlayer(EntityPlayerMP par1EntityPlayerMP, int par2)
+ {
+ boolean isdeath = true;
+ if(par3) isdeath = false;
+ return this.respawnPlayer(par1EntityPlayerMP, par2, par3, null, isdeath);
+ return this.respawnPlayer(par1EntityPlayerMP, par2, false, null, false);
+ }
+
+ public EntityPlayerMP respawnPlayer(EntityPlayerMP par1EntityPlayerMP, int targetDimension, boolean returnFromEnd, Location location, boolean isdeath)
Expand Down Expand Up @@ -561,8 +559,7 @@
+ CraftPlayer cp = (CraftPlayer)par1EntityPlayerMP.bukkitEntity;
+ if ( cp != null )
+ {
+ try { cp.enderChest.inventory = entityplayermp1.getInventoryEnderChest(); } catch(Exception e) {cp.enderChest = new CraftInventory(entityplayermp1.getInventoryEnderChest());}
+ try { cp.inventory.inventory = entityplayermp1.inventory; } catch(Exception e) {cp.inventory = new CraftInventoryPlayer(entityplayermp1.inventory); }
+
+ entityplayermp1.bukkitEntity = cp;
+ cp.setHandle(entityplayermp1);
+ }
Expand Down Expand Up @@ -710,6 +707,11 @@
+ }
+ else entityplayermp1.clonePlayer(par1EntityPlayerMP, returnFromEnd);
+
+ if(cp != null){
+ try { cp.enderChest.inventory = entityplayermp1.getInventoryEnderChest(); } catch(Exception e) {cp.enderChest = new CraftInventory(entityplayermp1.getInventoryEnderChest());}
+ try { cp.inventory.inventory = entityplayermp1.inventory; } catch(Exception e) {cp.inventory = new CraftInventoryPlayer(entityplayermp1.inventory); }
+ }
+
+ // CraftBukkit end
+ //Forge same
entityplayermp1.playerNetServerHandler.sendPacket(new S05PacketSpawnPosition(chunkcoordinates1.posX, chunkcoordinates1.posY, chunkcoordinates1.posZ));
Expand Down Expand Up @@ -754,7 +756,7 @@
return entityplayermp1;
}

@@ -492,34 +935,112 @@
@@ -492,34 +937,112 @@
transferPlayerToDimension(p_72356_1_, p_72356_2_, mcServer.worldServerForDimension(p_72356_2_).getDefaultTeleporter());
}

Expand Down Expand Up @@ -887,7 +889,7 @@
}

public void transferEntityToWorld(Entity p_82448_1_, int p_82448_2_, WorldServer p_82448_3_, WorldServer p_82448_4_, Teleporter teleporter)
@@ -605,6 +1126,109 @@
@@ -605,6 +1128,109 @@
p_82448_1_.setWorld(p_82448_4_);
}

Expand Down Expand Up @@ -997,7 +999,7 @@
public void sendPlayerInfoToAllPlayers()
{
if (++this.playerPingIndex > 600)
@@ -612,11 +1236,13 @@
@@ -612,11 +1238,13 @@
this.playerPingIndex = 0;
}

Expand All @@ -1011,7 +1013,7 @@
}

public void sendPacketToAllPlayers(Packet p_148540_1_)
@@ -877,13 +1503,24 @@
@@ -877,13 +1505,24 @@
for (int j = 0; j < this.playerEntityList.size(); ++j)
{
EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntityList.get(j);
Expand All @@ -1038,7 +1040,7 @@
if (d4 * d4 + d5 * d5 + d6 * d6 < p_148543_8_ * p_148543_8_)
{
entityplayermp.playerNetServerHandler.sendPacket(p_148543_11_);
@@ -941,13 +1578,16 @@
@@ -941,13 +1580,16 @@
p_72354_1_.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(1, 0.0F));
p_72354_1_.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(7, p_72354_2_.getRainStrength(1.0F)));
p_72354_1_.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(8, p_72354_2_.getWeightedThunderStrength(1.0F)));
Expand All @@ -1056,7 +1058,7 @@
p_72385_1_.playerNetServerHandler.sendPacket(new S09PacketHeldItemChange(p_72385_1_.inventory.currentItem));
}

@@ -961,9 +1601,17 @@
@@ -961,9 +1603,17 @@
return this.maxPlayers;
}

Expand All @@ -1075,7 +1077,7 @@
}

public void setWhiteListEnabled(boolean p_72371_1_)
@@ -1032,12 +1680,30 @@
@@ -1032,12 +1682,30 @@

public void removeAllPlayers()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ public void respawn()
{
if ( getHealth() <= 0 && isOnline() )
{
server.getServer().getConfigurationManager().respawnPlayer( getHandle(), 0, false );
server.getServer().getConfigurationManager().respawnPlayer( getHandle(), 0 );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.server.S07PacketRespawn;
import net.minecraft.network.play.server.S1DPacketEntityEffect;
import net.minecraft.network.play.server.S1FPacketSetExperience;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.util.MathHelper;
Expand Down Expand Up @@ -77,6 +78,8 @@ public static void transferPlayerToDimension(EntityPlayerMP player, int dim, Ser
// Cauldron end
player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dim, worldserver1.difficultySetting, worldserver1.getWorldInfo()
.getTerrainType(), player.theItemInWorldManager.getGameType()));
player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));

worldserver.removePlayerEntityDangerously(player);
if (player.riddenByEntity != null) {
player.riddenByEntity.mountEntity(null);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/thermos/wrapper/ChunkBlockHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public class ChunkBlockHashMap {
public static long chunk_hash(int x, int z)
{
//return ((x & 0xFFFF) << 16) | (z & 0xFFFF);
long key = LongHash.toLong(x, z);
return LongHash.toLong((int) (key & 0xFFFFFFFFL), (int) (key >>> 32));
// long key = LongHash.toLong(x, z);
// return LongHash.toLong((int) (key & 0xFFFFFFFFL), (int) (key >>> 32));
return (((long)x)<<32L)^z;
}

private static int chunk_array(int index)
Expand Down

0 comments on commit 920b9f8

Please sign in to comment.