mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-23 03:49:22 +01:00
misc wip sack fixes.
This commit is contained in:
parent
971fdd652f
commit
85725a0f85
9 changed files with 73 additions and 95 deletions
|
@ -75,7 +75,7 @@ public class CommonEvents {
|
|||
ItemStackHandlerAA inv = new ItemStackHandlerAA(28); //TODO whats going on here
|
||||
DrillItem.loadSlotsFromNBT(inv, invStack);
|
||||
|
||||
FilterSettings filter = new FilterSettings(4, false, false, false);
|
||||
FilterSettings filter = new FilterSettings(4, false, false);
|
||||
filter.readFromNBT(invStack.getOrCreateTag(), "Filter");
|
||||
if (filter.check(stack)) {
|
||||
if (isVoid) {
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.util.UUID;
|
|||
|
||||
public class SackContainer extends AbstractContainerMenu implements IButtonReactor {
|
||||
|
||||
public final FilterSettings filter = new FilterSettings(4, false, false, false);
|
||||
public final FilterSettings filter = new FilterSettings(4, false,false);
|
||||
private final ItemStackHandlerAA bagInventory;
|
||||
private final Inventory inventory;
|
||||
public boolean autoInsert;
|
||||
|
@ -141,10 +141,8 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
|||
if (id == 0) {
|
||||
this.filter.isWhitelist = data == 1;
|
||||
} else if (id == 1) {
|
||||
this.filter.respectNBT = data == 1;
|
||||
} else if (id == 2) {
|
||||
this.autoInsert = data == 1;
|
||||
} else if (id == 3) {
|
||||
} else if (id == 2) {
|
||||
this.filter.respectMod = data == 1;
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +195,7 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
|||
}
|
||||
|
||||
@Override
|
||||
public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) {
|
||||
public void clicked(int slotId, int dragType, @Nonnull ClickType clickTypeIn, @Nonnull Player player) {
|
||||
if (SlotFilter.checkFilter(this, slotId, player)) {
|
||||
return; //TODO: Check if this is correct, used to return ItemStack.EMPTY
|
||||
} else if (clickTypeIn == ClickType.SWAP && dragType == this.inventory.selected) {
|
||||
|
@ -208,10 +206,9 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removed(Player player) {
|
||||
public void removed(@Nonnull Player player) {
|
||||
ItemStack stack = this.inventory.getSelected();
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof Sack) {
|
||||
//DrillItem.writeSlotsToNBT(this.bagInventory, this.inventory.getSelected());
|
||||
CompoundTag compound = stack.getOrCreateTag();
|
||||
this.filter.writeToNBT(compound, "Filter");
|
||||
compound.putBoolean("AutoInsert", this.autoInsert);
|
||||
|
@ -220,7 +217,7 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
public boolean stillValid(@Nonnull Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -229,7 +226,7 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
|||
if (buttonID == 0) {
|
||||
this.autoInsert = !this.autoInsert;
|
||||
} else {
|
||||
//this.filter.onButtonPressed(buttonID); //TODO
|
||||
this.filter.onButtonPressed(buttonID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,20 +30,16 @@ public class FilterSettingsGui {
|
|||
private final FilterSettings theSettings;
|
||||
|
||||
public Buttons.SmallerButton whitelistButton;
|
||||
public Buttons.SmallerButton nbtButton;
|
||||
public Buttons.SmallerButton modButton;
|
||||
|
||||
public FilterSettingsGui(FilterSettings settings, int x, int y, List<Renderable> buttonList) {
|
||||
public FilterSettingsGui(FilterSettings settings, int x, int y, SackGui gui) {
|
||||
this.theSettings = settings;
|
||||
|
||||
this.whitelistButton = new Buttons.SmallerButton( x, y, Component.literal("WH"), true, Button::onPress); //TODO these need translation keys
|
||||
buttonList.add(this.whitelistButton);
|
||||
this.whitelistButton = new Buttons.SmallerButton( x, y, Component.literal("WH"), true, $ -> gui.buttonClicked(1)); //TODO these need translation keys
|
||||
gui.renderables.add(this.whitelistButton);
|
||||
y += 14;
|
||||
this.nbtButton = new Buttons.SmallerButton( x, y, Component.literal("NB"), true, Button::onPress);//TODO also button actions
|
||||
buttonList.add(this.nbtButton);
|
||||
y += 14;
|
||||
this.modButton = new Buttons.SmallerButton( x, y, Component.literal("MO"), true, Button::onPress);
|
||||
buttonList.add(this.modButton);
|
||||
this.modButton = new Buttons.SmallerButton( x, y, Component.literal("MO"), true, $ -> gui.buttonClicked(2));
|
||||
gui.renderables.add(this.modButton);
|
||||
|
||||
this.tick();
|
||||
}
|
||||
|
@ -52,10 +48,7 @@ public class FilterSettingsGui {
|
|||
this.whitelistButton.setMessage(Component.literal("WH").withStyle(this.theSettings.isWhitelist
|
||||
? ChatFormatting.DARK_GREEN
|
||||
: ChatFormatting.RED));
|
||||
this.whitelistButton.setMessage(Component.literal("NB").withStyle(this.theSettings.respectNBT
|
||||
? ChatFormatting.DARK_GREEN
|
||||
: ChatFormatting.RED));
|
||||
this.whitelistButton.setMessage(Component.literal("MO").withStyle(this.theSettings.respectMod
|
||||
this.modButton.setMessage(Component.literal("MO").withStyle(this.theSettings.respectMod
|
||||
? ChatFormatting.DARK_GREEN
|
||||
: ChatFormatting.RED));
|
||||
}
|
||||
|
@ -68,10 +61,6 @@ public class FilterSettingsGui {
|
|||
? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.whitelist")
|
||||
: Component.translatable("info." + ActuallyAdditions.MODID + ".gui.blacklist")).withStyle(ChatFormatting.BOLD));
|
||||
list.add(Component.translatable("info." + ActuallyAdditions.MODID + ".gui.whitelistInfo"));
|
||||
} else if (this.nbtButton.isMouseOver(mouseX, mouseY)) {
|
||||
list.add((this.theSettings.respectNBT
|
||||
? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.respectNBT")
|
||||
: Component.translatable("info." + ActuallyAdditions.MODID + ".gui.ignoreNBT")).withStyle(ChatFormatting.BOLD));
|
||||
} else if (this.modButton.isMouseOver(mouseX, mouseY)) {
|
||||
list.add((this.theSettings.respectMod
|
||||
? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.respectMod")
|
||||
|
|
|
@ -12,14 +12,24 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
|||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.SackContainer;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.Tooltip;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SackGui extends AAScreen<SackContainer> {
|
||||
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_bag");
|
||||
|
@ -42,31 +52,34 @@ 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.renderables);
|
||||
//
|
||||
// this.buttonAutoInsert = new Button(0, this.leftPos - 21, this.topPos + 8, 20, 20, (this.container.autoInsert
|
||||
// ? TextFormatting.DARK_GREEN
|
||||
// : TextFormatting.RED) + "I");
|
||||
//this.addButton(this.buttonAutoInsert);
|
||||
this.filter = new FilterSettingsGui(this.container.filter, this.leftPos + 138, this.topPos + 10, this);
|
||||
|
||||
this.buttonAutoInsert = Button.builder(
|
||||
Component.literal(this.container.autoInsert? "I" : "O")
|
||||
.withStyle(this.container.autoInsert? ChatFormatting.DARK_GREEN : ChatFormatting.RED),
|
||||
(button) -> {
|
||||
this.container.autoInsert = !this.container.autoInsert;
|
||||
this.buttonAutoInsert.setMessage(Component.literal(this.container.autoInsert? "I" : "O")
|
||||
.withStyle(this.container.autoInsert? ChatFormatting.DARK_GREEN : ChatFormatting.RED));
|
||||
this.buttonClicked(0);
|
||||
}).pos(leftPos - 21, topPos + 8).size(20, 20)
|
||||
.build();
|
||||
|
||||
this.addRenderableWidget(this.buttonAutoInsert);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void actionPerformed(Button button) throws IOException {
|
||||
// CompoundNBT data = new CompoundNBT();
|
||||
// data.putInt("ButtonID", button.id);
|
||||
// data.putInt("PlayerID", Minecraft.getInstance().player.getId());
|
||||
// data.putInt("WorldID", Minecraft.getInstance().level.provider.getDimension());
|
||||
// PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER));
|
||||
// }
|
||||
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().getPath());
|
||||
PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void containerTick() {
|
||||
super.containerTick();
|
||||
this.filter.tick();
|
||||
|
||||
//this.buttonAutoInsert.displayString = (this.container.autoInsert
|
||||
// ? TextFormatting.DARK_GREEN
|
||||
// : TextFormatting.RED) + "I";
|
||||
}
|
||||
|
||||
/* @Override
|
||||
|
@ -81,15 +94,15 @@ public class SackGui extends AAScreen<SackContainer> {
|
|||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
this.filter.drawHover(guiGraphics, mouseX, mouseY);
|
||||
|
||||
/* if (this.buttonAutoInsert.isMouseOver()) {
|
||||
List<String> text = new ArrayList<>();
|
||||
text.add(TextFormatting.BOLD + "Auto-Insert " + (this.container.autoInsert
|
||||
if (this.buttonAutoInsert.isMouseOver(mouseX, mouseY)) {
|
||||
List<Component> text = new ArrayList<>();
|
||||
text.add(Component.literal("Auto-Insert " + (this.container.autoInsert
|
||||
? "On"
|
||||
: "Off"));
|
||||
text.addAll(this.font.listFormattedStringToWidth("Turn this on to make items that get picked up automatically go into the bag.", 200));
|
||||
text.addAll(this.font.listFormattedStringToWidth(TextFormatting.GRAY + "" + TextFormatting.ITALIC + "Note that this WON'T work when you are holding the bag in your hand.", 200));
|
||||
this.renderToolTip(stack, text, mouseX, mouseY, this.getMinecraft().font);
|
||||
}*/
|
||||
: "Off")).withStyle(ChatFormatting.BOLD));
|
||||
text.add(Component.literal("Turn this on to make items that get picked up automatically go into the bag.")); //TODO how to word wrap these to 200?
|
||||
text.add(Component.literal("Note that this WON'T work when you are holding the bag in your hand.").withStyle(ChatFormatting.GRAY).withStyle(ChatFormatting.ITALIC)); //TODO this too
|
||||
guiGraphics.renderTooltip(font, text, Optional.empty(), mouseX, mouseY); //TODO i have no idea what im doing here...
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,7 +33,7 @@ public class SlotFilter extends SlotItemHandlerUnconditioned {
|
|||
if (slotId >= 0 && slotId < container.slots.size()) {
|
||||
Slot slot = container.getSlot(slotId);
|
||||
if (slot instanceof SlotFilter) {
|
||||
((SlotFilter) slot).slotClick(player);
|
||||
((SlotFilter) slot).slotClick(player, container.getCarried());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ public class SlotFilter extends SlotItemHandlerUnconditioned {
|
|||
return !stack.isEmpty() && stack.getItem() instanceof ItemFilter;
|
||||
}
|
||||
|
||||
private void slotClick(Player player) {
|
||||
ItemStack heldStack = player.getInventory().getSelected();
|
||||
private void slotClick(Player player, ItemStack cursorItem) {
|
||||
ItemStack heldStack = cursorItem;
|
||||
ItemStack stackInSlot = this.getItem();
|
||||
|
||||
if (StackUtil.isValid(stackInSlot) && !StackUtil.isValid(heldStack)) {
|
||||
|
|
|
@ -106,10 +106,10 @@ public final class PacketHandler {
|
|||
Player player = context.player().get();
|
||||
Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(compound.getString("WorldID"))));
|
||||
Entity entity = level.getEntity(compound.getInt("PlayerID"));
|
||||
if (entity instanceof Player) {
|
||||
AbstractContainerMenu container = ((Player) entity).containerMenu;
|
||||
if (container instanceof IButtonReactor) {
|
||||
((IButtonReactor) container).onButtonPressed(compound.getInt("ButtonID"), (Player) entity);
|
||||
if (entity instanceof Player p) {
|
||||
AbstractContainerMenu container = p.containerMenu;
|
||||
if (container instanceof IButtonReactor reactor) {
|
||||
reactor.onButtonPressed(compound.getInt("ButtonID"), (Player) entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,19 +22,12 @@ import net.minecraft.world.item.ItemStack;
|
|||
public class FilterSettings {
|
||||
public final ItemStackHandlerAA filterInventory;
|
||||
public boolean isWhitelist;
|
||||
public boolean respectNBT;
|
||||
public boolean respectMod;
|
||||
private boolean lastWhitelist;
|
||||
private boolean lastRespectNBT;
|
||||
private boolean lastRespectMod;
|
||||
|
||||
public enum Buttons {
|
||||
WHITELIST,
|
||||
NBT,
|
||||
MOD
|
||||
}
|
||||
|
||||
public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectNBT, boolean defaultRespectMod) {
|
||||
public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMod) {
|
||||
this.filterInventory = new ItemStackHandlerAA(slots) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
|
@ -44,13 +37,12 @@ public class FilterSettings {
|
|||
};
|
||||
|
||||
this.isWhitelist = defaultWhitelist;
|
||||
this.respectNBT = defaultRespectNBT;
|
||||
this.respectMod = defaultRespectMod;
|
||||
}
|
||||
|
||||
public void onContentsChanged() {}
|
||||
|
||||
public static boolean check(ItemStack stack, ItemStackHandlerAA filter, boolean whitelist, boolean nbt, boolean mod) {
|
||||
public static boolean check(ItemStack stack, ItemStackHandlerAA filter, boolean whitelist, boolean mod) {
|
||||
if (!stack.isEmpty()) {
|
||||
for (int i = 0; i < filter.getSlots(); i++) {
|
||||
ItemStack slot = filter.getStackInSlot(i);
|
||||
|
@ -61,11 +53,11 @@ public class FilterSettings {
|
|||
DrillItem.loadSlotsFromNBT(inv, slot);
|
||||
for (int k = 0; k < inv.getSlots(); k++) {
|
||||
ItemStack filterSlot = inv.getStackInSlot(k);
|
||||
if (!filterSlot.isEmpty() && areEqualEnough(filterSlot, stack, nbt, mod)) {
|
||||
if (!filterSlot.isEmpty() && areEqualEnough(filterSlot, stack, mod)) {
|
||||
return whitelist;
|
||||
}
|
||||
}
|
||||
} else if (areEqualEnough(slot, stack, nbt, mod)) {
|
||||
} else if (areEqualEnough(slot, stack, mod)) {
|
||||
return whitelist;
|
||||
}
|
||||
}
|
||||
|
@ -74,24 +66,19 @@ public class FilterSettings {
|
|||
return !whitelist;
|
||||
}
|
||||
|
||||
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean nbt, boolean mod) {
|
||||
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean mod) {
|
||||
Item firstItem = first.getItem();
|
||||
Item secondItem = second.getItem();
|
||||
if (mod && BuiltInRegistries.ITEM.getKey(firstItem).getNamespace().equals(BuiltInRegistries.ITEM.getKey(secondItem).getNamespace())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (firstItem != secondItem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !nbt || ItemStack.isSameItemSameTags(first, second);
|
||||
return firstItem == secondItem;
|
||||
}
|
||||
|
||||
public void writeToNBT(CompoundTag tag, String name) {
|
||||
CompoundTag compound = new CompoundTag();
|
||||
compound.putBoolean("Whitelist", this.isWhitelist);
|
||||
compound.putBoolean("NBT", this.respectNBT);
|
||||
compound.putBoolean("Mod", this.respectMod);
|
||||
compound.put("Items", filterInventory.serializeNBT());
|
||||
tag.put(name, compound);
|
||||
|
@ -100,37 +87,29 @@ public class FilterSettings {
|
|||
public void readFromNBT(CompoundTag tag, String name) {
|
||||
CompoundTag compound = tag.getCompound(name);
|
||||
this.isWhitelist = compound.getBoolean("Whitelist");
|
||||
this.respectNBT = compound.getBoolean("NBT");
|
||||
this.respectMod = compound.getBoolean("Mod");
|
||||
this.filterInventory.deserializeNBT(compound.getCompound("Items"));
|
||||
}
|
||||
|
||||
public boolean needsUpdateSend() {
|
||||
return this.lastWhitelist != this.isWhitelist || this.lastRespectNBT != this.respectNBT || this.lastRespectMod != this.respectMod;
|
||||
return this.lastWhitelist != this.isWhitelist || this.lastRespectMod != this.respectMod;
|
||||
}
|
||||
|
||||
public void updateLasts() {
|
||||
this.lastWhitelist = this.isWhitelist;
|
||||
this.lastRespectNBT = this.respectNBT;
|
||||
this.lastRespectMod = this.respectMod;
|
||||
}
|
||||
|
||||
public void onButtonPressed(int id) {
|
||||
if (id == Buttons.WHITELIST.ordinal()) {
|
||||
if (id == 1) {
|
||||
this.isWhitelist = !this.isWhitelist;
|
||||
} else if (id == Buttons.NBT.ordinal()) {
|
||||
this.respectNBT = !this.respectNBT;
|
||||
} else if (id == Buttons.MOD.ordinal()) {
|
||||
} else if (id == 2) {
|
||||
this.respectMod = !this.respectMod;
|
||||
|
||||
if (this.respectMod) {
|
||||
this.respectNBT = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean check(ItemStack stack) {
|
||||
return !this.needsCheck() || check(stack, this.filterInventory, this.isWhitelist, this.respectNBT, this.respectMod);
|
||||
return !this.needsCheck() || check(stack, this.filterInventory, this.isWhitelist, this.respectMod);
|
||||
}
|
||||
|
||||
public boolean needsCheck() {
|
||||
|
|
|
@ -35,8 +35,8 @@ import java.util.Optional;
|
|||
|
||||
public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem implements IButtonReactor, MenuProvider {
|
||||
|
||||
public FilterSettings leftFilter = new FilterSettings(12, true, false, false);
|
||||
public FilterSettings rightFilter = new FilterSettings(12, true, false, false);
|
||||
public FilterSettings leftFilter = new FilterSettings(12, true, false);
|
||||
public FilterSettings rightFilter = new FilterSettings(12, true, false);
|
||||
|
||||
public TileEntityLaserRelayItemAdvanced(BlockPos pos, BlockState state) {
|
||||
super(ActuallyBlocks.LASER_RELAY_ITEM_ADVANCED.getTileEntityType(), pos, state);
|
||||
|
@ -118,7 +118,7 @@ public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem i
|
|||
ItemStack copy = stack.copy();
|
||||
copy.setCount(1);
|
||||
|
||||
if (!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectNBT, usedSettings.respectMod)) {
|
||||
if (!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectMod)) {
|
||||
for (int k = 0; k < usedSettings.filterInventory.getSlots(); k++) {
|
||||
ItemStack slot = usedSettings.filterInventory.getStackInSlot(k);
|
||||
if (!slot.isEmpty()) {
|
||||
|
|
|
@ -38,7 +38,7 @@ import java.util.List;
|
|||
public class TileEntityRangedCollector extends TileEntityInventoryBase implements IButtonReactor, MenuProvider {
|
||||
|
||||
public static final int RANGE = 6;
|
||||
public FilterSettings filter = new FilterSettings(12, true, false, false);
|
||||
public FilterSettings filter = new FilterSettings(12, true, false);
|
||||
|
||||
public TileEntityRangedCollector(BlockPos pos, BlockState state) {
|
||||
super(ActuallyBlocks.RANGED_COLLECTOR.getTileEntityType(), pos, state, 6);
|
||||
|
|
Loading…
Reference in a new issue