Fix Ring of Far Reach stacking reach on every dimension change (#157)

This commit is contained in:
micvog authored and GitHub committed 2026-10-04 03:20:27 -04:00
1 parent c802a448e4
commit cefdfd7ca6
3 files changed
+60 -13

No files matched your search

@@ -381,24 +381,38 @@ public class ClientProxy extends CommonProxy {
@Override
public void setExtraReach(EntityLivingBase entity, float reach) {
super.setExtraReach(entity, reach);
IExtendedPlayerController controller = getReachController(entity);
if(controller != null)
controller.setReachDistanceExtension(Math.max(0, controller.getReachDistanceExtension() + reach));
}
@Override
public void setClientExtraReach(EntityLivingBase entity, float reach) {
IExtendedPlayerController controller = getReachController(entity);
if(controller != null)
controller.setReachDistanceExtension(Math.max(0, reach));
}
private IExtendedPlayerController getReachController(EntityLivingBase entity) {
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer;
// Player object might have changed, need to check the UUID.
if(entity.worldObj.isRemote && entity.getUniqueID().equals(player.getUniqueID())) {
if(!(mc.playerController instanceof IExtendedPlayerController)) {
GameType type = ReflectionHelper.getPrivateValue(PlayerControllerMP.class, mc.playerController, LibObfuscation.CURRENT_GAME_TYPE);
NetHandlerPlayClient net = ReflectionHelper.getPrivateValue(PlayerControllerMP.class, mc.playerController, LibObfuscation.NET_CLIENT_HANDLER);
BotaniaPlayerController controller = new BotaniaPlayerController(mc, net);
boolean isFlying = player.capabilities.isFlying;
boolean allowFlying = player.capabilities.allowFlying;
controller.setGameType(type);
player.capabilities.isFlying = isFlying;
player.capabilities.allowFlying = allowFlying;
mc.playerController = controller;
}
if(!entity.worldObj.isRemote || !entity.getUniqueID().equals(player.getUniqueID()))
return null;
((IExtendedPlayerController) mc.playerController).setReachDistanceExtension(Math.max(0, ((IExtendedPlayerController) mc.playerController).getReachDistanceExtension() + reach));
if(!(mc.playerController instanceof IExtendedPlayerController)) {
GameType type = ReflectionHelper.getPrivateValue(PlayerControllerMP.class, mc.playerController, LibObfuscation.CURRENT_GAME_TYPE);
NetHandlerPlayClient net = ReflectionHelper.getPrivateValue(PlayerControllerMP.class, mc.playerController, LibObfuscation.NET_CLIENT_HANDLER);
BotaniaPlayerController controller = new BotaniaPlayerController(mc, net);
boolean isFlying = player.capabilities.isFlying;
boolean allowFlying = player.capabilities.allowFlying;
controller.setGameType(type);
player.capabilities.isFlying = isFlying;
player.capabilities.allowFlying = allowFlying;
mc.playerController = controller;
}
return (IExtendedPlayerController) mc.playerController;
}
@Override
@@ -256,6 +256,13 @@ public class CommonProxy {
((EntityPlayerMP) entity).theItemInWorldManager.setBlockReachDistance(Math.max(5, ((EntityPlayerMP) entity).theItemInWorldManager.getBlockReachDistance() + reach));
}
/**
* Sets (instead of adds to) the extra reach of the client player. No-op on the server.
*/
public void setClientExtraReach(EntityLivingBase entity, float reach) {
// NO-OP
}
public boolean openWikiPage(World world, Block block, MovingObjectPosition pos) {
return false;
}
@@ -11,10 +11,13 @@
package vazkii.botania.common.item.equipment.bauble;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import vazkii.botania.common.Botania;
import vazkii.botania.common.lib.LibItemNames;
import baubles.api.BaubleType;
import baubles.api.BaublesApi;
public class ItemReachRing extends ItemBauble {
@@ -27,6 +30,29 @@ public class ItemReachRing extends ItemBauble {
Botania.proxy.setExtraReach(player, 3.5F);
}
@Override
public void onPlayerLoad(ItemStack stack, EntityLivingBase player) {
if(player.worldObj.isRemote) {
// Baubles resends all baubles to the client on login and on every dimension change and calls this for each
// of them, but the client keeps its reach extension across dimension changes. Set it instead of adding to it.
Botania.proxy.setClientExtraReach(player, 3.5F * countWornRings(player));
} else super.onPlayerLoad(stack, player);
}
private static int countWornRings(EntityLivingBase player) {
if(!(player instanceof EntityPlayer))
return 0;
int count = 0;
IInventory baubles = BaublesApi.getBaubles((EntityPlayer) player);
for(int i = 0; i < baubles.getSizeInventory(); i++) {
ItemStack bauble = baubles.getStackInSlot(i);
if(bauble != null && bauble.getItem() instanceof ItemReachRing)
count++;
}
return count;
}
@Override
public void onUnequipped(ItemStack stack, EntityLivingBase player) {
Botania.proxy.setExtraReach(player, -3.5F);