-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix server crash related to the primordial infestation effect
- Loading branch information
1 parent
89da508
commit 3dcdc0a
Showing
8 changed files
with
136 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/com/github/elenterius/biomancy/mixin/client/AbstractSignEditScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.elenterius.biomancy.mixin.client; | ||
|
||
import com.github.elenterius.biomancy.init.ModMobEffects; | ||
import com.github.elenterius.biomancy.styles.Fonts; | ||
import com.github.elenterius.biomancy.util.TransliterationUtil; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraft.client.gui.screens.inventory.AbstractSignEditScreen; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.level.block.entity.SignBlockEntity; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(AbstractSignEditScreen.class) | ||
public abstract class AbstractSignEditScreenMixin extends Screen { | ||
|
||
@Shadow | ||
@Final | ||
private String[] messages; | ||
|
||
@Shadow | ||
@Final | ||
private SignBlockEntity sign; | ||
|
||
private AbstractSignEditScreenMixin(Component title) { | ||
super(title); | ||
} | ||
|
||
@Inject(method = "removed", at = @At(value = "HEAD")) | ||
private void onRemoved(CallbackInfo ci) { | ||
if (minecraft == null) return; | ||
if (minecraft.player == null) return; | ||
if (!minecraft.player.hasEffect(ModMobEffects.PRIMORDIAL_INFESTATION.get())) return; | ||
|
||
int maxWidth = biomancy$approximateMaxLineWidth(); | ||
for (int i = 0; i < messages.length; i++) { | ||
messages[i] = biomancy$transform(messages[i], maxWidth); | ||
} | ||
} | ||
|
||
@Unique | ||
private static String biomancy$transform(String text, int maxWidth) { | ||
String transliterated = TransliterationUtil.transliterate(text); | ||
return StringUtils.abbreviate(transliterated, maxWidth); | ||
} | ||
|
||
@Unique | ||
private int biomancy$approximateMaxLineWidth() { | ||
return Mth.floor((float) sign.getMaxTextLineWidth() / (Fonts.CARO_INVITICA_GLYPH_WIDTH - 1)); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/github/elenterius/biomancy/mixin/client/AnvilScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.elenterius.biomancy.mixin.client; | ||
|
||
import com.github.elenterius.biomancy.init.ModMobEffects; | ||
import com.github.elenterius.biomancy.util.TransliterationUtil; | ||
import net.minecraft.client.gui.screens.inventory.AnvilScreen; | ||
import net.minecraft.client.gui.screens.inventory.ItemCombinerScreen; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.AnvilMenu; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
|
||
@Mixin(AnvilScreen.class) | ||
public abstract class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> { | ||
|
||
@Shadow | ||
@Final | ||
private Player player; | ||
|
||
private AnvilScreenMixin(AnvilMenu menu, Inventory playerInventory, Component title, ResourceLocation texture) { | ||
super(menu, playerInventory, title, texture); | ||
} | ||
|
||
@ModifyVariable(method = "onNameChanged", at = @At(value = "HEAD"), argsOnly = true) | ||
private String onNameChanged(String text) { | ||
if (menu.getSlot(0).hasItem() && player.hasEffect(ModMobEffects.PRIMORDIAL_INFESTATION.get())) { | ||
return TransliterationUtil.transliterate(text); | ||
} | ||
|
||
return text; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters