Skip to content

Commit

Permalink
Minecraft/FontRenderer 인스턴스를 public method에서 얻기
Browse files Browse the repository at this point in the history
- getMaxLength 대신 Predicate<String>에 문자열을 넣어서 커밋 가능한 문자열인지 테스트
- 잘못된 인스턴스를 얻어서 발생하는 크래시 현상 해결
  • Loading branch information
sokcuri committed Jul 19, 2020
1 parent 28df02d commit e8819df
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.gui.fonts.TextInputUtil;

import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class TextInputUtilWrapper implements TextComponentWrapper {
Expand All @@ -16,11 +17,11 @@ public TextInputUtilWrapper(TextInputUtil inputUtil) {
}

public Minecraft getMinecraftInstance() {
return ObfuscatedField.$TextInputUtil.minecraft.get(base);
return Minecraft.getInstance();
}

public FontRenderer getFontRenderer() {
return ObfuscatedField.$TextInputUtil.fontRenderer.get(base);
return Minecraft.getInstance().fontRenderer;
}

public Supplier<String> getSupplier() {
Expand All @@ -31,8 +32,8 @@ public Consumer<String> getConsumer() {
return ObfuscatedField.$TextInputUtil.textConsumer.get(base);
}

public int getMaxStringLength() {
return ObfuscatedField.$TextInputUtil.maxStringLength.get(base);
public Predicate<String> getPredicate() {
return ObfuscatedField.$TextInputUtil.textPredicate.get(base);
}

@Override
Expand Down Expand Up @@ -85,7 +86,7 @@ public String getText() {

@Override
public boolean setText(String str) {
if (getFontRenderer().getStringWidth(str) <= getMaxStringLength()) {
if (getPredicate().test(str)) {
getConsumer().accept(str);
return true;
}
Expand All @@ -102,7 +103,10 @@ public void writeText(String str) {
} else {
res = str + s;
}
if (setText(res) && getText().length() == res.length()) {

boolean textCommitted = setText(res);

if (textCommitted && getText().length() == res.length()) {
setCursorPosition(cursorPosition + 1);
setCursorPosition2(cursorPosition + 1);
}
Expand Down

0 comments on commit e8819df

Please sign in to comment.