Skip to content

Commit

Permalink
Update to BTA 7.1-pre1a (#1)
Browse files Browse the repository at this point in the history
* Update to BTA 7.1-pre1a

* Fix shifted button offsets
  • Loading branch information
ressidell authored Apr 14, 2024
1 parent 6ab1363 commit 0aed015
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 100 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ dependencies {

// Helper library
// If you do not need Halplibe you can comment this line out or delete this line
// modImplementation "com.github.Turnip-Labs:bta-halplibe:${project.halplibe_version}"
modImplementation "com.github.Turnip-Labs:bta-halplibe:${project.halplibe_version}"

modImplementation "ModMenu:ModMenu:2.0.0"
modImplementation "ModMenu:ModMenu:2.0.3"

implementation "org.slf4j:slf4j-api:1.8.0-beta4"
implementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0"
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
org.gradle.jvmargs=-Xmx2G

# BTA
bta_version=1.7.7.0_02
bta_version=7.1-pre1a

# Loader
loader_version=0.14.19-babric.1-bta

# HalpLibe
# halplibe_version=2.3.0
halplibe_version=3.2.1

# Mod
mod_version=1.1.0
mod_version=1.1.1
mod_group=rootenginear
mod_name=sortchest
3 changes: 1 addition & 2 deletions src/main/java/rootenginear/sortchest/ModMenuModule.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rootenginear.sortchest;

import io.github.prospector.modmenu.api.ModMenuApi;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import rootenginear.sortchest.gui.GuiModMenuOptionsPage;

Expand All @@ -15,6 +14,6 @@ public String getModId() {

@Override
public Function<GuiScreen, ? extends GuiScreen> getConfigScreenFactory() {
return (screenBase -> new GuiModMenuOptionsPage(screenBase, Minecraft.getMinecraft(Minecraft.class).gameSettings));
return (GuiModMenuOptionsPage::getOptionsScreen);
}
}
3 changes: 2 additions & 1 deletion src/main/java/rootenginear/sortchest/SortChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rootenginear.sortchest.gui.GuiModMenuOptionsPage;

public class SortChest implements ModInitializer {
public class SortChest implements ModInitializer {
public static final String MOD_ID = "sortchest";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

Expand Down
67 changes: 40 additions & 27 deletions src/main/java/rootenginear/sortchest/gui/GuiModMenuOptionsPage.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
package rootenginear.sortchest.gui;

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.options.GuiOptionsPageControls;
import net.minecraft.client.option.GameSettings;
import net.minecraft.client.gui.options.GuiOptions;
import net.minecraft.client.gui.options.components.KeyBindingComponent;
import net.minecraft.client.gui.options.data.OptionsPage;
import net.minecraft.client.gui.options.data.OptionsPages;
import rootenginear.sortchest.interfaces.ISortChestSettings;
import rootenginear.sortchest.mixin.accessor.GuiOptionsPageControlsAccessor;
import rootenginear.sortchest.mixin.accessor.GuiOptionsPageOptionBaseAccessor;

import java.util.ArrayList;

public class GuiModMenuOptionsPage extends GuiOptionsPageControls {
public GuiModMenuOptionsPage(GuiScreen parent, GameSettings settings) {
super(parent, settings);

GuiOptionsPageOptionBaseAccessor opobThis = (GuiOptionsPageOptionBaseAccessor) this;
opobThis.setCategoryKeys(new ArrayList<>());
opobThis.setOptions(new ArrayList<>());
opobThis.setButtons(new ArrayList<>());

GuiOptionsPageControlsAccessor opcThis = (GuiOptionsPageControlsAccessor) this;
opcThis.setKeyBindings(new ArrayList<>());

ISortChestSettings iSortChestSettings = (ISortChestSettings) settings;
this.addKeyBindingsCategory(
"options.category.sortchest",
iSortChestSettings.bta_rootenginear_mods$getKeySort(),
iSortChestSettings.bta_rootenginear_mods$getKeyRefill(),
iSortChestSettings.bta_rootenginear_mods$getKeyFill(),
iSortChestSettings.bta_rootenginear_mods$getKeyDump()
);
import turniplabs.halplibe.helper.ModVersionHelper;
import turniplabs.halplibe.util.ClientStartEntrypoint;

import static rootenginear.sortchest.SortChest.LOGGER;


public class GuiModMenuOptionsPage implements ClientStartEntrypoint {
public static ISortChestSettings modSettings;
public static OptionsPage sortOptions;

public static GuiOptions getOptionsScreen(GuiScreen parent){
return new GuiOptions(parent, Minecraft.getMinecraft(Minecraft.class).gameSettings, sortOptions);
}

@Override
public void beforeClientStart() {

}

@Override
public void afterClientStart() {
modSettings = (ISortChestSettings) Minecraft.getMinecraft(Minecraft.class).gameSettings;
sortOptions = new OptionsPage("options.category.sortchest")
.withComponent(new KeyBindingComponent(modSettings.bta_rootenginear_mods$getKeyDump()))
.withComponent(new KeyBindingComponent(modSettings.bta_rootenginear_mods$getKeyFill()))
.withComponent(new KeyBindingComponent(modSettings.bta_rootenginear_mods$getKeyRefill()))
.withComponent(new KeyBindingComponent(modSettings.bta_rootenginear_mods$getKeySort()));


if(ModVersionHelper.isModPresent("modmenu")){
OptionsPages.register(sortOptions);
}
//OptionsPages.CONTROLS.withComponent(keybindCategory);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@

@Mixin(value = GameSettings.class, remap = false)
public class GameSettingsMixin implements ISortChestSettings {
@Unique
public KeyBinding keySort = new KeyBinding("sortchest.sort", 0x1F);
@Unique
public KeyBinding keyRefill = new KeyBinding("sortchest.refill", 0x13);
@Unique
public KeyBinding keyFill = new KeyBinding("sortchest.fill", 0x21);
@Unique
public KeyBinding keyDump = new KeyBinding("sortchest.dump", 0x20);

public KeyBinding keyRefill = new KeyBinding("sortchest.refill").bindKeyboard(0x13); //R
public KeyBinding keyFill = new KeyBinding("sortchest.fill").bindKeyboard(0x21); //F
public KeyBinding keyDump = new KeyBinding("sortchest.dump").bindKeyboard(0x20); //D
public KeyBinding keySort = new KeyBinding("sortchest.sort").bindKeyboard( 0x1F); //S

@Override
public KeyBinding bta_rootenginear_mods$getKeySort() {
return this.keySort;
}

@Override
public KeyBinding bta_rootenginear_mods$getKeyRefill() {
return this.keyRefill;
Expand Down
46 changes: 28 additions & 18 deletions src/main/java/rootenginear/sortchest/mixin/GuiContainerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ private static Comparator<ItemStack> compareItemStacks() {

@Unique
private static void swap(PlayerController playerController, EntityPlayer entityPlayer, int windowId, int x, int i) {
playerController.doInventoryAction(windowId, InventoryAction.CLICK_LEFT, new int[]{x, 0}, entityPlayer);
playerController.doInventoryAction(windowId, InventoryAction.CLICK_LEFT, new int[]{i, 0}, entityPlayer);
playerController.doInventoryAction(windowId, InventoryAction.CLICK_LEFT, new int[]{x, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.CLICK_LEFT, new int[]{x, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.CLICK_LEFT, new int[]{i, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.CLICK_LEFT, new int[]{x, 0}, entityPlayer);
}

@Unique
Expand All @@ -156,30 +156,30 @@ private void mergeItemsInChest(PlayerController playerController, EntityPlayer e
int nextSlot = invData.indexOf(itemData);
if (nextSlot == -1) continue;

playerController.doInventoryAction(windowId, InventoryAction.CLICK_LEFT, new int[]{firstSlotIndex, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.CLICK_LEFT, new int[]{firstSlotIndex, 0}, entityPlayer);

do {
playerController.doInventoryAction(windowId, InventoryAction.CLICK_LEFT, new int[]{nextSlot, 0}, entityPlayer);
playerController.doInventoryAction(windowId, InventoryAction.CLICK_LEFT, new int[]{nextSlot, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.CLICK_LEFT, new int[]{nextSlot, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.CLICK_LEFT, new int[]{nextSlot, 0}, entityPlayer);
invData.set(nextSlot, null);
} while ((nextSlot = invData.indexOf(itemData)) != -1);

playerController.doInventoryAction(windowId, InventoryAction.CLICK_LEFT, new int[]{firstSlotIndex, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.CLICK_LEFT, new int[]{firstSlotIndex, 0}, entityPlayer);
}
}

@Unique
private void dumpItemFromChest(PlayerController playerController, EntityPlayer entityPlayer, int windowId) {
playerController.doInventoryAction(windowId, InventoryAction.MOVE_ALL, new int[]{0, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.MOVE_ALL, new int[]{0, 0}, entityPlayer);
}

@Unique
private void dumpItemToChest(PlayerController playerController, EntityPlayer entityPlayer, int windowId, int countInvSlots) {
// Dump inventory (not hotbar) content
playerController.doInventoryAction(windowId, InventoryAction.MOVE_ALL, new int[]{countInvSlots, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.MOVE_ALL, new int[]{countInvSlots, 0}, entityPlayer);

// Dump hotbar content
playerController.doInventoryAction(windowId, InventoryAction.MOVE_ALL, new int[]{countInvSlots + (9 * 3), 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.MOVE_ALL, new int[]{countInvSlots + (9 * 3), 0}, entityPlayer);
}

@Unique
Expand All @@ -199,19 +199,19 @@ private void refillChest(PlayerController playerController, EntityPlayer entityP
String invItemStr = invItem.itemID + ":" + invItem.getMetadata();
if (!chestItems.contains(invItemStr)) continue;

playerController.doInventoryAction(windowId, InventoryAction.MOVE_SIMILAR, new int[]{i, 0}, entityPlayer);
playerController.handleInventoryMouseClick(windowId, InventoryAction.MOVE_SIMILAR, new int[]{i, 0}, entityPlayer);
chestItems.remove(invItemStr);
}
}

@Inject(method = "initGui", at = @At("TAIL"))
@Inject(method = "init", at = @At("TAIL"))
private void addChestButtons(CallbackInfo ci) {
if (Utils.isNotChest(this)) return;

GuiScreen screenThis = (GuiScreen) (Object) this;

int centerX = (screenThis.width - xSize) / 2;
int centerY = (screenThis.height - ySize) / 2;
int centerX = (screenThis.width) / 2;
int centerY = (screenThis.height) / 2;

ISortChestSettings gameSettings = ((ISortChestSettings) Minecraft.getMinecraft(Minecraft.class).gameSettings);
String keySort = gameSettings.bta_rootenginear_mods$getKeySort().getKeyName();
Expand All @@ -221,25 +221,35 @@ private void addChestButtons(CallbackInfo ci) {

I18n i18n = I18n.getInstance();



int textPadding = 6;
int buttonWidth = 12;
int buttonHeight = 12;
int buttonXSeparator = 2;
int buttonStartXPos = centerX + (xSize / 2) - 20;
int buttonYSeparator = 68;
int buttonStartYPos = centerY - 13;

screenThis.controlList.clear();
screenThis.controlList.add(
new GuiSortChestButton(0, centerX + xSize - 8 - 12 - 12 - 2, centerY + 4, 12, 12, "⇵", 3,
new GuiSortChestButton(0, buttonStartXPos - buttonWidth - buttonXSeparator, buttonStartYPos-buttonYSeparator, buttonWidth, buttonHeight, "⇵", textPadding,
i18n.translateKey("sortchest.sort") + " [" + keySort + "]"
)
);
screenThis.controlList.add(
new GuiSortChestButton(1, centerX + xSize - 8 - 12, centerY + 4, 12, 12, "∑", 3,
new GuiSortChestButton(1, buttonStartXPos, buttonStartYPos-buttonYSeparator, buttonWidth, buttonHeight, "∑", textPadding,
i18n.translateKey("sortchest.refill") + " [" + keyRefill + "]"
)
);

screenThis.controlList.add(
new GuiSortChestButton(2, centerX + xSize - 8 - 12 - 12 - 2, centerY + ySize - 96 - 1, 12, 12, "⊼", 3,
new GuiSortChestButton(2, buttonStartXPos - buttonWidth - buttonXSeparator, buttonStartYPos, buttonWidth, buttonHeight, "⊼", textPadding,
i18n.translateKey("sortchest.fill") + " [" + keyFill + "]"
)
);
screenThis.controlList.add(
new GuiSortChestButton(3, centerX + xSize - 8 - 12, centerY + ySize - 96 - 1, 12, 12, "⊻", 3,
new GuiSortChestButton(3, buttonStartXPos , buttonStartYPos, buttonWidth, buttonHeight, "⊻", textPadding,
i18n.translateKey("sortchest.dump") + " [" + keyDump + "]"
)
);
Expand Down

This file was deleted.

This file was deleted.

6 changes: 5 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"main": [
"rootenginear.sortchest.SortChest"
],
"afterClientStart": [
"rootenginear.sortchest.gui.GuiModMenuOptionsPage"
],
"modmenu": [
"rootenginear.sortchest.ModMenuModule"
]
Expand All @@ -27,7 +30,8 @@
"sortchest.mixins.json"
],
"depends": {
"fabricloader": ">=0.13.3"
"fabricloader": ">=0.13.3",
"halplibe": ">=3.2.1"
},
"suggests": {
"modmenu": ">=2.0.0"
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/sortchest.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"GuiScreenMixin",
"I18nMixin",
"accessor.GuiChestAccessor",
"accessor.GuiOptionsPageControlsAccessor",
"accessor.GuiOptionsPageOptionBaseAccessor",
"accessor.LanguageAccessor"
],
"injectors": {
Expand Down

0 comments on commit 0aed015

Please sign in to comment.