Files
MinecraftForge/patches/minecraft/net/minecraft/client/Minecraft.java.patch
T
2026-09-19 07:45:38 -07:00

296 lines
15 KiB
Diff

--- a/net/minecraft/client/Minecraft.java
+++ b/net/minecraft/client/Minecraft.java
@@ -265,7 +_,7 @@
import org.slf4j.Logger;
@OnlyIn(Dist.CLIENT)
-public class Minecraft extends ReentrantBlockableEventLoop<Runnable> implements WindowEventHandler {
+public class Minecraft extends ReentrantBlockableEventLoop<Runnable> implements WindowEventHandler, net.minecraftforge.client.extensions.IForgeMinecraft {
private static Minecraft instance;
private static final Logger LOGGER = LogUtils.getLogger();
private static final SectionCategory TRACY_CURRENT_LEVEL = TracyClient.createSectionCategory("Level");
@@ -420,7 +_,6 @@
}
}, Util.nonCriticalIoPool());
LOGGER.info("Setting user: {}", this.user.getName());
- LOGGER.debug("(Session ID is {})", this.user.getSessionId());
this.demo = gameConfig.game.demo;
this.allowsMultiplayer = !gameConfig.game.disableMultiplayer;
this.allowsChat = !gameConfig.game.disableChat;
@@ -568,6 +_,7 @@
this.keyboardHandler = new KeyboardHandler(this);
this.options.applyGraphicsPreset(this.options.graphicsPreset().get());
this.resourceManager = new ReloadableResourceManager(PackType.CLIENT_RESOURCES);
+ net.minecraftforge.client.loading.ClientModLoader.begin(this, this.resourcePackRepository, this.resourceManager);
this.resourcePackRepository.reload();
this.options.loadSelectedResourcePacks(this.resourcePackRepository);
this.languageManager = new LanguageManager(this, this.options.languageCode, var1 -> {
@@ -645,6 +_,7 @@
ParticleResources particleResources = new ParticleResources();
this.resourceManager.registerReloadListener(particleResources);
this.particleEngine = new ParticleEngine(this.level, particleResources);
+ net.minecraftforge.client.ForgeHooksClient.onRegisterParticleProviders(particleResources);
particleResources.onReload(this.particleEngine::clearParticles);
this.gameRenderer = new GameRenderer(this, new FirstPersonHandsAndItemsRenderer(this), this.modelManager, this.itemModelResolver);
this.resourceManager.registerReloadListener(this.gameRenderer);
@@ -663,6 +_,7 @@
this.window.getHeight()
);
this.levelExtractor = new LevelExtractor(this, this.gameRenderer.gameRenderState().levelRenderState, this.levelRenderer);
+ net.minecraftforge.client.event.ForgeEventFactoryClient.onInitLevelRenderer();
this.resourceManager.registerReloadListener(this.levelExtractor);
this.resourceManager.registerReloadListener(this.levelRenderer.cloudRenderer());
this.gpuWarnlistManager = new GpuWarnlistManager();
@@ -694,6 +_,7 @@
MessageBox.error(message.toString());
}
+ net.minecraftforge.client.ForgeHooksClient.initClientHooks(this, this.resourceManager);
this.window.setAllowCursorChanges(this.options.allowCursorChanges().get());
this.window.setQuitShortcuts(this.options.quitShortcuts().get());
if (InputQuirks.EMULATE_RIGHT_CLICK_WITH_CTRL_KEY) {
@@ -721,14 +_,15 @@
.createReload(Util.backgroundExecutor().forName("resourceLoad"), this, RESOURCE_RELOAD_INITIAL_TASK, packs);
GameLoadTimesEvent.INSTANCE.beginStep(TelemetryProperty.LOAD_TIME_LOADING_OVERLAY_MS);
GameLoadCookie loadCookie = new GameLoadCookie(realmsClient, gameConfig.quickPlay);
- this.gui.setOverlay(new LoadingOverlay(this, reloadInstance, maybeT -> Util.ifElse(maybeT, t -> this.rollbackResourcePacks(t, loadCookie), () -> {
+ this.gui.setOverlay(net.minecraftforge.fml.loading.ImmediateWindowHandler.<LoadingOverlay>loadingOverlay(() -> this, () ->reloadInstance, maybeT -> Util.ifElse(maybeT, t -> this.rollbackResourcePacks(t, loadCookie), () -> {
if (SharedConstants.IS_RUNNING_IN_IDE) {
this.selfTest();
}
this.reloadStateTracker.finishReload();
this.onResourceLoadFinished(loadCookie);
- }), false));
+ net.minecraftforge.client.loading.ClientModLoader.completeModLoading();
+ }), false).get());
this.quickPlayLog = QuickPlayLog.of(gameConfig.quickPlay.logPath());
this.framerateLimitTracker = new FramerateLimitTracker(this.options, this);
this.fpsPieProfiler = new ContinuousProfiler(Util.timeSource(), () -> this.fpsPieRenderTicks, this.framerateLimitTracker::isHeavilyThrottled);
@@ -812,6 +_,7 @@
StringBuilder builder = new StringBuilder("Minecraft");
if (checkModStatus().shouldReportAsModified()) {
builder.append("*");
+ builder.append(" Forge");
}
builder.append(" ");
@@ -835,6 +_,8 @@
}
private static UserApiService createUserApiService(final MinecraftServicesDiscoveryService discoveryService, final GameConfig config) {
+ if ("0".equals(config.user.user.getAccessToken())) // Forge: We use "0" in dev. Short circuit to stop exception spam.
+ return UserApiService.OFFLINE;
return config.game.offlineDeveloperMode ? UserApiService.OFFLINE : discoveryService.createUserApiService(config.user.user.getAccessToken());
}
@@ -851,7 +_,7 @@
}
private void rollbackResourcePacks(final Throwable t, final @Nullable GameLoadCookie loadCookie) {
- if (this.resourcePackRepository.getSelectedIds().size() > 1) {
+ if (this.resourcePackRepository.getSelectedPacks().stream().anyMatch(e -> !e.isRequired())) { //Forge: This caused infinite loop if any resource packs are forced. Such as mod resources. So check if we can disable any.
this.clearResourcePacksOnError(t, null, loadCookie);
} else {
Util.throwAsRuntime(t);
@@ -1148,6 +_,7 @@
FreeTypeUtil.destroy();
this.windowSurface.close();
RenderSystem.shutdownRenderer();
+ net.minecraftforge.fml.config.ConfigTracker.forceUnload();
} catch (Throwable t) {
LOGGER.error("Shutdown failure!", t);
throw t;
@@ -1305,7 +_,9 @@
profiler.popPush("gpuAsync");
RenderSystem.executePendingTasks();
profiler.pop();
+ net.minecraftforge.client.event.ForgeEventFactoryClient.onRenderTickStart(this.deltaTracker);
this.gameRenderer.render();
+ net.minecraftforge.client.event.ForgeEventFactoryClient.onRenderTickEnd(this.deltaTracker);
}
profiler.push("swapchainBlit");
@@ -1432,6 +_,7 @@
this.window.setGuiScale(guiScale);
if (this.gui.screen() != null) {
this.gui.screen().resize(this.window.getGuiScaledWidth(), this.window.getGuiScaledHeight());
+ this.gui.resizeLayers(this.window.getGuiScaledWidth(), this.window.getGuiScaledHeight());
}
this.mouseHandler.resyncMousePosition();
@@ -1595,6 +_,7 @@
}
public void stop() {
+ if (this.isRunning()) net.minecraftforge.event.ForgeEventFactory.onGameShuttingDown();
this.running = false;
}
@@ -1622,9 +_,16 @@
if (down && this.hitResult != null && this.hitResult.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockHit = (BlockHitResult)this.hitResult;
BlockPos pos = blockHit.getBlockPos();
- if (!this.level.getBlockState(pos).isAir()) {
+ if (!this.level.isEmptyBlock(pos)) {
+ var inputEvent = new net.minecraftforge.client.event.InputEvent.InteractionKeyMappingTriggered.Attack(this.options.keyAttack, InteractionHand.MAIN_HAND);
+ if (net.minecraftforge.client.event.InputEvent.InteractionKeyMappingTriggered.Attack.BUS.post(inputEvent)) {
+ if (inputEvent.shouldSwingHand()) {
+ this.player.swing(InteractionHand.MAIN_HAND, swingAnimation, false);
+ }
+ return;
+ }
Direction direction = blockHit.getDirection();
- if (this.gameMode.continueDestroyBlock(pos, direction)) {
+ if (this.gameMode.continueDestroyBlock(pos, direction) && inputEvent.shouldSwingHand()) {
this.player.swing(InteractionHand.MAIN_HAND, swingAnimation, false);
this.player.connection.send(ServerboundPunchPacket.INSTANCE);
}
@@ -1679,6 +_,8 @@
return true;
}
+ var inputEvent = new net.minecraftforge.client.event.InputEvent.InteractionKeyMappingTriggered.Attack(this.options.keyAttack, InteractionHand.MAIN_HAND);
+ if (!net.minecraftforge.client.event.InputEvent.InteractionKeyMappingTriggered.Attack.BUS.post(inputEvent))
switch (this.hitResult.getType()) {
case ENTITY:
AttackRange customItemRange = heldItem.get(DataComponents.ATTACK_RANGE);
@@ -1689,7 +_,7 @@
case BLOCK:
BlockHitResult blockHit = (BlockHitResult)this.hitResult;
BlockPos pos = blockHit.getBlockPos();
- if (!this.level.getBlockState(pos).isAir()) {
+ if (!this.level.isEmptyBlock(pos)) {
this.gameMode.startDestroyBlock(pos, blockHit.getDirection());
if (this.level.getBlockState(pos).isAir()) {
endAttack = true;
@@ -1702,10 +_,13 @@
}
this.player.resetAttackStrengthTicker();
+ net.minecraftforge.event.ForgeEventFactory.onLeftClickEmpty(this.player);
}
+ if (inputEvent.shouldSwingHand()) {
this.player.swing(InteractionHand.MAIN_HAND, attackAnimation, false);
this.player.connection.send(ServerboundPunchPacket.INSTANCE);
+ }
return endAttack;
}
}
@@ -1726,6 +_,13 @@
}
SwingAnimation swingAnimation = heldItem.getInteractAnimation();
+
+ var inputEvent = new net.minecraftforge.client.event.InputEvent.InteractionKeyMappingTriggered.UseItem(this.options.keyUse, hand);
+ if (net.minecraftforge.client.event.InputEvent.InteractionKeyMappingTriggered.UseItem.BUS.post(inputEvent)) {
+ if (inputEvent.shouldSwingHand()) this.player.swing(hand, swingAnimation, false);
+ return;
+ }
+
if (this.hitResult != null) {
switch (this.hitResult.getType()) {
case ENTITY:
@@ -1737,7 +_,7 @@
if (this.player.isWithinEntityInteractionRange(entity, 0.0)
&& this.gameMode.interact(this.player, entity, entityHit, hand) instanceof InteractionResult.Success success) {
- if (success.swingSource() == InteractionResult.SwingSource.PREDICTED) {
+ if (success.swingSource() == InteractionResult.SwingSource.PREDICTED && inputEvent.shouldSwingHand()) {
this.player.swing(hand, swingAnimation, false);
}
@@ -1749,7 +_,7 @@
int oldCount = heldItem.getCount();
InteractionResult useResult = this.gameMode.useItemOn(this.player, hand, blockHit);
if (useResult instanceof InteractionResult.Success success) {
- if (success.swingSource() == InteractionResult.SwingSource.PREDICTED) {
+ if (success.swingSource() == InteractionResult.SwingSource.PREDICTED && inputEvent.shouldSwingHand()) {
this.player.swing(hand, swingAnimation, false);
if (!heldItem.isEmpty() && (heldItem.getCount() != oldCount || this.player.hasInfiniteMaterials())) {
this.player.itemUsed(hand);
@@ -1765,6 +_,9 @@
}
}
+ if (heldItem.isEmpty() && (this.hitResult == null || this.hitResult.getType() == HitResult.Type.MISS))
+ net.minecraftforge.event.ForgeEventFactory.onRightClickEmpty(this.player, hand);
+
if (!heldItem.isEmpty() && this.gameMode.useItem(this.player, hand) instanceof InteractionResult.Success success) {
if (success.swingSource() == InteractionResult.SwingSource.PREDICTED) {
this.player.swing(hand, swingAnimation, false);
@@ -1793,6 +_,8 @@
}
ProfilerFiller profiler = Profiler.get();
+ net.minecraftforge.event.ForgeEventFactory.onPreClientTick();
+
profiler.push("gameMode");
if (!this.pause && this.level != null) {
this.gameMode.tick();
@@ -1845,6 +_,7 @@
this.tutorial.tick();
+ net.minecraftforge.event.ForgeEventFactory.onPreLevelTick(this.level, () -> true);
try {
this.level.tick(() -> true);
} catch (Throwable t) {
@@ -1858,6 +_,7 @@
throw new ReportedException(report);
}
+ net.minecraftforge.event.ForgeEventFactory.onPostLevelTick(this.level, () -> true);
}
profiler.popPush("animateTick");
@@ -1882,6 +_,7 @@
profiler.popPush("keyboard");
this.keyboardHandler.tick();
profiler.pop();
+ net.minecraftforge.event.ForgeEventFactory.onPostClientTick();
}
private boolean isLevelRunningNormally() {
@@ -2088,6 +_,7 @@
}
public void setLevel(final ClientLevel level) {
+ if (this.level != null) net.minecraftforge.event.ForgeEventFactory.onLevelUnload(this.level);
this.level = level;
this.updateLevelInEngines(level);
}
@@ -2149,6 +_,7 @@
IntegratedServer server = this.singleplayerServer;
this.singleplayerServer = null;
this.gameRenderer.resetData();
+ net.minecraftforge.client.event.ForgeEventFactoryClient.firePlayerLogout(this.gameMode, this.player);
this.gameMode = null;
this.narrator.clear();
this.gui.setClientLevelTeardownInProgress(true);
@@ -2156,6 +_,7 @@
try {
if (this.level != null) {
this.gui.hud.onDisconnected();
+ net.minecraftforge.event.ForgeEventFactory.onLevelUnload(this.level);
}
this.level = null;
@@ -2171,6 +_,7 @@
}
profiler.pop();
+ net.minecraftforge.client.ForgeHooksClient.handleClientLevelClosing(this.level);
}
this.setScreenAndShow(screen);
@@ -2403,6 +_,7 @@
private void pickBlockOrEntity() {
if (this.hitResult != null && this.hitResult.getType() != HitResult.Type.MISS) {
+ if (net.minecraftforge.client.event.ForgeEventFactoryClient.onClickInputPickBlock(this.options.keyPickItem)) return;
boolean includeData = this.hasControlDown();
switch (this.hitResult) {
case BlockHitResult blockHitResult: