Skip to content

Commit

Permalink
fix: #9 Do not call the wrapper before it is created
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonCaramel committed Nov 2, 2023
1 parent 0b19e22 commit 9b20329
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions common/src/main/java/moe/caramel/chat/mixin/MixinEditBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ public abstract class MixinEditBox implements EditBoxController {
@Shadow public int cursorPos;
@Shadow public String value;

@Redirect(
method = "<init>(Lnet/minecraft/client/gui/Font;IIIILnet/minecraft/client/gui/components/EditBox;Lnet/minecraft/network/chat/Component;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/EditBox;setValue(Ljava/lang/String;)V")
)
private void init(final EditBox self, final String value) {
this.caramelChat$wrapper = new WrapperEditBox((EditBox) (Object) this);
self.setValue(value);
}

@Inject(
method = "<init>(Lnet/minecraft/client/gui/Font;IIIILnet/minecraft/client/gui/components/EditBox;Lnet/minecraft/network/chat/Component;)V",
at = @At("TAIL")
)
private void init(final CallbackInfo ci) {
this.caramelChat$wrapper = new WrapperEditBox((EditBox) (Object) this);
private void lazyInit(final CallbackInfo ci) {
if (this.caramelChat$wrapper == null) {
this.caramelChat$wrapper = new WrapperEditBox((EditBox) (Object) this);
}
this.caramelChat$formatter = this.formatter; // Cache
this.caramelChat$caretFormatter();
}
Expand Down

0 comments on commit 9b20329

Please sign in to comment.