Magma/patches/minecraft/net/minecraft/client/Minecraft.java.patch
2024-03-04 21:16:02 +13:00

467 lines
21 KiB
Diff

--- a/net/minecraft/client/Minecraft.java
+++ b/net/minecraft/client/Minecraft.java
@@ -249,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 {
static Minecraft f_90981_;
private static final Logger f_90982_ = LogUtils.getLogger();
public static final boolean f_91002_ = Util.m_137581_() == Util.OS.OSX;
@@ -413,7 +_,6 @@
this.f_193584_ = this.m_193585_(this.f_231338_, p_91084_);
this.f_90998_ = p_91084_.f_101905_.f_101942_;
f_90982_.info("Setting user: {}", (Object)this.f_90998_.m_92546_());
- f_90982_.debug("(Session ID is {})", (Object)this.f_90998_.m_92544_());
this.f_91033_ = p_91084_.f_101908_.f_101926_;
this.f_91034_ = !p_91084_.f_101908_.f_101929_;
this.f_91035_ = !p_91084_.f_101908_.f_101930_;
@@ -449,15 +_,15 @@
}
this.f_90990_.m_85380_(this.f_91066_.m_232035_().m_231551_());
+ // FORGE: Move mouse and keyboard handler setup further below
this.f_91067_ = new MouseHandler(this);
- this.f_91067_.m_91524_(this.f_90990_.m_85439_());
this.f_91068_ = new KeyboardHandler(this);
- this.f_91068_.m_90887_(this.f_90990_.m_85439_());
RenderSystem.initRenderer(this.f_91066_.f_92035_, false);
this.f_91042_ = new MainTarget(this.f_90990_.m_85441_(), this.f_90990_.m_85442_());
this.f_91042_.m_83931_(0.0F, 0.0F, 0.0F, 0.0F);
this.f_91042_.m_83954_(f_91002_);
this.f_91036_ = new ReloadableResourceManager(PackType.CLIENT_RESOURCES);
+ net.minecraftforge.client.loading.ClientModLoader.begin(this, this.f_91038_, this.f_91036_);
this.f_91038_.m_10506_();
this.f_91066_.m_92145_(this.f_91038_);
this.f_91039_ = new LanguageManager(this.f_91066_.f_92075_);
@@ -504,10 +_,13 @@
this.f_91063_ = new GameRenderer(this, this.f_90994_.m_234586_(), this.f_91036_, this.f_90993_);
this.f_91036_.m_7217_(this.f_91063_.m_247116_());
this.f_91060_ = new LevelRenderer(this, this.f_90994_, this.f_167845_, this.f_90993_);
+ net.minecraftforge.fml.ModLoader.get().postEvent(new net.minecraftforge.client.event.RenderLevelStageEvent.RegisterStageEvent());
this.f_91036_.m_7217_(this.f_91060_);
- this.m_91271_();
+ // Forge: We delay this to allow registration of modded creative mode tabs
+ // this.createSearchTrees();
this.f_91036_.m_7217_(this.f_90997_);
this.f_91061_ = new ParticleEngine(this.f_91073_, this.f_90987_);
+ net.minecraftforge.client.ForgeHooksClient.onRegisterParticleProviders(this.f_91061_);
this.f_91036_.m_7217_(this.f_91061_);
this.f_91053_ = new PaintingTextureManager(this.f_90987_);
this.f_91036_.m_7217_(this.f_91053_);
@@ -516,7 +_,10 @@
this.f_91047_ = new GpuWarnlistManager();
this.f_91036_.m_7217_(this.f_91047_);
this.f_91036_.m_7217_(this.f_205120_);
- this.f_91065_ = new Gui(this, this.f_90995_);
+ this.f_91065_ = new net.minecraftforge.client.gui.overlay.ForgeGui(this);
+ // FORGE: Moved keyboard and mouse handler setup below ingame gui creation to prevent NPEs in them.
+ this.f_91067_.m_91524_(this.f_90990_.m_85439_());
+ this.f_91068_.m_90887_(this.f_90990_.m_85439_());
this.f_91064_ = new DebugRenderer(this);
RealmsClient realmsclient = RealmsClient.m_239151_(this);
this.f_238717_ = new RealmsDataFetcher(realmsclient);
@@ -536,6 +_,7 @@
TinyFileDialogs.tinyfd_messageBox("Minecraft", stringbuilder.toString(), "ok", "error", false);
}
+ net.minecraftforge.client.ForgeHooksClient.initClientHooks(this, this.f_91036_);
this.f_90990_.m_85409_(this.f_91066_.m_231817_().m_231551_());
this.f_90990_.m_85424_(this.f_91066_.m_232123_().m_231551_());
this.f_90990_.m_85426_();
@@ -554,7 +_,7 @@
this.f_167847_.m_168557_(ResourceLoadStateTracker.ReloadReason.INITIAL, list);
ReloadInstance reloadinstance = this.f_91036_.m_142463_(Util.m_183991_(), this, f_90983_, list);
GameLoadTimesEvent.f_285635_.m_285833_(TelemetryProperty.f_285629_);
- this.m_91150_(new LoadingOverlay(this, reloadinstance, (p_210745_) -> {
+ this.m_91150_(net.minecraftforge.fml.loading.ImmediateWindowHandler.<LoadingOverlay>loadingOverlay(()->this, () ->reloadinstance, (p_210745_) -> {
Util.m_137521_(p_210745_, this::m_91239_, () -> {
if (SharedConstants.f_136183_) {
this.m_91273_();
@@ -562,20 +_,23 @@
this.f_167847_.m_168556_();
this.m_286052_();
+ if (net.minecraftforge.client.loading.ClientModLoader.completeModLoading())
+ return; // Do not overwrite the error screen if there are errors
+ // FORGE: Move opening initial screen to after startup and events are enabled
+ if (this.m_239929_()) {
+ this.m_91152_(BanNoticeScreen.m_239967_((p_278873_) -> {
+ if (p_278873_) {
+ Util.m_137581_().m_137646_("https://aka.ms/mcjavamoderation");
+ }
+
+ this.m_278684_(realmsclient, reloadinstance, p_91084_.f_278410_);
+ }, this.m_239210_()));
+ } else {
+ this.m_278684_(realmsclient, reloadinstance, p_91084_.f_278410_);
+ }
});
- }, false));
+ }, false).get());
this.f_278504_ = QuickPlayLog.m_278648_(p_91084_.f_278410_.f_278493_());
- if (this.m_239929_()) {
- this.m_91152_(BanNoticeScreen.m_239967_((p_278873_) -> {
- if (p_278873_) {
- Util.m_137581_().m_137646_("https://aka.ms/mcjavamoderation");
- }
-
- this.m_278684_(realmsclient, reloadinstance, p_91084_.f_278410_);
- }, this.m_239210_()));
- } else {
- this.m_278684_(realmsclient, reloadinstance, p_91084_.f_278410_);
- }
}
@@ -611,7 +_,7 @@
private String m_91270_() {
StringBuilder stringbuilder = new StringBuilder("Minecraft");
if (m_193589_().m_184597_()) {
- stringbuilder.append("*");
+ stringbuilder.append(' ').append(net.minecraftforge.forge.snapshots.ForgeSnapshotsMod.BRANDING_NAME).append('*');
}
stringbuilder.append(" ");
@@ -635,6 +_,8 @@
private UserApiService m_193585_(YggdrasilAuthenticationService p_193586_, GameConfig p_193587_) {
try {
+ if ("0".equals(p_193587_.f_101905_.f_101942_.m_92547_())) // Forge: We use "0" in dev. Short circuit to stop exception spam.
+ return UserApiService.OFFLINE;
return p_193586_.createUserApiService(p_193587_.f_101905_.f_101942_.m_92547_());
} catch (AuthenticationException authenticationexception) {
f_90982_.error("Failed to verify authentication", (Throwable)authenticationexception);
@@ -647,7 +_,7 @@
}
private void m_91239_(Throwable p_91240_) {
- if (this.f_91038_.m_10523_().size() > 1) {
+ if (this.f_91038_.m_10524_().stream().anyMatch(e -> !e.m_10449_())) { //Forge: This caused infinite loop if any resource packs are forced. Such as mod resources. So check if we can disable any.
this.m_91241_(p_91240_, (Component)null);
} else {
Util.m_137559_(p_91240_);
@@ -739,7 +_,10 @@
}
public void m_91271_() {
- this.f_90997_.m_235232_(SearchRegistry.f_119941_, (p_231389_) -> {
+ var nameSearchKeys = net.minecraftforge.client.CreativeModeTabSearchRegistry.getNameSearchKeys();
+ var tagSearchKeys = net.minecraftforge.client.CreativeModeTabSearchRegistry.getTagSearchKeys();
+ for (var nameSearchKey : nameSearchKeys.values())
+ this.f_90997_.m_235232_(nameSearchKey, (p_231389_) -> {
return new FullTextSearchTree<>((p_210797_) -> {
return p_210797_.m_41651_((Player)null, TooltipFlag.Default.f_256752_.m_257777_()).stream().map((p_210807_) -> {
return ChatFormatting.m_126649_(p_210807_.getString()).trim();
@@ -750,7 +_,8 @@
return Stream.of(BuiltInRegistries.f_257033_.m_7981_(p_91317_.m_41720_()));
}, p_231389_);
});
- this.f_90997_.m_235232_(SearchRegistry.f_119942_, (p_231430_) -> {
+ for (var tagSearchKey : tagSearchKeys.values())
+ this.f_90997_.m_235232_(tagSearchKey, (p_231430_) -> {
return new IdSearchTree<>((p_231353_) -> {
return p_231353_.m_204131_().map(TagKey::f_203868_);
}, p_231430_);
@@ -770,9 +_,12 @@
});
}, p_231451_);
});
- CreativeModeTabs.m_258007_().m_257882_((p_255439_) -> {
- this.m_231374_(SearchRegistry.f_119941_, p_255439_);
- this.m_231374_(SearchRegistry.f_119942_, p_255439_);
+ nameSearchKeys.forEach((tab, nameSearchKey) -> {
+ var tagSearchKey = tagSearchKeys.get(tab);
+ tab.m_257882_(contents -> {
+ this.m_231374_(nameSearchKey, contents);
+ this.m_231374_(tagSearchKey, contents);
+ });
});
}
@@ -824,13 +_,13 @@
Bootstrap.m_135875_(p_91333_.m_127526_());
if (p_91333_.m_127527_() != null) {
Bootstrap.m_135875_("#@!@# Game crashed! Crash report saved to: #@!@# " + p_91333_.m_127527_());
- System.exit(-1);
+ net.minecraftforge.server.ServerLifecycleHooks.handleExit(-1);
} else if (p_91333_.m_127512_(file2)) {
Bootstrap.m_135875_("#@!@# Game crashed! Crash report saved to: #@!@# " + file2.getAbsolutePath());
- System.exit(-1);
+ net.minecraftforge.server.ServerLifecycleHooks.handleExit(-1);
} else {
Bootstrap.m_135875_("#@?@# Game crashed! Crash report could not be saved. #@?@#");
- System.exit(-2);
+ net.minecraftforge.server.ServerLifecycleHooks.handleExit(-2);
}
}
@@ -954,10 +_,6 @@
f_90982_.error("setScreen called from non-game thread");
}
- if (this.f_91080_ != null) {
- this.f_91080_.m_7861_();
- }
-
if (p_91153_ == null && this.f_91073_ == null) {
p_91153_ = new TitleScreen();
} else if (p_91153_ == null && this.f_91074_.m_21224_()) {
@@ -968,6 +_,19 @@
}
}
+ net.minecraftforge.client.ForgeHooksClient.clearGuiLayers(this);
+ Screen old = this.f_91080_;
+ if (p_91153_ != null) {
+ var event = new net.minecraftforge.client.event.ScreenEvent.Opening(old, p_91153_);
+ if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return;
+ p_91153_ = event.getNewScreen();
+ }
+
+ if (old != null && p_91153_ != old) {
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.ScreenEvent.Closing(old));
+ old.m_7861_();
+ }
+
this.f_91080_ = p_91153_;
if (this.f_91080_ != null) {
this.f_91080_.m_274333_();
@@ -1113,9 +_,12 @@
RenderSystem.enableCull();
this.f_91026_.m_7238_();
if (!this.f_91079_) {
+ this.realPartialTick = this.f_91012_ ? this.f_91013_ : this.f_90991_.f_92518_; // Cache this since pause is volatile
+ net.minecraftforge.event.ForgeEventFactory.onRenderTickStart(this.realPartialTick);
this.f_91026_.m_6182_("gameRenderer");
this.f_91063_.m_109093_(this.f_91012_ ? this.f_91013_ : this.f_90991_.f_92518_, i, p_91384_);
this.f_91026_.m_7238_();
+ net.minecraftforge.event.ForgeEventFactory.onRenderTickEnd(this.realPartialTick);
}
if (this.f_91056_ != null) {
@@ -1240,10 +_,12 @@
this.f_90990_.m_85378_((double)i);
if (this.f_91080_ != null) {
this.f_91080_.m_6574_(this, this.f_90990_.m_85445_(), this.f_90990_.m_85446_());
+ net.minecraftforge.client.ForgeHooksClient.resizeGuiLayers(this, this.f_90990_.m_85445_(), this.f_90990_.m_85446_());
}
RenderTarget rendertarget = this.m_91385_();
rendertarget.m_83941_(this.f_90990_.m_85441_(), this.f_90990_.m_85442_(), f_91002_);
+ if (this.f_91063_ != null)
this.f_91063_.m_109097_(this.f_90990_.m_85441_(), this.f_90990_.m_85442_());
this.f_91067_.m_91599_();
}
@@ -1517,6 +_,7 @@
}
public void m_91395_() {
+ if (this.m_91396_()) net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.GameShuttingDownEvent());
this.f_91019_ = false;
}
@@ -1546,10 +_,18 @@
if (p_91387_ && this.f_91077_ != null && this.f_91077_.m_6662_() == HitResult.Type.BLOCK) {
BlockHitResult blockhitresult = (BlockHitResult)this.f_91077_;
BlockPos blockpos = blockhitresult.m_82425_();
- if (!this.f_91073_.m_8055_(blockpos).m_60795_()) {
+ if (!this.f_91073_.m_46859_(blockpos)) {
+ var inputEvent = net.minecraftforge.client.ForgeHooksClient.onClickInput(0, this.f_91066_.f_92096_, InteractionHand.MAIN_HAND);
+ if (inputEvent.isCanceled()) {
+ if (inputEvent.shouldSwingHand()) {
+ this.f_91061_.addBlockHitEffects(blockpos, blockhitresult);
+ this.f_91074_.m_6674_(InteractionHand.MAIN_HAND);
+ }
+ return;
+ }
Direction direction = blockhitresult.m_82434_();
- if (this.f_91072_.m_105283_(blockpos, direction)) {
- this.f_91061_.m_107367_(blockpos, direction);
+ if (this.f_91072_.m_105283_(blockpos, direction) && inputEvent.shouldSwingHand()) {
+ this.f_91061_.addBlockHitEffects(blockpos, blockhitresult);
this.f_91074_.m_6674_(InteractionHand.MAIN_HAND);
}
}
@@ -1578,6 +_,8 @@
return false;
} else {
boolean flag = false;
+ var inputEvent = net.minecraftforge.client.ForgeHooksClient.onClickInput(0, this.f_91066_.f_92096_, InteractionHand.MAIN_HAND);
+ if (!inputEvent.isCanceled())
switch (this.f_91077_.m_6662_()) {
case ENTITY:
this.f_91072_.m_105223_(this.f_91074_, ((EntityHitResult)this.f_91077_).m_82443_());
@@ -1585,7 +_,7 @@
case BLOCK:
BlockHitResult blockhitresult = (BlockHitResult)this.f_91077_;
BlockPos blockpos = blockhitresult.m_82425_();
- if (!this.f_91073_.m_8055_(blockpos).m_60795_()) {
+ if (!this.f_91073_.m_46859_(blockpos)) {
this.f_91072_.m_105269_(blockpos, blockhitresult.m_82434_());
if (this.f_91073_.m_8055_(blockpos).m_60795_()) {
flag = true;
@@ -1598,8 +_,10 @@
}
this.f_91074_.m_36334_();
+ net.minecraftforge.common.ForgeHooks.onEmptyLeftClick(this.f_91074_);
}
+ if (inputEvent.shouldSwingHand())
this.f_91074_.m_6674_(InteractionHand.MAIN_HAND);
return flag;
}
@@ -1615,6 +_,11 @@
}
for(InteractionHand interactionhand : InteractionHand.values()) {
+ var inputEvent = net.minecraftforge.client.ForgeHooksClient.onClickInput(1, this.f_91066_.f_92095_, interactionhand);
+ if (inputEvent.isCanceled()) {
+ if (inputEvent.shouldSwingHand()) this.f_91074_.m_6674_(interactionhand);
+ return;
+ }
ItemStack itemstack = this.f_91074_.m_21120_(interactionhand);
if (!itemstack.m_246617_(this.f_91073_.m_246046_())) {
return;
@@ -1635,7 +_,7 @@
}
if (interactionresult.m_19077_()) {
- if (interactionresult.m_19080_()) {
+ if (interactionresult.m_19080_() && inputEvent.shouldSwingHand()) {
this.f_91074_.m_6674_(interactionhand);
}
@@ -1647,7 +_,7 @@
int i = itemstack.m_41613_();
InteractionResult interactionresult1 = this.f_91072_.m_233732_(this.f_91074_, interactionhand, blockhitresult);
if (interactionresult1.m_19077_()) {
- if (interactionresult1.m_19080_()) {
+ if (interactionresult1.m_19080_() && inputEvent.shouldSwingHand()) {
this.f_91074_.m_6674_(interactionhand);
if (!itemstack.m_41619_() && (itemstack.m_41613_() != i || this.f_91072_.m_105290_())) {
this.f_91063_.f_109055_.m_109320_(interactionhand);
@@ -1663,6 +_,9 @@
}
}
+ if (itemstack.m_41619_() && (this.f_91077_ == null || this.f_91077_.m_6662_() == HitResult.Type.MISS))
+ net.minecraftforge.common.ForgeHooks.onEmptyClick(this.f_91074_, interactionhand);
+
if (!itemstack.m_41619_()) {
InteractionResult interactionresult2 = this.f_91072_.m_233721_(this.f_91074_, interactionhand);
if (interactionresult2.m_19077_()) {
@@ -1689,6 +_,8 @@
--this.f_91011_;
}
+ net.minecraftforge.event.ForgeEventFactory.onPreClientTick();
+
this.f_91026_.m_6180_("gui");
this.f_240378_.m_240688_();
this.f_91065_.m_193832_(this.f_91012_);
@@ -1780,6 +_,7 @@
this.f_91005_.m_120596_();
+ net.minecraftforge.event.ForgeEventFactory.onPreLevelTick(this.f_91073_, () -> true);
try {
this.f_91073_.m_104726_(() -> {
return true;
@@ -1795,6 +_,7 @@
throw new ReportedException(crashreport);
}
+ net.minecraftforge.event.ForgeEventFactory.onPostLevelTick(this.f_91073_, () -> true);
}
this.f_91026_.m_6182_("animateTick");
@@ -1814,6 +_,8 @@
this.f_91026_.m_6182_("keyboard");
this.f_91068_.m_90931_();
this.f_91026_.m_7238_();
+
+ net.minecraftforge.event.ForgeEventFactory.onPostClientTick();
}
private boolean m_91278_() {
@@ -2011,6 +_,7 @@
}
public void m_91156_(ClientLevel p_91157_) {
+ if (this.f_91073_ != null) net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.level.LevelEvent.Unload(this.f_91073_));
ProgressScreen progressscreen = new ProgressScreen(true);
progressscreen.m_6309_(Component.m_237115_("connect.joining"));
this.m_91362_(progressscreen);
@@ -2044,10 +_,12 @@
IntegratedServer integratedserver = this.f_91007_;
this.f_91007_ = null;
this.f_91063_.m_109150_();
+ net.minecraftforge.client.ForgeHooksClient.firePlayerLogout(this.f_91072_, this.f_91074_);
this.f_91072_ = null;
this.f_240365_.m_93328_();
this.m_91362_(p_91321_);
if (this.f_91073_ != null) {
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.level.LevelEvent.Unload(this.f_91073_));
if (integratedserver != null) {
this.f_91026_.m_6180_("waitForServer");
@@ -2061,6 +_,7 @@
this.f_243981_.m_246151_();
this.f_91065_.m_93089_();
this.f_91010_ = false;
+ net.minecraftforge.client.ForgeHooksClient.handleClientLevelClosing(this.f_91073_);
}
this.f_91073_ = null;
@@ -2167,6 +_,7 @@
private void m_91280_() {
if (this.f_91077_ != null && this.f_91077_.m_6662_() != HitResult.Type.MISS) {
+ if (net.minecraftforge.client.ForgeHooksClient.onClickInput(2, this.f_91066_.f_92097_, InteractionHand.MAIN_HAND).isCanceled()) return;
boolean flag = this.f_91074_.m_150110_().f_35937_;
BlockEntity blockentity = null;
HitResult.Type hitresult$type = this.f_91077_.m_6662_();
@@ -2179,10 +_,7 @@
}
Block block = blockstate.m_60734_();
- itemstack = block.m_7397_(this.f_91073_, blockpos, blockstate);
- if (itemstack.m_41619_()) {
- return;
- }
+ itemstack = blockstate.getCloneItemStack(this.f_91077_, this.f_91073_, blockpos, this.f_91074_);
if (flag && Screen.m_96637_() && blockstate.m_155947_()) {
blockentity = this.f_91073_.m_7702_(blockpos);
@@ -2193,7 +_,7 @@
}
Entity entity = ((EntityHitResult)this.f_91077_).m_82443_();
- itemstack = entity.m_142340_();
+ itemstack = entity.getPickedResult(this.f_91077_);
if (itemstack == null) {
return;
}
@@ -2732,6 +_,19 @@
public void m_91312_(int p_91313_) {
this.f_91051_.m_119410_(p_91313_);
+ }
+
+ public ItemColors getItemColors() {
+ return this.f_91041_;
+ }
+
+ public SearchRegistry getSearchTreeManager() {
+ return this.f_90997_;
+ }
+
+ private float realPartialTick;
+ public float getPartialTick() {
+ return this.realPartialTick;
}
public EntityModelSet m_167973_() {