Skip to content

Commit

Permalink
Initial update to 1.20.2
Browse files Browse the repository at this point in the history
Some things are still broken, but I'm making a commit here to mark the
work that has been done so far.
  • Loading branch information
arm32x committed Sep 21, 2023
1 parent 2e643ab commit ac6223d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx2G
# Gradle Plugins
android_git_version_version=0.4.14
loom_version=1.2-SNAPSHOT
loom_version=1.3-SNAPSHOT
shadow_version=7.1.2
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.2
loader_version=0.14.21
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22
# Dependencies
# check these on https://modmuss50.me/fabric.html
fabric_version=0.83.1+1.20.1
fabric_version=0.89.1+1.20.2
msgpack_java_version=0.9.3
# Test dependencies
junit_version=5.9.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.text.OrderedText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -45,6 +46,10 @@ public class MultilineTextFieldWidget extends TextFieldWidget {
// support tabs yet.
private static final int INDENT_SIZE = 4;

// The amount of time the cursor will spend being either visible or
// invisible before switching to the other state.
private static final long CURSOR_BLINK_INTERVAL_MS = 300;

private final EditBox editBox;

private boolean horizontalScrollEnabled;
Expand Down Expand Up @@ -142,7 +147,8 @@ public int getWordSkipPosition(int wordOffset) {
}

@Override
public void moveCursor(int offset) {
public void moveCursor(int offset, boolean hasShiftDown) {
editBox.setSelecting(hasShiftDown);
editBox.moveCursor(CursorMovement.RELATIVE, offset);
}

Expand All @@ -165,18 +171,18 @@ private void moveCursor(double mouseX, double mouseY) {
charIndex++;
}

setCursor(charIndex);
setCursor(charIndex, false);
}

@Override
public void setCursor(int cursor) {
public void setCursor(int cursor, boolean hasShiftDown) {
editBox.setSelecting(hasShiftDown);
editBox.moveCursor(CursorMovement.ABSOLUTE, cursor);
}

@Override
public void setSelectionStart(int cursor) {
editBox.setSelecting(true);
setCursor(cursor);
setCursor(cursor, true);
}

@Override
Expand Down Expand Up @@ -234,21 +240,21 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
if (this.isMouseOver(mouseX, mouseY)) {
boolean changed = false;
if (Screen.hasShiftDown() && isHorizontalScrollEnabled()) {
changed = setHorizontalScroll(getHorizontalScroll() - (int)Math.round(amount * SCROLL_SENSITIVITY));
} else if (isVerticalScrollEnabled()) {
changed = setVerticalScroll(getVerticalScroll() - (int)Math.round(amount * SCROLL_SENSITIVITY));
}
horizontalAmount = Screen.hasShiftDown() ? verticalAmount : horizontalAmount;
verticalAmount = Screen.hasShiftDown() ? 0 : verticalAmount;

boolean changed = setHorizontalScroll(getHorizontalScroll() - (int)Math.round(horizontalAmount * SCROLL_SENSITIVITY));
changed = changed || setVerticalScroll(getVerticalScroll() - (int)Math.round(verticalAmount * SCROLL_SENSITIVITY));

// This updates the position of the suggestions window.
if (cursorChangeListener != null) {
cursorChangeListener.run();
}
return changed;
} else {
return super.mouseScrolled(mouseX, mouseY, amount);
return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
}
}

Expand Down Expand Up @@ -278,7 +284,8 @@ public void renderButton(DrawContext context, int mouseX, int mouseY, float delt
int x = this.getX() + (self.getDrawsBackground() ? 4 : 0) - horizontalScroll;
int y = this.getY() + (self.getDrawsBackground() ? 3 : 0) - verticalScroll;

boolean showCursor = isFocused() && self.getFocusedTicks() / 6 % 2 == 0;
long timeSinceLastSwitchFocusMs = Util.getMeasuringTimeMs() - self.getLastSwitchFocusTime();
boolean showCursor = isFocused() && timeSinceLastSwitchFocusMs / CURSOR_BLINK_INTERVAL_MS % 2 == 0;
boolean lineCursor = getCursor() < getText().length() || getText().length() >= self.invokeGetMaxLength();

int cursorLine = getCurrentLineIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
return suggestor.mouseScrolled(amount)
|| super.mouseScrolled(mouseX, mouseY, amount);
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
return suggestor.mouseScrolled(Screen.hasShiftDown() ? 0 : verticalAmount)
|| super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
Expand Down Expand Up @@ -247,15 +248,17 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
for (CommandEditor editor : editors) {
if (editor.mouseScrolled(mouseX, mouseY, amount)) return true;
if (editor.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) return true;
}

double amount = Screen.hasShiftDown() ? 0 : verticalAmount;
if (maxScrollOffset != 0 && amount != 0 && mouseY < height - 36 && !Screen.hasShiftDown()) {
setScrollOffset(getScrollOffset() - (int)Math.round(amount * SCROLL_SENSITIVITY));
return true;
}
return super.mouseScrolled(mouseX, mouseY, amount);
return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
}

public int getScrollOffset() {
Expand Down Expand Up @@ -335,7 +338,8 @@ public void setFocusedEditor(CommandEditor editor) {

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
renderBackground(context);
// Avoid this.renderBackground because it's a no-op (see below).
super.renderBackground(context, mouseX, mouseY, delta);

for (CommandEditor editor : editors) {
editor.render(context, mouseX, mouseY, delta);
Expand Down Expand Up @@ -364,6 +368,12 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
matrices.pop();
}

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
// No-op. This is a hack to prevent the background from being drawn a
// second time from super.render.
}

@Override
public boolean isDirty() {
return editors.stream().anyMatch(Dirtyable::isDirty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.CommandBlockBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.client.network.ClientConnectionState;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Environment(EnvType.CLIENT)
@Mixin(ClientPlayNetworkHandler.class)
public final class ClientPlayNetworkHandlerMixin {
@Shadow private @Final MinecraftClient client;
public abstract class ClientPlayNetworkHandlerMixin extends ClientCommonNetworkHandler {
protected ClientPlayNetworkHandlerMixin(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) {
super(client, connection, connectionState);
}

// Injecting into a lambda, who knows how stable this is...
@Inject(method = "method_38542(Lnet/minecraft/network/packet/s2c/play/BlockEntityUpdateS2CPacket;Lnet/minecraft/block/entity/BlockEntity;)V", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface TextFieldWidgetAccessor {
@Accessor int getEditableColor();
@Accessor int getUneditableColor();
@Accessor TextRenderer getTextRenderer();
@Accessor int getFocusedTicks();
@Accessor long getLastSwitchFocusTime();
@Accessor boolean isFocusUnlocked();

@Invoker int invokeGetMaxLength();
Expand Down

0 comments on commit ac6223d

Please sign in to comment.