1
0
forked from Clones/Controlify

new create world screen compat

This commit is contained in:
isXander
2023-02-22 20:53:56 +00:00
parent f17685535a
commit 84bb9c2a0b
5 changed files with 90 additions and 4 deletions

View File

@ -13,7 +13,7 @@ plugins {
}
group = "dev.isxander"
version = "0.2.0+1.19.4"
version = "0.3.0+1.19.4"
repositories {
mavenCentral()

View File

@ -0,0 +1,41 @@
package dev.isxander.controlify.mixins.feature.screenop.vanilla;
import dev.isxander.controlify.screenop.ScreenProcessor;
import dev.isxander.controlify.screenop.ScreenProcessorProvider;
import dev.isxander.controlify.screenop.compat.vanilla.CreateWorldScreenProcessor;
import net.minecraft.client.gui.components.tabs.Tab;
import net.minecraft.client.gui.components.tabs.TabManager;
import net.minecraft.client.gui.components.tabs.TabNavigationBar;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import java.util.List;
@Mixin(CreateWorldScreen.class)
public class CreateWorldScreenMixin implements ScreenProcessorProvider {
@Shadow private @Nullable TabNavigationBar tabNavigationBar;
@Shadow @Final private TabManager tabManager;
@Unique private final CreateWorldScreenProcessor controlify$screenProcessor
= new CreateWorldScreenProcessor((CreateWorldScreen) (Object) this, this::changeTab);
@Override
public ScreenProcessor<?> screenProcessor() {
return controlify$screenProcessor;
}
private void changeTab(boolean reverse) {
List<Tab> tabs = ((TabNavigationBarAccessor) tabNavigationBar).getTabs();
int currentIndex = tabs.indexOf(tabManager.getCurrentTab());
int newIndex = currentIndex + (reverse ? -1 : 1);
if (newIndex < 0) newIndex = tabs.size() - 1;
if (newIndex >= tabs.size()) newIndex = 0;
tabNavigationBar.selectTab(newIndex);
}
}

View File

@ -0,0 +1,13 @@
package dev.isxander.controlify.mixins.feature.screenop.vanilla;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.gui.components.tabs.Tab;
import net.minecraft.client.gui.components.tabs.TabNavigationBar;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(TabNavigationBar.class)
public interface TabNavigationBarAccessor {
@Accessor
ImmutableList<Tab> getTabs();
}

View File

@ -0,0 +1,30 @@
package dev.isxander.controlify.screenop.compat.vanilla;
import dev.isxander.controlify.controller.Controller;
import dev.isxander.controlify.screenop.ScreenProcessor;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
import java.util.function.Consumer;
public class CreateWorldScreenProcessor extends ScreenProcessor<CreateWorldScreen> {
private final Consumer<Boolean> tabChangeMethod;
public CreateWorldScreenProcessor(CreateWorldScreen screen, Consumer<Boolean> tabChangeMethod) {
super(screen);
this.tabChangeMethod = tabChangeMethod;
}
@Override
protected void handleButtons(Controller<?, ?> controller) {
if (controller.bindings().GUI_NEXT_TAB.justPressed()) {
tabChangeMethod.accept(false);
return;
}
if (controller.bindings().GUI_PREV_TAB.justPressed()) {
tabChangeMethod.accept(true);
return;
}
super.handleButtons(controller);
}
}

View File

@ -12,6 +12,9 @@
"client": [
"compat.sodium.SodiumOptionsGUIAccessor",
"compat.sodium.SodiumOptionsGUIMixin",
"compat.yacl.CyclingControllerElementMixin",
"compat.yacl.SliderControllerElementMixin",
"compat.yacl.YACLScreenMixin",
"core.ClientPacketListenerMixin",
"core.KeyboardHandlerMixin",
"core.MinecraftMixin",
@ -25,6 +28,7 @@
"feature.screenop.vanilla.AbstractSelectionListMixin",
"feature.screenop.vanilla.AbstractSliderButtonMixin",
"feature.screenop.vanilla.ContainerObjectSelectionListEntryMixin",
"feature.screenop.vanilla.CreateWorldScreenMixin",
"feature.screenop.vanilla.CreativeModeInventoryScreenAccessor",
"feature.screenop.vanilla.CreativeModeInventoryScreenMixin",
"feature.screenop.vanilla.JoinMultiplayerScreenAccessor",
@ -36,10 +40,8 @@
"feature.screenop.vanilla.SelectWorldScreenAccessor",
"feature.screenop.vanilla.SelectWorldScreenMixin",
"feature.screenop.vanilla.ServerSelectionListEntryMixin",
"feature.screenop.vanilla.TabNavigationBarAccessor",
"feature.screenop.vanilla.WorldSelectionListEntryMixin",
"compat.yacl.CyclingControllerElementMixin",
"compat.yacl.SliderControllerElementMixin",
"compat.yacl.YACLScreenMixin",
"feature.settingsbutton.ControlsScreenMixin",
"feature.virtualmouse.GameRendererMixin",
"feature.virtualmouse.InputConstantsMixin",