This commit is contained in:
Mrbysco 2024-03-06 00:10:50 +01:00
commit 7e0e86744c
4 changed files with 30 additions and 12 deletions

View file

@ -226,7 +226,7 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
if (buttonID == 0) { if (buttonID == 0) {
this.autoInsert = !this.autoInsert; this.autoInsert = !this.autoInsert;
} else { } else {
this.filter.onButtonPressed(buttonID); this.filter.onButtonPressed(buttonID - 1);
} }
} }
} }

View file

@ -11,18 +11,24 @@
package de.ellpeck.actuallyadditions.mod.inventory.gui; package de.ellpeck.actuallyadditions.mod.inventory.gui;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Renderable; import net.minecraft.client.gui.components.Renderable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.network.PacketDistributor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class FilterSettingsGui { public class FilterSettingsGui {
@ -32,18 +38,26 @@ public class FilterSettingsGui {
public Buttons.SmallerButton whitelistButton; public Buttons.SmallerButton whitelistButton;
public Buttons.SmallerButton modButton; public Buttons.SmallerButton modButton;
public FilterSettingsGui(FilterSettings settings, int x, int y, SackGui gui) { public FilterSettingsGui(FilterSettings settings, int x, int y, Consumer<AbstractButton> buttonConsumer, int idOffset) {
this.theSettings = settings; this.theSettings = settings;
this.whitelistButton = new Buttons.SmallerButton( x, y, Component.literal("WH"), true, $ -> gui.buttonClicked(1)); //TODO these need translation keys this.whitelistButton = new Buttons.SmallerButton( x, y, Component.literal("WH"), true, $ -> buttonClicked(idOffset)); //TODO these need translation keys
gui.renderables.add(this.whitelistButton); buttonConsumer.accept(this.whitelistButton);
y += 14; y += 14;
this.modButton = new Buttons.SmallerButton( x, y, Component.literal("MO"), true, $ -> gui.buttonClicked(2)); this.modButton = new Buttons.SmallerButton( x, y, Component.literal("MO"), true, $ -> buttonClicked(idOffset + 1));
gui.renderables.add(this.modButton); buttonConsumer.accept(this.modButton);
this.tick(); this.tick();
} }
public void buttonClicked(int id) {
CompoundTag data = new CompoundTag();
data.putInt("ButtonID", id);
data.putInt("PlayerID", Minecraft.getInstance().player.getId());
data.putString("WorldID", Minecraft.getInstance().level.dimension().location().toString());
PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER));
}
public void tick() { public void tick() {
this.whitelistButton.setMessage(Component.literal("WH").withStyle(this.theSettings.isWhitelist this.whitelistButton.setMessage(Component.literal("WH").withStyle(this.theSettings.isWhitelist
? ChatFormatting.DARK_GREEN ? ChatFormatting.DARK_GREEN

View file

@ -52,10 +52,10 @@ public class SackGui extends AAScreen<SackContainer> {
public void init() { public void init() {
super.init(); super.init();
this.filter = new FilterSettingsGui(this.container.filter, this.leftPos + 138, this.topPos + 10, this); this.filter = new FilterSettingsGui(this.container.filter, this.leftPos + 138, this.topPos + 10, this::addRenderableWidget, 1);
this.buttonAutoInsert = Button.builder( this.buttonAutoInsert = Button.builder(
Component.literal(this.container.autoInsert? "I" : "O") Component.literal("I")
.withStyle(this.container.autoInsert? ChatFormatting.DARK_GREEN : ChatFormatting.RED), .withStyle(this.container.autoInsert? ChatFormatting.DARK_GREEN : ChatFormatting.RED),
(button) -> { (button) -> {
this.container.autoInsert = !this.container.autoInsert; this.container.autoInsert = !this.container.autoInsert;
@ -72,7 +72,7 @@ public class SackGui extends AAScreen<SackContainer> {
CompoundTag data = new CompoundTag(); CompoundTag data = new CompoundTag();
data.putInt("ButtonID", id); data.putInt("ButtonID", id);
data.putInt("PlayerID", Minecraft.getInstance().player.getId()); data.putInt("PlayerID", Minecraft.getInstance().player.getId());
data.putString("WorldID", Minecraft.getInstance().level.dimension().location().getPath()); data.putString("WorldID", Minecraft.getInstance().level.dimension().location().toString());
PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER)); PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER));
} }

View file

@ -24,9 +24,13 @@ public class FilterSettings {
public boolean isWhitelist; public boolean isWhitelist;
public boolean respectMod; public boolean respectMod;
private boolean lastWhitelist; private boolean lastWhitelist;
private boolean lastRespectNBT;
private boolean lastRespectMod; private boolean lastRespectMod;
public enum Buttons {
WHITELIST,
MOD
}
public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMod) { public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMod) {
this.filterInventory = new ItemStackHandlerAA(slots) { this.filterInventory = new ItemStackHandlerAA(slots) {
@Override @Override
@ -101,9 +105,9 @@ public class FilterSettings {
} }
public void onButtonPressed(int id) { public void onButtonPressed(int id) {
if (id == 1) { if (id == Buttons.WHITELIST.ordinal()) {
this.isWhitelist = !this.isWhitelist; this.isWhitelist = !this.isWhitelist;
} else if (id == 2) { } else if (id == Buttons.MOD.ordinal()) {
this.respectMod = !this.respectMod; this.respectMod = !this.respectMod;
} }
} }