Skip to content

Commit

Permalink
fix scroll capping
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceWalkerRS committed Dec 23, 2023
1 parent 5df0b0e commit edeacd8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import org.lwjgl.opengl.GL11;

import com.mojang.blaze3d.vertex.BufferBuilder;

import com.terraformersmc.modmenu.util.GlUtil;
import com.terraformersmc.modmenu.util.ListWidgetHelper;
import com.terraformersmc.modmenu.util.MathUtil;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.ListWidget;

public abstract class EntryListWidget extends ListWidget {
public abstract class EntryListWidget extends ListWidget implements ListWidgetHelper {

protected double scrollAmount;
private boolean scrolling;
Expand Down Expand Up @@ -295,6 +297,20 @@ public void setScrollAmount(double amount) {
this.scrollAmount = amount;
}

@Override
public void doCapScrolling() {
int max = this.getHeight() - (this.maxY - this.minY - 4);
if (max < 0) {
max /= 2;
}
if (this.scrollAmount < 0.0F) {
this.scrollAmount = 0.0F;
}
if (this.scrollAmount > max) {
this.scrollAmount = max;
}
}

protected int getMaxScroll() {
return Math.max(0, this.getHeight() - (this.maxY - this.minY - 4));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.terraformersmc.modmenu.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.terraformersmc.modmenu.util.ListWidgetHelper;

import net.minecraft.client.gui.widget.ListWidget;

@Mixin(ListWidget.class)
public class MixinListWidget implements ListWidgetHelper {

@Inject(method = "capScrolling", at = @At("HEAD"))
private void modmenu$capScrolling(CallbackInfo ci) {
this.doCapScrolling();
}

@Override
public void doCapScrolling() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.terraformersmc.modmenu.util;

public interface ListWidgetHelper {

void doCapScrolling();

}

0 comments on commit edeacd8

Please sign in to comment.