5257a41Merge branch 1.10.2 into 1.11689f897Merge branch 1.9.4 into 1.10.20aed9c3Merge branch 1.8.9 into 1.9.4f36ebf1Merge branch 1.8 into 1.8.908170b3Downgrade FG to 2.1 because FG 2.2 is 1.9+ only41d2547Update translations00e999fFix replay not being closed when opened via URI scheme handler (fixes #92)767ea29Fix book gui not being suppressed during replay (fixes #90)5b04edbHide ReplayMod app entry from menus on Linux6aff99dFix livelock during netty write to embedded channel (fixes #85)703805fFix infinite loop in mc.scheduledTasks (fixes #86)7a4440cUpdate ReplayStudio0b9c56cFix resource packs not working after first time jumping back in time933ee5f[Compat] Fix camera entity with BetterSprinting prior to 2.0.0 (fixes #78)83b1090Fix hotbar being visible while spectating player (fixes #83)5c73117[Compat] Fix invisible entities with Orange's 1.7 Animations (fixes #78)4704b29Replace the RenderPlayer hook (used subclassing) with a mixin (fixes #79)0c226b0Fix path at end of replay resulting in constant reloading (fixes #56)1b9b13eRename render success sound to all lowercase (required for 1.11) (fixes #66)c2000b3Fix only front-facing chunks visible for ODS rendering (fixes #67)aafeeccFix initial login gui not closing on success (fixes #68)9292addUse percent-encoding for replay file names (fixes #71)8499c0fFix name of invis armor stand with CustomNameVisible not rendering (fixes #72)b9ea572Try to handle invalid ffmpeg arguments more gracefully (fixes #77)a2f8c88Fix compression packets being recorded (fixes #80)19629c3Replace usages of System.out with loggerfe1d9b8Stop Forge from allowing the mod to load on other MC versions (fixes #82)d56fa9bUpdate ReplayStudio/MCProtocolLib (Fixes missing ARMOR_STAND MobType)7c719e0Update ReplayStudio/MCProtocolLib (Fixes missing ARMOR_STAND MobType)1a1e96cFix server with RM installed refusing clients without RM (fixes #76)35eb9caReplace usage of FMLLog with the mod logger
103 lines
5.5 KiB
Java
103 lines
5.5 KiB
Java
package com.replaymod.compat.bettersprinting;
|
|
|
|
import com.replaymod.replay.ReplayModReplay;
|
|
import com.replaymod.replay.events.ReplayChatMessageEvent;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.util.SoundCategory;
|
|
import net.minecraft.util.SoundEvent;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.IWorldEventListener;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.client.event.GuiOpenEvent;
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
import net.minecraftforge.fml.common.Loader;
|
|
import net.minecraftforge.fml.common.ModContainer;
|
|
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
|
|
import net.minecraftforge.fml.common.versioning.Restriction;
|
|
import net.minecraftforge.fml.common.versioning.VersionRange;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.Collections;
|
|
|
|
/**
|
|
* Old Better Sprinting versions replace the vanilla player with their own, overridden instance (replacing the camera entity).
|
|
*
|
|
* See: https://github.com/chylex/Better-Sprinting/blob/1.8/src/main/java/chylex/bettersprinting/client/player/impl/LogicImplOverride.java
|
|
*/
|
|
public class DisableBetterSprinting {
|
|
private static final VersionRange OLD_VERSION = VersionRange.newRange(null,
|
|
Collections.singletonList(new Restriction(null, false, new DefaultArtifactVersion("2.0.0"), false)));
|
|
private static final String LOGIC_CLASS_NAME = "chylex.bettersprinting.client.player.impl.LogicImplOverride";
|
|
private static final String CONTROLLER_OVERRIDE_CLASS_NAME = LOGIC_CLASS_NAME + ".PlayerControllerMPOverride";
|
|
|
|
public static void register() {
|
|
Loader.instance().getModList().stream()
|
|
.filter(mod -> mod.getModId().equalsIgnoreCase("bettersprinting"))
|
|
.findFirst()
|
|
.map(ModContainer::getProcessedVersion).filter(OLD_VERSION::containsVersion)
|
|
.ifPresent($_ -> MinecraftForge.EVENT_BUS.register(new DisableBetterSprinting()));
|
|
}
|
|
|
|
private DisableBetterSprinting() {}
|
|
|
|
private final Minecraft mc = Minecraft.getMinecraft();
|
|
private PlayerControllerMP originalController;
|
|
private BetterSprintingWorldAccess worldAccessHook = new BetterSprintingWorldAccess();
|
|
|
|
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
public void beforeGuiOpenEvent(GuiOpenEvent event) {
|
|
if (ReplayModReplay.instance.getReplayHandler() != null && mc.world != null) {
|
|
// During replay, get ready to revert BetterSprinting's overwritten playerController
|
|
originalController = mc.playerController;
|
|
mc.world.addEventListener(worldAccessHook);
|
|
}
|
|
}
|
|
|
|
@SubscribeEvent(priority = EventPriority.LOW)
|
|
public void afterGuiOpenEvent(GuiOpenEvent event) {
|
|
if (ReplayModReplay.instance.getReplayHandler() != null && mc.world != null) {
|
|
mc.world.addEventListener(worldAccessHook);
|
|
}
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public void onReplayChatMessage(ReplayChatMessageEvent event) {
|
|
// Suppress this message if it's the Better Sprinting warning message
|
|
for (StackTraceElement elem : Thread.currentThread().getStackTrace()) {
|
|
if (LOGIC_CLASS_NAME.equals(elem.getClassName())) {
|
|
event.setCanceled(true);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private class BetterSprintingWorldAccess implements IWorldEventListener {
|
|
@Override
|
|
public void onEntityRemoved(Entity entityIn) {
|
|
if (mc.playerController != null && mc.playerController.getClass().getName().equals(CONTROLLER_OVERRIDE_CLASS_NAME)) {
|
|
// Someone has secretly swapped out the player controller and is about to substitute their own player entity.
|
|
// This is the right time to destroy their plan.
|
|
mc.playerController = originalController;
|
|
}
|
|
}
|
|
|
|
@Override public void notifyBlockUpdate(World worldIn, BlockPos pos, IBlockState oldState, IBlockState newState, int flags) {}
|
|
@Override public void notifyLightSet(BlockPos pos) {}
|
|
@Override public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) {}
|
|
@Override public void playSoundToAllNearExcept(@Nullable EntityPlayer player, SoundEvent soundIn, SoundCategory category, double x, double y, double z, float volume, float pitch) {}
|
|
@Override public void playRecord(SoundEvent soundIn, BlockPos pos) {}
|
|
@Override public void spawnParticle(int p_180442_1_, boolean p_180442_2_, double p_180442_3_, double p_180442_5_, double p_180442_7_, double p_180442_9_, double p_180442_11_, double p_180442_13_, int... p_180442_15_) {}
|
|
@Override public void spawnParticle(int p_190570_1_, boolean p_190570_2_, boolean p_190570_3_, double p_190570_4_, double p_190570_6_, double p_190570_8_, double p_190570_10_, double p_190570_12_, double p_190570_14_, int... p_190570_16_) {}
|
|
@Override public void onEntityAdded(Entity entityIn) {}
|
|
@Override public void broadcastSound(int p_180440_1_, BlockPos p_180440_2_, int p_180440_3_) {}
|
|
@Override public void playEvent(EntityPlayer player, int type, BlockPos blockPosIn, int data) {}
|
|
@Override public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) {}
|
|
}
|
|
}
|