Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop "You can only sleep at night" message filling the chat #102

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class LoadingConfig {
public boolean fixIgnisFruitAABB;
public boolean fixNetherLeavesFaceRendering;
public boolean optimizeASMDataTable;
public boolean squashBedErrorMessage;

// render debug
public boolean renderDebug;
Expand Down Expand Up @@ -240,6 +241,12 @@ public LoadingConfig(File file) {
true,
"Optimize ASMDataTable getAnnotationsFor for faster startup")
.getBoolean();
squashBedErrorMessage = config.get(
"fixes",
"squashBedErrorMessage",
true,
"Stop \"You can only sleep at night\" message filling the chat")
.getBoolean();

increaseParticleLimit = config.get("tweaks", "increaseParticleLimit", true, "Increase particle limit")
.getBoolean();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public enum Mixins {
TargetedMod.VANILLA),
OPTIMIZE_ASMDATATABLE_INDEX(
"forge.MixinASMDataTable", Side.BOTH, () -> Hodgepodge.config.optimizeASMDataTable, TargetedMod.VANILLA),
SQUASH_BED_ERROR_MESSAGE(
"minecraft.MixinNetHandlePlayClient",
Side.CLIENT,
() -> Hodgepodge.config.squashBedErrorMessage,
TargetedMod.VANILLA),
RENDER_DEBUG("minecraft.MixinRenderGlobal", Side.CLIENT, () -> Hodgepodge.config.renderDebug, TargetedMod.VANILLA),

// Potentially obsolete vanilla fixes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.mitchej123.hodgepodge.mixins.minecraft;

import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.play.server.S02PacketChat;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.common.MinecraftForge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(value = NetHandlerPlayClient.class)
public class MixinNetHandlePlayClient {

private static final int randomChannel = 43284;

@Shadow
private Minecraft gameController;

/**
* @author Quarri6343
* @reason Stop "You can only sleep at night" message filling the chat
*/
@Overwrite
public void handleChat(S02PacketChat p_147251_1_) {
ClientChatReceivedEvent event = new ClientChatReceivedEvent(p_147251_1_.func_148915_c());
if (!MinecraftForge.EVENT_BUS.post(event) && event.message != null) {
if (event.message.equals(new ChatComponentTranslation("tile.bed.noSleep", new Object[0]))
|| event.message.equals(new ChatComponentTranslation("tile.bed.notSafe", new Object[0]))
|| event.message.equals(new ChatComponentTranslation("tile.bed.occupied", new Object[0]))) {
this.gameController
.ingameGUI
.getChatGUI()
.printChatMessageWithOptionalDeletion(event.message, randomChannel);
} else {
this.gameController.ingameGUI.getChatGUI().printChatMessage(event.message);
}
}
}
}