forked from FabricMC/fabric
fix #71
This commit is contained in:
parent
6593414eae
commit
113fc3c3a4
1 changed files with 25 additions and 15 deletions
|
@ -41,7 +41,11 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
|||
@Shadow
|
||||
protected abstract void setSelectedTab(ItemGroup itemGroup_1);
|
||||
|
||||
private int currentPage = 0;
|
||||
@Shadow
|
||||
public abstract int method_2469(); /* XXX getSelectedTab XXX */
|
||||
|
||||
// "static" matches selectedTab
|
||||
private static int fabric_currentPage = 0;
|
||||
|
||||
private int fabric_getPageOffset(int page) {
|
||||
switch (page) {
|
||||
|
@ -64,19 +68,19 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
|||
|
||||
@Override
|
||||
public void fabric_nextPage() {
|
||||
if (fabric_getPageOffset(currentPage + 1) > ItemGroup.GROUPS.length) {
|
||||
if (fabric_getPageOffset(fabric_currentPage + 1) > ItemGroup.GROUPS.length) {
|
||||
return;
|
||||
}
|
||||
currentPage++;
|
||||
fabric_currentPage++;
|
||||
fabric_updateSelection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabric_previousPage() {
|
||||
if (currentPage == 0) {
|
||||
if (fabric_currentPage == 0) {
|
||||
return;
|
||||
}
|
||||
currentPage--;
|
||||
fabric_currentPage--;
|
||||
fabric_updateSelection();
|
||||
}
|
||||
|
||||
|
@ -88,16 +92,22 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
|||
@Override
|
||||
public boolean fabric_isButtonEnabled(FabricCreativeGuiComponents.Type type) {
|
||||
if (type == FabricCreativeGuiComponents.Type.NEXT) {
|
||||
return !(fabric_getPageOffset(currentPage + 1) > ItemGroup.GROUPS.length);
|
||||
return !(fabric_getPageOffset(fabric_currentPage + 1) > ItemGroup.GROUPS.length);
|
||||
}
|
||||
if (type == FabricCreativeGuiComponents.Type.PREVIOUS) {
|
||||
return currentPage != 0;
|
||||
return fabric_currentPage != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void fabric_updateSelection() {
|
||||
setSelectedTab(ItemGroup.GROUPS[fabric_getPageOffset(currentPage)]);
|
||||
int minPos = fabric_getPageOffset(fabric_currentPage);
|
||||
int maxPos = fabric_getPageOffset(fabric_currentPage + 1) - 1;
|
||||
int curPos = method_2469();
|
||||
|
||||
if (curPos < minPos || curPos > maxPos) {
|
||||
setSelectedTab(ItemGroup.GROUPS[fabric_getPageOffset(fabric_currentPage)]);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onInitialized", at = @At("RETURN"))
|
||||
|
@ -114,42 +124,42 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
|||
|
||||
@Inject(method = "setSelectedTab", at = @At("HEAD"), cancellable = true)
|
||||
private void setSelectedTab(ItemGroup itemGroup, CallbackInfo info) {
|
||||
if (!isGroupVisible(itemGroup)) {
|
||||
if (!fabric_isGroupVisible(itemGroup)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "method_2471", at = @At("HEAD"), cancellable = true)
|
||||
private void method_2471(ItemGroup itemGroup, int mx, int my, CallbackInfoReturnable<Boolean> info) {
|
||||
if (!isGroupVisible(itemGroup)) {
|
||||
if (!fabric_isGroupVisible(itemGroup)) {
|
||||
info.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "isClickInTab", at = @At("HEAD"), cancellable = true)
|
||||
private void isClickInTab(ItemGroup itemGroup, double mx, double my, CallbackInfoReturnable<Boolean> info) {
|
||||
if (!isGroupVisible(itemGroup)) {
|
||||
if (!fabric_isGroupVisible(itemGroup)) {
|
||||
info.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "method_2468", at = @At("HEAD"), cancellable = true)
|
||||
private void method_2468(ItemGroup itemGroup, CallbackInfo info) {
|
||||
if (!isGroupVisible(itemGroup)) {
|
||||
if (!fabric_isGroupVisible(itemGroup)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isGroupVisible(ItemGroup itemGroup) {
|
||||
private boolean fabric_isGroupVisible(ItemGroup itemGroup) {
|
||||
if (FabricCreativeGuiComponents.COMMON_GROUPS.contains(itemGroup)) {
|
||||
return true;
|
||||
}
|
||||
return currentPage == fabric_getOffsetPage(itemGroup.getId());
|
||||
return fabric_currentPage == fabric_getOffsetPage(itemGroup.getId());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fabric_currentPage() {
|
||||
return currentPage;
|
||||
return fabric_currentPage;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue