Skip to content

Commit

Permalink
Simulate vanilla respawn
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Jan 5, 2025
1 parent 7f3ed82 commit c8577c3
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/wdsj/hybridfix/HybridFixPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class HybridFixPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader {
{
{
if (!HAS_CLEANROOM) {
put("mixins.fix.capability.json", () -> Settings.fixCapabilityReset);
put("mixins.fix.capability.json", () -> Settings.fixCapabilityReset || Settings.simulateVanillaRespawn);
if (Utils.isMohist) {
put("mixins.fix.capability.mohist.json", () -> Settings.fixCapabilityReset);
put("mixins.fix.capability.mohist.json", () -> Settings.fixCapabilityReset || Settings.simulateVanillaRespawn);
}
put("mixins.bridge.explosion.json", () -> Settings.passExplosionEventToBukkit);
if (Utils.isMohist) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/wdsj/hybridfix/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ public class Settings {
@Config.RequiresMcRestart
public static boolean checkForUpdates = true;

@Config.Comment("Fix Simple Difficulty(And other similar mods) thirst not getting reset on respawn.")
@Config.Comment("Re-gather capabilities on respawn, will fix Simple Difficulty(And other similar mods) thirst not getting reset on respawn.")
@Config.RequiresMcRestart
public static boolean fixCapabilityReset = true;

@Config.Comment("Simulate vanilla respawn logic.")
@Config.RequiresMcRestart
public static boolean simulateVanillaRespawn = true;

@Config.Comment("Pass explosion event to Bukkit.")
@Config.RequiresMcRestart
public static boolean passExplosionEventToBukkit = !Utils.isMohist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,73 @@

import io.wdsj.hybridfix.mixin.fix.capability.EntityCapabilityAccessor;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;

import static net.minecraft.entity.Entity.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.EntityDataManager;

public class CBRespawnFixLogic {
private CBRespawnFixLogic() {
}
public static void fixRespawn(EntityPlayerMP playerIn) {
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 {
playerIn.getDataManager().lock.writeLock().lock();
playerIn.getDataManager().entries.clear();
dataManager.lock.writeLock().lock();
dataManager.entries.clear();
} finally {
playerIn.getDataManager().lock.writeLock().unlock();
dataManager.lock.writeLock().unlock();
}
playerIn.getDataManager().empty = true;
playerIn.getDataManager().setClean();
// Entity data params
playerIn.getDataManager().register(FLAGS, Byte.valueOf((byte)0));
playerIn.getDataManager().register(AIR, Integer.valueOf(300));
playerIn.getDataManager().register(CUSTOM_NAME_VISIBLE, Boolean.valueOf(false));
playerIn.getDataManager().register(CUSTOM_NAME, "");
playerIn.getDataManager().register(SILENT, Boolean.valueOf(false));
playerIn.getDataManager().register(NO_GRAVITY, Boolean.valueOf(false));
dataManager.empty = true;
dataManager.setClean();

playerIn.entityInit();
// 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);

net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(playerIn));
}
public static void regatherCapabilities(EntityPlayerMP playerIn) {
((EntityCapabilityAccessor) (Entity) playerIn).setCapabilities(net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(playerIn));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.wdsj.hybridfix.mixin.fix.capability;

import io.wdsj.hybridfix.config.Settings;
import io.wdsj.hybridfix.logic.respawn.CBRespawnFixLogic;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.management.PlayerList;
Expand All @@ -21,6 +22,7 @@ public abstract class PlayerListMixin {
remap = false
)
public void onMoveToWorld(EntityPlayerMP playerIn, int i, boolean b, Location loc, boolean b1, CallbackInfoReturnable<EntityPlayerMP> cir) {
CBRespawnFixLogic.fixRespawn(playerIn);
if (Settings.simulateVanillaRespawn) CBRespawnFixLogic.simulateVanillaRespawn(playerIn);
if (Settings.fixCapabilityReset) CBRespawnFixLogic.regatherCapabilities(playerIn);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.wdsj.hybridfix.mixin.fix.capability.mohist;

import io.wdsj.hybridfix.config.Settings;
import io.wdsj.hybridfix.logic.respawn.CBRespawnFixLogic;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.management.PlayerList;
Expand All @@ -23,6 +24,7 @@ public abstract class PlayerListMixin {
remap = false
)
public void func(EntityPlayerMP playerIn, int i, boolean b, CallbackInfoReturnable<EntityPlayerMP> cir) {
CBRespawnFixLogic.fixRespawn(playerIn);
if (Settings.simulateVanillaRespawn) CBRespawnFixLogic.simulateVanillaRespawn(playerIn);
if (Settings.fixCapabilityReset) CBRespawnFixLogic.regatherCapabilities(playerIn);
}
}
16 changes: 14 additions & 2 deletions src/main/resources/hybridfix_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,17 @@ public net.minecraft.entity.Entity field_184233_aA # CUSTOM_NAME_VISIBLE
public net.minecraft.entity.Entity field_184234_aB # SILENT
public net.minecraft.entity.Entity field_189655_aD # NO_GRAVITY

# EntityPlayer method
public net.minecraft.entity.player.EntityPlayer func_70088_a()V # entityInit
# EntityLivingBase data keys
public net.minecraft.entity.EntityLivingBase field_184621_as # HAND_STATES
public net.minecraft.entity.EntityLivingBase field_184632_c # HEALTH
public net.minecraft.entity.EntityLivingBase field_184633_f # POTION_EFFECTS
public net.minecraft.entity.EntityLivingBase field_184634_g # HIDE_PARTICLES
public net.minecraft.entity.EntityLivingBase field_184635_h # ARROW_COUNT_IN_ENTITY

# EntityPlayer data keys
public net.minecraft.entity.player.EntityPlayer field_184829_a # ABSORPTION
public net.minecraft.entity.player.EntityPlayer field_184830_b # PLAYER_SCORE
public net.minecraft.entity.player.EntityPlayer field_184827_bp # PLAYER_MODEL_FLAG
public net.minecraft.entity.player.EntityPlayer field_184828_bq # MAIN_HAND
public net.minecraft.entity.player.EntityPlayer field_192032_bt # LEFT_SHOULDER_ENTITY
public net.minecraft.entity.player.EntityPlayer field_192033_bu # RIGHT_SHOULDER_ENTITY

0 comments on commit c8577c3

Please sign in to comment.