mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
Merge branch '1.20.4' of https://github.com/Ellpeck/ActuallyAdditions into 1.20.4
This commit is contained in:
commit
7e0e86744c
4 changed files with 30 additions and 12 deletions
|
@ -226,7 +226,7 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
|||
if (buttonID == 0) {
|
||||
this.autoInsert = !this.autoInsert;
|
||||
} else {
|
||||
this.filter.onButtonPressed(buttonID);
|
||||
this.filter.onButtonPressed(buttonID - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,18 +11,24 @@
|
|||
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
||||
|
||||
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 net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.Renderable;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class FilterSettingsGui {
|
||||
|
@ -32,18 +38,26 @@ public class FilterSettingsGui {
|
|||
public Buttons.SmallerButton whitelistButton;
|
||||
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.whitelistButton = new Buttons.SmallerButton( x, y, Component.literal("WH"), true, $ -> gui.buttonClicked(1)); //TODO these need translation keys
|
||||
gui.renderables.add(this.whitelistButton);
|
||||
this.whitelistButton = new Buttons.SmallerButton( x, y, Component.literal("WH"), true, $ -> buttonClicked(idOffset)); //TODO these need translation keys
|
||||
buttonConsumer.accept(this.whitelistButton);
|
||||
y += 14;
|
||||
this.modButton = new Buttons.SmallerButton( x, y, Component.literal("MO"), true, $ -> gui.buttonClicked(2));
|
||||
gui.renderables.add(this.modButton);
|
||||
this.modButton = new Buttons.SmallerButton( x, y, Component.literal("MO"), true, $ -> buttonClicked(idOffset + 1));
|
||||
buttonConsumer.accept(this.modButton);
|
||||
|
||||
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() {
|
||||
this.whitelistButton.setMessage(Component.literal("WH").withStyle(this.theSettings.isWhitelist
|
||||
? ChatFormatting.DARK_GREEN
|
||||
|
|
|
@ -52,10 +52,10 @@ public class SackGui extends AAScreen<SackContainer> {
|
|||
public void 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(
|
||||
Component.literal(this.container.autoInsert? "I" : "O")
|
||||
Component.literal("I")
|
||||
.withStyle(this.container.autoInsert? ChatFormatting.DARK_GREEN : ChatFormatting.RED),
|
||||
(button) -> {
|
||||
this.container.autoInsert = !this.container.autoInsert;
|
||||
|
@ -72,7 +72,7 @@ public class SackGui extends AAScreen<SackContainer> {
|
|||
CompoundTag data = new CompoundTag();
|
||||
data.putInt("ButtonID", id);
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,13 @@ public class FilterSettings {
|
|||
public boolean isWhitelist;
|
||||
public boolean respectMod;
|
||||
private boolean lastWhitelist;
|
||||
private boolean lastRespectNBT;
|
||||
private boolean lastRespectMod;
|
||||
|
||||
public enum Buttons {
|
||||
WHITELIST,
|
||||
MOD
|
||||
}
|
||||
|
||||
public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMod) {
|
||||
this.filterInventory = new ItemStackHandlerAA(slots) {
|
||||
@Override
|
||||
|
@ -101,9 +105,9 @@ public class FilterSettings {
|
|||
}
|
||||
|
||||
public void onButtonPressed(int id) {
|
||||
if (id == 1) {
|
||||
if (id == Buttons.WHITELIST.ordinal()) {
|
||||
this.isWhitelist = !this.isWhitelist;
|
||||
} else if (id == 2) {
|
||||
} else if (id == Buttons.MOD.ordinal()) {
|
||||
this.respectMod = !this.respectMod;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue