Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CB respawn logic #913

Open
wants to merge 1 commit into
base: 1.12.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 70 additions & 52 deletions patches/net/minecraft/entity/Entity.java.patch

Large diffs are not rendered by default.

144 changes: 75 additions & 69 deletions patches/net/minecraft/entity/EntityLivingBase.java.patch

Large diffs are not rendered by default.

158 changes: 84 additions & 74 deletions patches/net/minecraft/entity/player/EntityPlayer.java.patch

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
@@ -26,7 +28,7 @@
@@ -26,9 +28,9 @@
private static final Logger LOGGER = LogManager.getLogger();
private static final Map < Class <? extends Entity > , Integer > NEXT_ID_MAP = Maps. < Class <? extends Entity > , Integer > newHashMap();
private final Entity entity;
- private final Map < Integer, EntityDataManager.DataEntry<? >> entries = Maps. < Integer, EntityDataManager.DataEntry<? >> newHashMap();
+ private final Map < Integer, DataEntry<? >> entries = new Int2ObjectOpenHashMap<>(); // Paper
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private boolean empty = true;
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
- private boolean empty = true;
+ public final Map < Integer, DataEntry<? >> entries = new Int2ObjectOpenHashMap<>(); // Paper // CatServer - private -> public
+ public final ReadWriteLock lock = new ReentrantReadWriteLock(); // CatServer - private -> public
+ public boolean empty = true; // CatServer - private -> public
private boolean dirty;

public EntityDataManager(Entity entityIn)
@@ -38,7 +40,7 @@

public static <T> DataParameter<T> createKey(Class <? extends Entity > clazz, DataSerializer<T> serializer)
Expand Down
50 changes: 26 additions & 24 deletions patches/net/minecraft/server/management/PlayerList.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -617,18 +617,20 @@
playerIn.dimension = dimension;
PlayerInteractionManager playerinteractionmanager;

@@ -493,8 +848,20 @@
@@ -493,8 +848,22 @@
}

EntityPlayerMP entityplayermp = new EntityPlayerMP(this.mcServer, this.mcServer.getWorld(playerIn.dimension), playerIn.getGameProfile(), playerinteractionmanager);
+ */
+ EntityPlayerMP entityplayermp = playerIn;
+ // CatServer start - Call construct event and re-gather capabilities
+ if (catserver.server.CatServer.getConfig().callConstructCapabilityEventOnRespawn) {
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(entityplayermp));
+ ((Entity) entityplayermp).capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(entityplayermp);
+ // CatServer start - Fix CB respawn logic
+ if (catserver.server.CatServer.getConfig().simulateVanillaRespawn) {
+ catserver.server.utils.ModFixUtils.simulateVanillaRespawn(entityplayermp);
+ }
+ // CatServer end - Call construct event and re-gather capabilities
+ if (catserver.server.CatServer.getConfig().regatherCapabilityOnRespawn) {
+ catserver.server.utils.ModFixUtils.regatherCapabilities(entityplayermp);
+ }
+ // CatServer end - Fix CB respawn logic
+ org.bukkit.World fromWorld = playerIn.getBukkitEntity().getWorld();
+ playerIn.queuedEndExit = false;
+
Expand All @@ -638,7 +640,7 @@
entityplayermp.setEntityId(playerIn.getEntityId());
entityplayermp.setCommandStats(playerIn);
entityplayermp.setPrimaryHand(playerIn.getPrimaryHand());
@@ -504,44 +871,103 @@
@@ -504,44 +873,103 @@
entityplayermp.addTag(s);
}

Expand Down Expand Up @@ -763,7 +765,7 @@
return entityplayermp;
}

@@ -549,44 +975,125 @@
@@ -549,44 +977,125 @@
{
GameProfile gameprofile = player.getGameProfile();
int i = this.canSendCommands(gameprofile) ? this.ops.getPermissionLevel(gameprofile) : 0;
Expand Down Expand Up @@ -902,7 +904,7 @@
{
d0 = MathHelper.clamp(d0 / 8.0D, toWorldIn.getWorldBorder().minX() + 16.0D, toWorldIn.getWorldBorder().maxX() - 16.0D);
d1 = MathHelper.clamp(d1 / 8.0D, toWorldIn.getWorldBorder().minZ() + 16.0D, toWorldIn.getWorldBorder().maxZ() - 16.0D);
@@ -597,7 +1104,7 @@
@@ -597,7 +1106,7 @@
oldWorldIn.updateEntityWithOptionalForce(entityIn, false);
}
}
Expand All @@ -911,7 +913,7 @@
{
d0 = MathHelper.clamp(d0 * 8.0D, toWorldIn.getWorldBorder().minX() + 16.0D, toWorldIn.getWorldBorder().maxX() - 16.0D);
d1 = MathHelper.clamp(d1 * 8.0D, toWorldIn.getWorldBorder().minZ() + 16.0D, toWorldIn.getWorldBorder().maxZ() - 16.0D);
@@ -608,7 +1115,7 @@
@@ -608,7 +1117,7 @@
oldWorldIn.updateEntityWithOptionalForce(entityIn, false);
}
}
Expand All @@ -920,7 +922,7 @@
{
BlockPos blockpos;

@@ -634,7 +1141,7 @@
@@ -634,7 +1143,7 @@

oldWorldIn.profiler.endSection();

Expand All @@ -929,7 +931,7 @@
{
oldWorldIn.profiler.startSection("placing");
d0 = (double)MathHelper.clamp((int)d0, -29999872, 29999872);
@@ -643,7 +1150,8 @@
@@ -643,7 +1152,8 @@
if (entityIn.isEntityAlive())
{
entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
Expand All @@ -939,7 +941,7 @@
toWorldIn.spawnEntity(entityIn);
toWorldIn.updateEntityWithOptionalForce(entityIn, false);
}
@@ -654,11 +1162,155 @@
@@ -654,11 +1164,155 @@
entityIn.setWorld(toWorldIn);
}

Expand Down Expand Up @@ -1096,7 +1098,7 @@
this.playerPingIndex = 0;
}
}
@@ -671,6 +1323,24 @@
@@ -671,6 +1325,24 @@
}
}

Expand All @@ -1121,7 +1123,7 @@
public void sendPacketToAllPlayersInDimension(Packet<?> packetIn, int dimension)
{
for (int i = 0; i < this.playerEntityList.size(); ++i)
@@ -786,12 +1456,20 @@
@@ -786,12 +1458,20 @@
int i = this.mcServer.getOpPermissionLevel();
this.ops.addEntry(new UserListOpsEntry(profile, this.mcServer.getOpPermissionLevel(), this.ops.bypassesPlayerLimit(profile)));
this.sendPlayerPermissionLevel(this.getPlayerByUUID(profile.getId()), i);
Expand All @@ -1142,7 +1144,7 @@
}

private void sendPlayerPermissionLevel(EntityPlayerMP player, int permLevel)
@@ -824,7 +1502,7 @@
@@ -824,7 +1504,7 @@

public boolean canSendCommands(GameProfile profile)
{
Expand All @@ -1151,7 +1153,7 @@
}

@Nullable
@@ -847,6 +1525,12 @@
@@ -847,6 +1527,12 @@
{
EntityPlayerMP entityplayermp = this.playerEntityList.get(i);

Expand All @@ -1164,7 +1166,7 @@
if (entityplayermp != except && entityplayermp.dimension == dimension)
{
double d0 = x - entityplayermp.posX;
@@ -905,7 +1589,7 @@
@@ -905,7 +1591,7 @@

public void updateTimeAndWeatherForPlayer(EntityPlayerMP playerIn, WorldServer worldIn)
{
Expand All @@ -1173,7 +1175,7 @@
playerIn.connection.sendPacket(new SPacketWorldBorder(worldborder, SPacketWorldBorder.Action.INITIALIZE));
playerIn.connection.sendPacket(new SPacketTimeUpdate(worldIn.getTotalWorldTime(), worldIn.getWorldTime(), worldIn.getGameRules().getBoolean("doDaylightCycle")));
BlockPos blockpos = worldIn.getSpawnPoint();
@@ -913,16 +1597,21 @@
@@ -913,16 +1599,21 @@

if (worldIn.isRaining())
{
Expand All @@ -1199,7 +1201,7 @@
playerIn.connection.sendPacket(new SPacketHeldItemChange(playerIn.inventory.currentItem));
}

@@ -938,7 +1627,7 @@
@@ -938,7 +1629,7 @@

public String[] getAvailablePlayerDat()
{
Expand All @@ -1208,7 +1210,7 @@
}

public void setWhiteListEnabled(boolean whitelistEnabled)
@@ -1004,17 +1693,26 @@
@@ -1004,17 +1695,26 @@

public void removeAllPlayers()
{
Expand Down Expand Up @@ -1239,15 +1241,15 @@
}

public void sendMessage(ITextComponent component)
@@ -1022,6 +1720,7 @@
@@ -1022,6 +1722,7 @@
this.sendMessage(component, true);
}

+ @Nullable
public StatisticsManagerServer getPlayerStatsFile(EntityPlayer playerIn)
{
UUID uuid = playerIn.getUniqueID();
@@ -1050,6 +1749,8 @@
@@ -1050,6 +1751,8 @@
return statisticsmanagerserver;
}

Expand All @@ -1256,7 +1258,7 @@
public PlayerAdvancements getPlayerAdvancements(EntityPlayerMP p_192054_1_)
{
UUID uuid = p_192054_1_.getUniqueID();
@@ -1073,7 +1774,7 @@
@@ -1073,7 +1776,7 @@

if (this.mcServer.worlds != null)
{
Expand Down
2 changes: 1 addition & 1 deletion patches/net/minecraft/world/Explosion.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- private final Entity exploder;
- private final float size;
+ public final Entity exploder;
+ public float size; // CatServer - private final -> public
+ public final float size; // CatServer - private -> public
private final List<BlockPos> affectedBlockPositions;
private final Map<EntityPlayer, Vec3d> playerKnockbackMap;
+ private final Vec3d position;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/catserver/server/CatServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public class CatServerConfig {
public boolean disableAsyncCatchWarn = false;
public boolean versionCheck = true;

public boolean regatherCapabilityOnRespawn = false;
public boolean simulateVanillaRespawn = false;
public boolean bridgeForgeExplosionEventToBukkit = false;
public boolean callConstructCapabilityEventOnRespawn = false;

public CatServerConfig(String file) {
this.configFile = new File(file);
Expand Down Expand Up @@ -107,8 +108,9 @@ public void loadConfig() {
disableFMLHandshake = getOrWriteBooleanConfig("network.fml.disableHandshake", config.getBoolean("disableFMLHandshake", disableFMLHandshake));
disableFMLStatusModInfo = getOrWriteBooleanConfig("network.fml.disableStatusModInfo", config.getBoolean("disableFMLStatusModInfo", disableFMLStatusModInfo));
// compatibility
regatherCapabilityOnRespawn = getOrWriteBooleanConfig("compatibility.regatherCapabilityOnRespawn", regatherCapabilityOnRespawn);
simulateVanillaRespawn = getOrWriteBooleanConfig("compatibility.simulateVanillaRespawn", simulateVanillaRespawn);
bridgeForgeExplosionEventToBukkit = getOrWriteBooleanConfig("compatibility.bridgeForgeExplosionEventToBukkit", bridgeForgeExplosionEventToBukkit);
callConstructCapabilityEventOnRespawn = getOrWriteBooleanConfig("compatibility.callConstructCapabilityEventOnRespawn", callConstructCapabilityEventOnRespawn);
// general
disableUpdateGameProfile = getOrWriteBooleanConfig("disableUpdateGameProfile", disableUpdateGameProfile);
disableAsyncCatchWarn = getOrWriteBooleanConfig("disableAsyncCatchWarn", disableAsyncCatchWarn);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/catserver/server/CatServerEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void onExplode(ExplosionEvent.Detonate event) {
Location location = new Location(bworld, explosionPos.x, explosionPos.y, explosionPos.z);
List<Block> bukkitBlocks;
boolean cancelled;
float yield;
final List<Block> blockList = Lists.newArrayList();
List<BlockPos> affectedBlockPositions = event.getAffectedBlocks();
for (int i1 = affectedBlockPositions.size() - 1; i1 >= 0; i1--) {
Expand All @@ -103,13 +102,11 @@ public void onExplode(ExplosionEvent.Detonate event) {
Bukkit.getServer().getPluginManager().callEvent(bukkitEvent);
cancelled = bukkitEvent.isCancelled();
bukkitBlocks = bukkitEvent.blockList();
yield = bukkitEvent.getYield();
} else {
BlockExplodeEvent bukkitEvent = new BlockExplodeEvent(location.getBlock(), blockList, 1.0F / explosion.size);
Bukkit.getServer().getPluginManager().callEvent(bukkitEvent);
cancelled = bukkitEvent.isCancelled();
bukkitBlocks = bukkitEvent.blockList();
yield = bukkitEvent.getYield();
}
explosion.getAffectedBlockPositions().clear();

Expand All @@ -121,7 +118,6 @@ public void onExplode(ExplosionEvent.Detonate event) {
BlockPos coords = new BlockPos(bblock.getX(), bblock.getY(), bblock.getZ());
explosion.getAffectedBlockPositions().add(coords);
}
explosion.size = yield * explosion.size;
}
}
}
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/catserver/server/utils/ModFixUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package catserver.server.utils;

import catserver.server.CatServer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.fml.common.Loader;
import org.bukkit.craftbukkit.entity.CraftPlayer;

Expand Down Expand Up @@ -43,4 +50,66 @@ else if (health > cbPlayer.getMaxHealth()) {
}
}
}

public static void simulateVanillaRespawn(EntityPlayerMP playerIn) {
final EntityDataManager dataManager = playerIn.getDataManager();
// Capture vanilla values
// Entity
byte capturedFlags = dataManager.get(Entity.FLAGS);
int capturedAirTicks = dataManager.get(Entity.AIR);
String capturedCustomName = dataManager.get(Entity.CUSTOM_NAME);
boolean capturedCustomNameVisible = dataManager.get(Entity.CUSTOM_NAME_VISIBLE);
boolean capturedSilent = dataManager.get(Entity.SILENT);
boolean capturedNoGravity = dataManager.get(Entity.NO_GRAVITY);
// EntityLivingBase
byte capturedHandStates = dataManager.get(EntityLivingBase.HAND_STATES);
float capturedHealth = dataManager.get(EntityLivingBase.HEALTH);
int capturedPotionEffects = dataManager.get(EntityLivingBase.POTION_EFFECTS);
boolean capturedHideParticles = dataManager.get(EntityLivingBase.HIDE_PARTICLES);
int capturedArrowCount = dataManager.get(EntityLivingBase.ARROW_COUNT_IN_ENTITY);
// EntityPlayer
float capturedAbsorptionAmount = dataManager.get(EntityPlayer.ABSORPTION);
int capturedScore = dataManager.get(EntityPlayer.PLAYER_SCORE);
byte capturedPlayerModelFlag = dataManager.get(EntityPlayer.PLAYER_MODEL_FLAG);
byte capturedMainHand = dataManager.get(EntityPlayer.MAIN_HAND);
NBTTagCompound capturedLeftShoulder = dataManager.get(EntityPlayer.LEFT_SHOULDER_ENTITY);
NBTTagCompound capturedRightShoulder = dataManager.get(EntityPlayer.RIGHT_SHOULDER_ENTITY);

try {
dataManager.lock.writeLock().lock();
dataManager.entries.clear();
} finally {
dataManager.lock.writeLock().unlock();
}
dataManager.empty = true;
dataManager.setClean();

// Restore captured vanilla values
// Entity
dataManager.register(Entity.FLAGS, capturedFlags);
dataManager.register(Entity.AIR, capturedAirTicks);
dataManager.register(Entity.CUSTOM_NAME, capturedCustomName);
dataManager.register(Entity.CUSTOM_NAME_VISIBLE, capturedCustomNameVisible);
dataManager.register(Entity.SILENT, capturedSilent);
dataManager.register(Entity.NO_GRAVITY, capturedNoGravity);
// EntityLivingBase
dataManager.register(EntityLivingBase.HAND_STATES, capturedHandStates);
dataManager.register(EntityLivingBase.HEALTH, capturedHealth);
dataManager.register(EntityLivingBase.POTION_EFFECTS, capturedPotionEffects);
dataManager.register(EntityLivingBase.HIDE_PARTICLES, capturedHideParticles);
dataManager.register(EntityLivingBase.ARROW_COUNT_IN_ENTITY, capturedArrowCount);
// EntityPlayer
dataManager.register(EntityPlayer.ABSORPTION, capturedAbsorptionAmount);
dataManager.register(EntityPlayer.PLAYER_SCORE, capturedScore);
dataManager.register(EntityPlayer.PLAYER_MODEL_FLAG, capturedPlayerModelFlag);
dataManager.register(EntityPlayer.MAIN_HAND, capturedMainHand);
dataManager.register(EntityPlayer.LEFT_SHOULDER_ENTITY, capturedLeftShoulder);
dataManager.register(EntityPlayer.RIGHT_SHOULDER_ENTITY, capturedRightShoulder);

MinecraftForge.EVENT_BUS.post(new EntityEvent.EntityConstructing(playerIn));
}

public static void regatherCapabilities(EntityPlayerMP playerIn) {
((Entity) playerIn).capabilities = ForgeEventFactory.gatherCapabilities(playerIn);
}
}