forked from FabricMC/fabric
fix #69
This commit is contained in:
parent
d7b5916416
commit
6593414eae
1 changed files with 26 additions and 19 deletions
|
@ -43,14 +43,32 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
||||||
|
|
||||||
private int currentPage = 0;
|
private int currentPage = 0;
|
||||||
|
|
||||||
|
private int fabric_getPageOffset(int page) {
|
||||||
|
switch (page) {
|
||||||
|
case 0:
|
||||||
|
return 0;
|
||||||
|
case 1:
|
||||||
|
return 12;
|
||||||
|
default:
|
||||||
|
return 12 + ((12 - FabricCreativeGuiComponents.COMMON_GROUPS.size()) * (page - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int fabric_getOffsetPage(int offset) {
|
||||||
|
if (offset < 12) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1 + ((offset - 12) / (12 - FabricCreativeGuiComponents.COMMON_GROUPS.size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fabric_nextPage() {
|
public void fabric_nextPage() {
|
||||||
if ((currentPage + 1) * 12 > ItemGroup.GROUPS.length) {
|
if (fabric_getPageOffset(currentPage + 1) > ItemGroup.GROUPS.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentPage++;
|
currentPage++;
|
||||||
updateSelection();
|
fabric_updateSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +77,7 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentPage--;
|
currentPage--;
|
||||||
updateSelection();
|
fabric_updateSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,7 +88,7 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
||||||
@Override
|
@Override
|
||||||
public boolean fabric_isButtonEnabled(FabricCreativeGuiComponents.Type type) {
|
public boolean fabric_isButtonEnabled(FabricCreativeGuiComponents.Type type) {
|
||||||
if (type == FabricCreativeGuiComponents.Type.NEXT) {
|
if (type == FabricCreativeGuiComponents.Type.NEXT) {
|
||||||
return !((currentPage + 1) * 12 > ItemGroup.GROUPS.length);
|
return !(fabric_getPageOffset(currentPage + 1) > ItemGroup.GROUPS.length);
|
||||||
}
|
}
|
||||||
if (type == FabricCreativeGuiComponents.Type.PREVIOUS) {
|
if (type == FabricCreativeGuiComponents.Type.PREVIOUS) {
|
||||||
return currentPage != 0;
|
return currentPage != 0;
|
||||||
|
@ -78,20 +96,13 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSelection() {
|
private void fabric_updateSelection() {
|
||||||
int nextTab;
|
setSelectedTab(ItemGroup.GROUPS[fabric_getPageOffset(currentPage)]);
|
||||||
if (currentPage == 0) {
|
|
||||||
nextTab = 0;
|
|
||||||
} else {
|
|
||||||
nextTab = 12 + ((12 - FabricCreativeGuiComponents.COMMON_GROUPS.size()) * (currentPage - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
setSelectedTab(ItemGroup.GROUPS[nextTab]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "onInitialized", at = @At("RETURN"))
|
@Inject(method = "onInitialized", at = @At("RETURN"))
|
||||||
private void onInitialized(CallbackInfo info) {
|
private void onInitialized(CallbackInfo info) {
|
||||||
updateSelection();
|
fabric_updateSelection();
|
||||||
|
|
||||||
int xpos = left + 170;
|
int xpos = left + 170;
|
||||||
int ypos = top + 4;
|
int ypos = top + 4;
|
||||||
|
@ -133,11 +144,7 @@ public abstract class MixinCreativePlayerInventoryGui extends AbstractPlayerInve
|
||||||
if (FabricCreativeGuiComponents.COMMON_GROUPS.contains(itemGroup)) {
|
if (FabricCreativeGuiComponents.COMMON_GROUPS.contains(itemGroup)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (itemGroup.getId() < 12) {
|
return currentPage == fabric_getOffsetPage(itemGroup.getId());
|
||||||
return currentPage == 0;
|
|
||||||
}
|
|
||||||
int page = (int) Math.floor((itemGroup.getId() - 12) / (12 - FabricCreativeGuiComponents.COMMON_GROUPS.size()));
|
|
||||||
return currentPage == page + 1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue