mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
First pass at the sack, still wip.
This commit is contained in:
parent
0e1217b5d3
commit
a75848e195
11 changed files with 376 additions and 229 deletions
|
@ -15,7 +15,6 @@ import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
|
|||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
||||
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag;
|
||||
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
||||
import de.ellpeck.actuallyadditions.mod.items.DrillItem;
|
||||
import de.ellpeck.actuallyadditions.mod.items.ItemBag;
|
||||
|
@ -72,10 +71,10 @@ public class CommonEvents {
|
|||
boolean changed = false;
|
||||
|
||||
boolean isVoid = ((ItemBag) invStack.getItem()).isVoid;
|
||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerBag.getSlotAmount(isVoid));
|
||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(28); //TODO whats going on here
|
||||
DrillItem.loadSlotsFromNBT(inv, invStack);
|
||||
|
||||
FilterSettings filter = new FilterSettings(4, false, false, false, false, 0, 0);
|
||||
FilterSettings filter = new FilterSettings(4, false, false, false);
|
||||
filter.readFromNBT(invStack.getOrCreateTag(), "Filter");
|
||||
if (filter.check(stack)) {
|
||||
if (isVoid) {
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.inventory;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotDeletion;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable;
|
||||
|
@ -21,7 +19,6 @@ import de.ellpeck.actuallyadditions.mod.items.ItemBag;
|
|||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
|
@ -31,77 +28,74 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ContainerBag extends Container implements IButtonReactor {
|
||||
|
||||
public final FilterSettings filter = new FilterSettings(4, false, true, false, false, 0, -1000);
|
||||
public final FilterSettings filter = new FilterSettings(4, false, false, false);
|
||||
private final ItemStackHandlerAA bagInventory;
|
||||
private final PlayerInventory inventory;
|
||||
public final boolean isVoid;
|
||||
public boolean autoInsert;
|
||||
private boolean oldAutoInsert;
|
||||
private final ItemStack sack;
|
||||
|
||||
public static final int SIZE = 28;
|
||||
|
||||
public static ContainerBag fromNetwork(int windowId, PlayerInventory inv, PacketBuffer data) {
|
||||
return new ContainerBag(windowId, inv, data.readItem(), data.readBoolean());
|
||||
return new ContainerBag(windowId, inv, data.readUUID(), new ItemStackHandlerAA(28));
|
||||
}
|
||||
|
||||
public ContainerBag(int windowId, PlayerInventory inventory, ItemStack sack, boolean isVoid) {
|
||||
public ContainerBag(int windowId, PlayerInventory playerInventory, UUID uuid, ItemStackHandlerAA handler) {
|
||||
super(ActuallyContainers.BAG_CONTAINER.get(), windowId);
|
||||
|
||||
this.inventory = inventory;
|
||||
this.bagInventory = new ItemStackHandlerAA(getSlotAmount(isVoid), (slot, stack, automation) -> !isBlacklisted(stack), ItemStackHandlerAA.REMOVE_TRUE);
|
||||
this.isVoid = isVoid;
|
||||
this.sack = sack;
|
||||
this.inventory = playerInventory;
|
||||
this.bagInventory = handler; //new ItemStackHandlerAA(SIZE, (slot, stack, automation) -> !isBlacklisted(stack), ItemStackHandlerAA.REMOVE_TRUE);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
this.addSlot(new SlotFilter(this.filter, i, 155, 10 + i * 18));
|
||||
}
|
||||
|
||||
if (this.isVoid) {
|
||||
if (false) { // isvoid, move to its own container
|
||||
this.addSlot(new SlotDeletion(this.bagInventory, 0, 64, 65) {
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack stack) {
|
||||
return ContainerBag.this.filter.check(stack);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 7; j++) {
|
||||
this.addSlot(new SlotItemHandlerUnconditioned(this.bagInventory, j + i * 7, 10 + j * 18, 10 + i * 18) {
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack stack) {
|
||||
return !isBlacklisted(stack) && ContainerBag.this.filter.check(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 7; j++) {
|
||||
this.addSlot(new SlotItemHandlerUnconditioned(this.bagInventory, j + i * 7, 10 + j * 18, 10 + i * 18) {
|
||||
@Override
|
||||
public boolean mayPlace(ItemStack stack) {
|
||||
return !isBlacklisted(stack) && ContainerBag.this.filter.check(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 9; j++) {
|
||||
this.addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 94 + i * 18));
|
||||
this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 94 + i * 18));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (i == inventory.selected) {
|
||||
this.addSlot(new SlotImmovable(inventory, i, 8 + i * 18, 152));
|
||||
if (i == playerInventory.selected) {
|
||||
this.addSlot(new SlotImmovable(playerInventory, i, 8 + i * 18, 152));
|
||||
} else {
|
||||
this.addSlot(new Slot(inventory, i, 8 + i * 18, 152));
|
||||
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 152));
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = inventory.getSelected();
|
||||
if (StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag) {
|
||||
DrillItem.loadSlotsFromNBT(this.bagInventory, inventory.getSelected());
|
||||
ItemStack stack = playerInventory.getSelected();
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ItemBag) {
|
||||
DrillItem.loadSlotsFromNBT(this.bagInventory, playerInventory.getSelected());
|
||||
if (stack.hasTag()) {
|
||||
CompoundNBT compound = stack.getOrCreateTag();
|
||||
this.filter.readFromNBT(compound, "Filter");
|
||||
|
@ -110,12 +104,6 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
}
|
||||
}
|
||||
|
||||
public static int getSlotAmount(boolean isVoid) {
|
||||
return isVoid
|
||||
? 1
|
||||
: 28;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastChanges() {
|
||||
super.broadcastChanges();
|
||||
|
@ -152,14 +140,10 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
if (id == 0) {
|
||||
this.filter.isWhitelist = data == 1;
|
||||
} else if (id == 1) {
|
||||
this.filter.respectMeta = data == 1;
|
||||
} else if (id == 2) {
|
||||
this.filter.respectNBT = data == 1;
|
||||
} else if (id == 3) {
|
||||
this.filter.respectOredict = data;
|
||||
} else if (id == 4) {
|
||||
} else if (id == 2) {
|
||||
this.autoInsert = data == 1;
|
||||
} else if (id == 5) {
|
||||
} else if (id == 3) {
|
||||
this.filter.respectMod = data == 1;
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +164,7 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
//Other Slots in Inventory excluded
|
||||
if (slot >= inventoryStart) {
|
||||
//Shift from Inventory
|
||||
if (this.isVoid || !this.filter.check(newStack) || !this.moveItemStackTo(newStack, 4, 32, false)) {
|
||||
if (!this.filter.check(newStack) || !this.moveItemStackTo(newStack, 4, 32, false)) {
|
||||
if (slot >= inventoryStart && slot <= inventoryEnd) {
|
||||
if (!this.moveItemStackTo(newStack, hotbarStart, hotbarEnd + 1, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
|
@ -195,7 +179,7 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (!StackUtil.isValid(newStack)) {
|
||||
if (newStack.isEmpty()) {
|
||||
theSlot.set(ItemStack.EMPTY);
|
||||
} else {
|
||||
theSlot.setChanged();
|
||||
|
@ -225,7 +209,7 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
@Override
|
||||
public void removed(PlayerEntity player) {
|
||||
ItemStack stack = this.inventory.getSelected();
|
||||
if (StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag) {
|
||||
if (!stack.isEmpty() && stack.getItem() instanceof ItemBag) {
|
||||
DrillItem.writeSlotsToNBT(this.bagInventory, this.inventory.getSelected());
|
||||
CompoundNBT compound = stack.getOrCreateTag();
|
||||
this.filter.writeToNBT(compound, "Filter");
|
||||
|
@ -236,7 +220,7 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
|
||||
@Override
|
||||
public boolean stillValid(PlayerEntity player) {
|
||||
return !this.sack.isEmpty() && player.getMainHandItem() == this.sack;
|
||||
return true; //!this.sack.isEmpty() && player.getMainHandItem() == this.sack; //TODO fix later
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -244,7 +228,7 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
if (buttonID == 0) {
|
||||
this.autoInsert = !this.autoInsert;
|
||||
} else {
|
||||
this.filter.onButtonPressed(buttonID);
|
||||
//this.filter.onButtonPressed(buttonID); //TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +238,9 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
|
||||
// TODO: [port] FIX THIS
|
||||
public static boolean isBlacklisted(ItemStack stack) {
|
||||
if (!runOnce) {
|
||||
//TODO replace with modern tagging blocking etc
|
||||
return false;
|
||||
/* if (!runOnce) {
|
||||
runOnce = true;
|
||||
for (String s : ConfigStringListValues.SACK_BLACKLIST.getValue()) {
|
||||
String[] split = s.split("@");
|
||||
|
@ -270,6 +256,6 @@ public class ContainerBag extends Container implements IButtonReactor {
|
|||
}
|
||||
}
|
||||
}
|
||||
return BLACKLIST.contains(Pair.of(stack.getItem(), 0));
|
||||
return BLACKLIST.contains(Pair.of(stack.getItem(), 0));*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,17 +10,20 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -31,27 +34,19 @@ public class FilterSettingsGui extends AbstractGui {
|
|||
private final FilterSettings theSettings;
|
||||
|
||||
public Buttons.SmallerButton whitelistButton;
|
||||
public Buttons.SmallerButton metaButton;
|
||||
public Buttons.SmallerButton nbtButton;
|
||||
public Buttons.SmallerButton modButton;
|
||||
public Buttons.SmallerButton oredictButton;
|
||||
|
||||
public FilterSettingsGui(FilterSettings settings, int x, int y, List<Button> buttonList) {
|
||||
public FilterSettingsGui(FilterSettings settings, int x, int y, List<Widget> buttonList) {
|
||||
this.theSettings = settings;
|
||||
|
||||
this.whitelistButton = new Buttons.SmallerButton( x, y, new TranslationTextComponent(""), true, Button::onPress); //TODO these need translation keys
|
||||
this.whitelistButton = new Buttons.SmallerButton( x, y, new StringTextComponent("WH"), true, Button::onPress); //TODO these need translation keys
|
||||
buttonList.add(this.whitelistButton);
|
||||
y += 14;
|
||||
this.metaButton = new Buttons.SmallerButton( x, y, new TranslationTextComponent(""), true, Button::onPress); //TODO also button actions
|
||||
buttonList.add(this.metaButton);
|
||||
y += 14;
|
||||
this.nbtButton = new Buttons.SmallerButton( x, y, new TranslationTextComponent(""), true, Button::onPress);
|
||||
this.nbtButton = new Buttons.SmallerButton( x, y, new StringTextComponent("NB"), true, Button::onPress);//TODO also button actions
|
||||
buttonList.add(this.nbtButton);
|
||||
y += 14;
|
||||
this.oredictButton = new Buttons.SmallerButton( x, y, new TranslationTextComponent(""), true, Button::onPress);
|
||||
buttonList.add(this.oredictButton);
|
||||
y += 15;
|
||||
this.modButton = new Buttons.SmallerButton( x, y, new TranslationTextComponent(""), true, Button::onPress);
|
||||
this.modButton = new Buttons.SmallerButton( x, y, new StringTextComponent("MO"), true, Button::onPress);
|
||||
buttonList.add(this.modButton);
|
||||
|
||||
this.tick();
|
||||
|
@ -61,68 +56,36 @@ public class FilterSettingsGui extends AbstractGui {
|
|||
this.whitelistButton.setMessage(new StringTextComponent("WH").withStyle(this.theSettings.isWhitelist
|
||||
? TextFormatting.DARK_GREEN
|
||||
: TextFormatting.RED));
|
||||
this.whitelistButton.setMessage(new StringTextComponent("ME").withStyle(this.theSettings.respectMeta
|
||||
? TextFormatting.DARK_GREEN
|
||||
: TextFormatting.RED));
|
||||
this.whitelistButton.setMessage(new StringTextComponent("NB").withStyle(this.theSettings.respectNBT
|
||||
? TextFormatting.DARK_GREEN
|
||||
: TextFormatting.RED));
|
||||
this.whitelistButton.setMessage(new StringTextComponent("MO").withStyle(this.theSettings.respectMod
|
||||
? TextFormatting.DARK_GREEN
|
||||
: TextFormatting.RED));
|
||||
this.whitelistButton.setMessage(new StringTextComponent("OR").withStyle(this.theSettings.respectOredict == 0
|
||||
? TextFormatting.DARK_GREEN
|
||||
: this.theSettings.respectOredict == 1
|
||||
? TextFormatting.GREEN
|
||||
: TextFormatting.DARK_GREEN));
|
||||
}
|
||||
|
||||
public void drawHover(int mouseX, int mouseY) {
|
||||
public void drawHover(MatrixStack stack, int mouseX, int mouseY) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
|
||||
List<ITextComponent> list = new ArrayList<>();
|
||||
if (this.whitelistButton.isMouseOver(mouseX, mouseY)) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(TextFormatting.BOLD + (this.theSettings.isWhitelist
|
||||
? StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.whitelist")
|
||||
: StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.blacklist")));
|
||||
//list.addAll(mc.font.substrByWidth(StringUtil.localizeFormatted("info." + ActuallyAdditions.MODID + ".gui.whitelistInfo"), 200));
|
||||
//GuiUtils.drawHoveringText(list, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.font);
|
||||
} else if (this.metaButton.isMouseOver(mouseX, mouseY)) {
|
||||
//GuiUtils.drawHoveringText(Collections.singletonList(TextFormatting.BOLD + (this.theSettings.respectMeta
|
||||
// ? StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.respectMeta")
|
||||
// : StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.ignoreMeta"))), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.font);
|
||||
list.add((this.theSettings.isWhitelist
|
||||
? new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.whitelist")
|
||||
: new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.blacklist")).withStyle(TextFormatting.BOLD));
|
||||
list.add(new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.whitelistInfo"));
|
||||
} else if (this.nbtButton.isMouseOver(mouseX, mouseY)) {
|
||||
//GuiUtils.drawHoveringText(Collections.singletonList(TextFormatting.BOLD + (this.theSettings.respectNBT
|
||||
// ? StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.respectNBT")
|
||||
// : StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.ignoreNBT"))), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.font);
|
||||
list.add((this.theSettings.respectNBT
|
||||
? new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.respectNBT")
|
||||
: new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.ignoreNBT")).withStyle(TextFormatting.BOLD));
|
||||
} else if (this.modButton.isMouseOver(mouseX, mouseY)) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(TextFormatting.BOLD + (this.theSettings.respectMod
|
||||
? StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.respectMod")
|
||||
: StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.ignoreMod")));
|
||||
list.add((this.theSettings.respectMod
|
||||
? new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.respectMod")
|
||||
: new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.ignoreMod")).withStyle(TextFormatting.BOLD));
|
||||
list.add(new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".gui.respectModInfo"));
|
||||
|
||||
//list.addAll(mc.font.listFormattedStringToWidth(StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.respectModInfo"), 200));
|
||||
|
||||
//GuiUtils.drawHoveringText(list, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.font);
|
||||
} else if (this.oredictButton.isMouseOver(mouseX, mouseY)) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(TextFormatting.BOLD + (this.theSettings.respectOredict == 0
|
||||
? StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.ignoreOredict")
|
||||
: this.theSettings.respectOredict == 1
|
||||
? StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.respectOredictSoft")
|
||||
: StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.respectOredictHard")));
|
||||
|
||||
String type = null;
|
||||
if (this.theSettings.respectOredict == 1) {
|
||||
type = "one";
|
||||
} else if (this.theSettings.respectOredict == 2) {
|
||||
type = "all";
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
//list.addAll(mc.font.listFormattedStringToWidth(StringUtil.localize("info." + ActuallyAdditions.MODID + ".gui.respectOredictInfo." + type), 200));
|
||||
}
|
||||
//GuiUtils.drawHoveringText(list, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.font);
|
||||
}
|
||||
//TODO tooltips still jank
|
||||
if (!list.isEmpty())
|
||||
GuiUtils.drawHoveringText(stack, list, mouseX, mouseY, mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight(), 200, mc.font);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class GuiBag extends AAScreen<ContainerBag> {
|
|||
super(container, inventory, title);
|
||||
this.imageWidth = 176;
|
||||
this.imageHeight = 90 + 86;
|
||||
this.isVoid = container.isVoid;
|
||||
this.isVoid = false; //TODO fix later
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,12 @@ public class GuiBag extends AAScreen<ContainerBag> {
|
|||
public void init() {
|
||||
super.init();
|
||||
|
||||
// this.filter = new FilterSettingsGui(this.container.filter, this.leftPos + 138, this.topPos + 10, this.buttons);
|
||||
this.filter = new FilterSettingsGui(this.container.filter, this.leftPos + 138, this.topPos + 10, this.buttons);
|
||||
//
|
||||
// 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.addButton(this.buttonAutoInsert);
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
@ -79,7 +79,7 @@ public class GuiBag extends AAScreen<ContainerBag> {
|
|||
@Override
|
||||
public void render(@Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks) {
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
this.filter.drawHover(mouseX, mouseY);
|
||||
this.filter.drawHover(stack, mouseX, mouseY);
|
||||
|
||||
/* if (this.buttonAutoInsert.isMouseOver()) {
|
||||
List<String> text = new ArrayList<>();
|
||||
|
|
|
@ -82,8 +82,8 @@ public class GuiLaserRelayItemWhitelist extends AAScreen<ContainerLaserRelayItem
|
|||
// this.drawHoveringText(list, x, y);
|
||||
// }
|
||||
|
||||
this.leftFilter.drawHover(x, y);
|
||||
this.rightFilter.drawHover(x, y);
|
||||
this.leftFilter.drawHover(matrices, x, y);
|
||||
this.rightFilter.drawHover(matrices, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,8 @@ package de.ellpeck.actuallyadditions.mod.items;
|
|||
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag;
|
||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
||||
import de.ellpeck.actuallyadditions.mod.sack.SackData;
|
||||
import de.ellpeck.actuallyadditions.mod.sack.SackManager;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -24,12 +26,11 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemBag extends ItemBase {
|
||||
public final boolean isVoid;
|
||||
|
@ -46,7 +47,7 @@ public class ItemBag extends ItemBase {
|
|||
TileEntity tile = context.getLevel().getBlockEntity(context.getClickedPos());
|
||||
if (tile != null) {
|
||||
if (!context.getLevel().isClientSide) {
|
||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerBag.getSlotAmount(this.isVoid));
|
||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(28);
|
||||
|
||||
boolean changed = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, context.getClickedFace())
|
||||
.map(cap -> {
|
||||
|
@ -85,24 +86,41 @@ public class ItemBag extends ItemBase {
|
|||
|
||||
@Override
|
||||
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||
if (!world.isClientSide && hand == Hand.MAIN_HAND) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, new SimpleNamedContainerProvider((windowId, playerInventory, playerEntity) -> new ContainerBag(windowId, playerInventory, playerEntity.getItemInHand(hand), this.isVoid), StringTextComponent.EMPTY));
|
||||
// player.openGui(ActuallyAdditions.INSTANCE, (this.isVoid
|
||||
// ? GuiTypes.VOID_BAG
|
||||
// : GuiTypes.BAG).ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
ItemStack sackStack = player.getItemInHand(hand);
|
||||
if (!world.isClientSide && hand == Hand.MAIN_HAND && sackStack.getItem() instanceof ItemBag && player instanceof ServerPlayerEntity) {
|
||||
|
||||
if (!isVoid) {
|
||||
SackData data = getData(sackStack);
|
||||
if (data == null)
|
||||
return ActionResult.fail(sackStack);
|
||||
|
||||
UUID uuid = data.getUuid();
|
||||
|
||||
data.updateAccessRecords(player.getName().getString(), System.currentTimeMillis());
|
||||
|
||||
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, new SimpleNamedContainerProvider((id, inv, entity) ->
|
||||
new ContainerBag(id, inv, uuid, data.getSpecialHandler()), sackStack.getHoverName()), (buffer -> buffer.writeUUID(uuid)));
|
||||
}
|
||||
|
||||
|
||||
/* NetworkHooks.openGui((ServerPlayerEntity) player,
|
||||
new SimpleNamedContainerProvider((windowId, playerInventory, playerEntity) ->
|
||||
new ContainerBag(windowId, playerInventory, playerEntity.getItemInHand(hand), this.isVoid), StringTextComponent.EMPTY));*/
|
||||
}
|
||||
return ActionResult.pass(player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
// TODO: [port] confirm this is correct
|
||||
@Nullable
|
||||
@Override
|
||||
public CompoundNBT getShareTag(ItemStack stack) {
|
||||
return new CompoundNBT();
|
||||
public static SackData getData(ItemStack stack) {
|
||||
if (!(stack.getItem() instanceof ItemBag))
|
||||
return null;
|
||||
UUID uuid;
|
||||
CompoundNBT tag = stack.getOrCreateTag();
|
||||
if (!tag.contains("UUID")) {
|
||||
uuid = UUID.randomUUID();
|
||||
tag.putUUID("UUID", uuid);
|
||||
} else
|
||||
uuid = tag.getUUID("UUID");
|
||||
return SackManager.get().getOrCreateSack(uuid);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public CompoundNBT getNBTShareTag(ItemStack stack) {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
package de.ellpeck.actuallyadditions.mod.sack;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
//Mainly copied my backpacks into here for the sacks --Flanks255
|
||||
public class SackData {
|
||||
public static final int SIZE = 28;
|
||||
private final UUID uuid;
|
||||
|
||||
private final ItemStackHandlerAA inventory;
|
||||
private final LazyOptional<IItemHandler> optional;
|
||||
|
||||
public final Metadata meta = new Metadata();
|
||||
|
||||
public LazyOptional<IItemHandler> getOptional() {
|
||||
return optional;
|
||||
}
|
||||
|
||||
public IItemHandler getHandler() {
|
||||
return inventory;
|
||||
}
|
||||
public ItemStackHandlerAA getSpecialHandler() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void updateAccessRecords(String player, long time) {
|
||||
if (meta.firstAccessedTime == 0) {
|
||||
meta.firstAccessedTime = time;
|
||||
meta.firstAccessedPlayer = player;
|
||||
}
|
||||
|
||||
meta.setLastAccessedTime(time);
|
||||
meta.setLastAccessedPlayer(player);
|
||||
}
|
||||
|
||||
public SackData(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
|
||||
inventory = new ItemStackHandlerAA(SIZE) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
SackManager.get().setDirty();
|
||||
}
|
||||
};
|
||||
optional = LazyOptional.of(() -> inventory);
|
||||
}
|
||||
|
||||
public SackData(UUID uuid, CompoundNBT incoming) {
|
||||
this.uuid = uuid;
|
||||
|
||||
inventory = new ItemStackHandlerAA(SIZE){
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
SackManager.get().setDirty();
|
||||
}
|
||||
};
|
||||
|
||||
inventory.deserializeNBT(incoming.getCompound("Inventory"));
|
||||
|
||||
optional = LazyOptional.of(() -> inventory);
|
||||
|
||||
if (incoming.contains("Metadata"))
|
||||
meta.deserializeNBT(incoming.getCompound("Metadata"));
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static Optional<SackData> fromNBT(CompoundNBT nbt) {
|
||||
if (nbt.contains("UUID")) {
|
||||
UUID uuid = nbt.getUUID("UUID");
|
||||
return Optional.of(new SackData(uuid, nbt));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public CompoundNBT toNBT() {
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
|
||||
nbt.putUUID("UUID", uuid);
|
||||
|
||||
nbt.put("Inventory", inventory.serializeNBT());
|
||||
|
||||
nbt.put("Metadata", meta.serializeNBT());
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public static class Metadata implements INBTSerializable<CompoundNBT> {
|
||||
private String firstAccessedPlayer = "";
|
||||
|
||||
private long firstAccessedTime = 0;
|
||||
private String lastAccessedPlayer = "";
|
||||
private long lastAccessedTime = 0;
|
||||
public long getLastAccessedTime() {
|
||||
return lastAccessedTime;
|
||||
}
|
||||
|
||||
public void setLastAccessedTime(long lastAccessedTime) {
|
||||
this.lastAccessedTime = lastAccessedTime;
|
||||
}
|
||||
|
||||
public String getLastAccessedPlayer() {
|
||||
return lastAccessedPlayer;
|
||||
}
|
||||
|
||||
public void setLastAccessedPlayer(String lastAccessedPlayer) {
|
||||
this.lastAccessedPlayer = lastAccessedPlayer;
|
||||
}
|
||||
|
||||
public long getFirstAccessedTime() {
|
||||
return firstAccessedTime;
|
||||
}
|
||||
|
||||
public String getFirstAccessedPlayer() {
|
||||
return firstAccessedPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT serializeNBT() {
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
|
||||
nbt.putString("firstPlayer", firstAccessedPlayer);
|
||||
nbt.putLong("firstTime", firstAccessedTime);
|
||||
nbt.putString("lastPlayer", lastAccessedPlayer);
|
||||
nbt.putLong("lastTime", lastAccessedTime);
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundNBT nbt) {
|
||||
firstAccessedPlayer = nbt.getString("firstPlayer");
|
||||
firstAccessedTime = nbt.getLong("firstTime");
|
||||
lastAccessedPlayer = nbt.getString("lastPlayer");
|
||||
lastAccessedTime = nbt.getLong("lastTime");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package de.ellpeck.actuallyadditions.mod.sack;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.WorldSavedData;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fml.common.thread.SidedThreadGroups;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SackManager extends WorldSavedData {
|
||||
private static final String NAME = ActuallyAdditions.MODID + "_sack_data";
|
||||
|
||||
private static final SackManager blankClient = new SackManager();
|
||||
|
||||
private static final HashMap<UUID, SackData> data = new HashMap<>();
|
||||
|
||||
public SackManager() {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
public static SackManager get() {
|
||||
if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.SERVER)
|
||||
return ServerLifecycleHooks.getCurrentServer().getLevel(World.OVERWORLD).getDataStorage().computeIfAbsent(SackManager::new, NAME);
|
||||
else
|
||||
return blankClient;
|
||||
}
|
||||
|
||||
public Optional<SackData> getSack(UUID uuid) {
|
||||
if (data.containsKey(uuid))
|
||||
return Optional.of(data.get(uuid));
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public SackData getOrCreateSack(UUID uuid) {
|
||||
return data.computeIfAbsent(uuid, id -> {
|
||||
setDirty();
|
||||
return new SackData(id);
|
||||
});
|
||||
}
|
||||
public void removeSack(UUID uuid) {
|
||||
getSack(uuid).ifPresent(backpack -> {
|
||||
backpack.getOptional().invalidate();
|
||||
data.remove(uuid);
|
||||
setDirty();
|
||||
});
|
||||
}
|
||||
|
||||
public LazyOptional<IItemHandler> getCapability(UUID uuid) {
|
||||
if (data.containsKey(uuid))
|
||||
return data.get(uuid).getOptional();
|
||||
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
public LazyOptional<IItemHandler> getCapability(ItemStack stack) {
|
||||
if (stack.getOrCreateTag().contains("UUID")) {
|
||||
UUID uuid = stack.getTag().getUUID("UUID");
|
||||
if (data.containsKey(uuid))
|
||||
return data.get(uuid).getOptional();
|
||||
}
|
||||
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundNBT nbt) {
|
||||
if (nbt.contains("Sacks")) {
|
||||
ListNBT list = nbt.getList("Sacks", Constants.NBT.TAG_COMPOUND);
|
||||
list.forEach((sackNBT) -> SackData.fromNBT((CompoundNBT) sackNBT).ifPresent((sack) -> data.put(sack.getUuid(), sack)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public CompoundNBT save(CompoundNBT compound) {
|
||||
ListNBT sacks = new ListNBT();
|
||||
data.forEach(((uuid, sackData) -> sacks.add(sackData.toNBT())));
|
||||
compound.put("Sacks", sacks);
|
||||
return compound;
|
||||
}
|
||||
}
|
|
@ -14,62 +14,49 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
|
|||
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
|
||||
import de.ellpeck.actuallyadditions.mod.items.DrillItem;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
|
||||
public class FilterSettings {
|
||||
|
||||
public final int whitelistButtonId;
|
||||
public final int metaButtonId;
|
||||
public final int nbtButtonId;
|
||||
public final int oredictButtonId;
|
||||
public final int modButtonId;
|
||||
public final ItemStackHandlerAA filterInventory;
|
||||
public boolean isWhitelist;
|
||||
public boolean respectMeta;
|
||||
public boolean respectNBT;
|
||||
public boolean respectMod;
|
||||
public int respectOredict;
|
||||
private boolean lastWhitelist;
|
||||
private boolean lastRespectMeta;
|
||||
private boolean lastRespectNBT;
|
||||
private boolean lastRespectMod;
|
||||
private int lastRecpectOredict;
|
||||
|
||||
public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, boolean defaultRespectMod, int defaultRespectOredict, int buttonIdStart) {
|
||||
public enum Buttons {
|
||||
WHITELIST,
|
||||
NBT,
|
||||
MOD
|
||||
}
|
||||
|
||||
public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectNBT, boolean defaultRespectMod) {
|
||||
this.filterInventory = new ItemStackHandlerAA(slots);
|
||||
|
||||
this.isWhitelist = defaultWhitelist;
|
||||
this.respectMeta = defaultRespectMeta;
|
||||
this.respectNBT = defaultRespectNBT;
|
||||
this.respectMod = defaultRespectMod;
|
||||
this.respectOredict = defaultRespectOredict;
|
||||
|
||||
this.whitelistButtonId = buttonIdStart;
|
||||
this.metaButtonId = buttonIdStart + 1;
|
||||
this.nbtButtonId = buttonIdStart + 2;
|
||||
this.oredictButtonId = buttonIdStart + 3;
|
||||
this.modButtonId = buttonIdStart + 4;
|
||||
}
|
||||
|
||||
public static boolean check(ItemStack stack, ItemStackHandlerAA filter, boolean whitelist, boolean meta, boolean nbt, boolean mod, int oredict) {
|
||||
if (StackUtil.isValid(stack)) {
|
||||
public static boolean check(ItemStack stack, ItemStackHandlerAA filter, boolean whitelist, boolean nbt, boolean mod) {
|
||||
if (!stack.isEmpty()) {
|
||||
for (int i = 0; i < filter.getSlots(); i++) {
|
||||
ItemStack slot = filter.getStackInSlot(i);
|
||||
|
||||
if (StackUtil.isValid(slot)) {
|
||||
if (!slot.isEmpty()) {
|
||||
if (SlotFilter.isFilter(slot)) {
|
||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerFilter.SLOT_AMOUNT);
|
||||
DrillItem.loadSlotsFromNBT(inv, slot);
|
||||
for (int k = 0; k < inv.getSlots(); k++) {
|
||||
ItemStack filterSlot = inv.getStackInSlot(k);
|
||||
if (StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)) {
|
||||
if (!filterSlot.isEmpty() && areEqualEnough(filterSlot, stack, nbt, mod)) {
|
||||
return whitelist;
|
||||
}
|
||||
}
|
||||
} else if (areEqualEnough(slot, stack, meta, nbt, mod, oredict)) {
|
||||
} else if (areEqualEnough(slot, stack, nbt, mod)) {
|
||||
return whitelist;
|
||||
}
|
||||
}
|
||||
|
@ -78,44 +65,13 @@ public class FilterSettings {
|
|||
return !whitelist;
|
||||
}
|
||||
|
||||
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt, boolean mod, int oredict) {
|
||||
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean nbt, boolean mod) {
|
||||
Item firstItem = first.getItem();
|
||||
Item secondItem = second.getItem();
|
||||
if (mod && firstItem.getRegistryName().getNamespace().equals(secondItem.getRegistryName().getNamespace())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if (oredict != 0) {
|
||||
// boolean firstEmpty = ArrayUtils.isEmpty(firstIds);
|
||||
// boolean secondEmpty = ArrayUtils.isEmpty(secondIds);
|
||||
//
|
||||
// //Both empty, meaning none has OreDict entries, so they are equal
|
||||
// if (firstEmpty && secondEmpty) {
|
||||
// return true;
|
||||
// }
|
||||
// //Only one empty, meaning they are not equal
|
||||
// else if (firstEmpty || secondEmpty) {
|
||||
// return false;
|
||||
// } else {
|
||||
// for (int id : firstIds) {
|
||||
// if (ArrayUtils.contains(secondIds, id)) {
|
||||
// //Needs to match only one id, so return true on first match
|
||||
// if (oredict == 1) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// //Needs to match every id, so just return false when no match
|
||||
// else if (oredict == 2) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// //If oredict mode 1, this will fail because nothing matched
|
||||
// //If oredict mode 2, this will mean nothing hasn't matched
|
||||
// return oredict == 2;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (firstItem != secondItem) {
|
||||
return false;
|
||||
}
|
||||
|
@ -130,10 +86,8 @@ public class FilterSettings {
|
|||
public void writeToNBT(CompoundNBT tag, String name) {
|
||||
CompoundNBT compound = new CompoundNBT();
|
||||
compound.putBoolean("Whitelist", this.isWhitelist);
|
||||
compound.putBoolean("Meta", this.respectMeta);
|
||||
compound.putBoolean("NBT", this.respectNBT);
|
||||
compound.putBoolean("Mod", this.respectMod);
|
||||
compound.putInt("Oredict", this.respectOredict);
|
||||
TileEntityInventoryBase.saveSlots(this.filterInventory, compound);
|
||||
tag.put(name, compound);
|
||||
}
|
||||
|
@ -141,56 +95,42 @@ public class FilterSettings {
|
|||
public void readFromNBT(CompoundNBT tag, String name) {
|
||||
CompoundNBT compound = tag.getCompound(name);
|
||||
this.isWhitelist = compound.getBoolean("Whitelist");
|
||||
this.respectMeta = compound.getBoolean("Meta");
|
||||
this.respectNBT = compound.getBoolean("NBT");
|
||||
this.respectMod = compound.getBoolean("Mod");
|
||||
this.respectOredict = compound.getInt("Oredict");
|
||||
TileEntityInventoryBase.loadSlots(this.filterInventory, compound);
|
||||
}
|
||||
|
||||
public boolean needsUpdateSend() {
|
||||
return this.lastWhitelist != this.isWhitelist || this.lastRespectMeta != this.respectMeta || this.lastRespectNBT != this.respectNBT || this.lastRespectMod != this.respectMod || this.lastRecpectOredict != this.respectOredict;
|
||||
return this.lastWhitelist != this.isWhitelist || this.lastRespectNBT != this.respectNBT || this.lastRespectMod != this.respectMod;
|
||||
}
|
||||
|
||||
public void updateLasts() {
|
||||
this.lastWhitelist = this.isWhitelist;
|
||||
this.lastRespectMeta = this.respectMeta;
|
||||
this.lastRespectNBT = this.respectNBT;
|
||||
this.lastRespectMod = this.respectMod;
|
||||
this.lastRecpectOredict = this.respectOredict;
|
||||
}
|
||||
|
||||
public void onButtonPressed(int id) {
|
||||
if (id == this.whitelistButtonId) {
|
||||
if (id == Buttons.WHITELIST.ordinal()) {
|
||||
this.isWhitelist = !this.isWhitelist;
|
||||
} else if (id == this.metaButtonId) {
|
||||
this.respectMeta = !this.respectMeta;
|
||||
} else if (id == this.nbtButtonId) {
|
||||
} else if (id == Buttons.NBT.ordinal()) {
|
||||
this.respectNBT = !this.respectNBT;
|
||||
} else if (id == this.modButtonId) {
|
||||
} else if (id == Buttons.MOD.ordinal()) {
|
||||
this.respectMod = !this.respectMod;
|
||||
|
||||
if (this.respectMod) {
|
||||
this.respectMeta = false;
|
||||
this.respectNBT = false;
|
||||
this.respectOredict = 0;
|
||||
}
|
||||
} else if (id == this.oredictButtonId) {
|
||||
if (this.respectOredict + 1 > 2) {
|
||||
this.respectOredict = 0;
|
||||
} else {
|
||||
this.respectOredict++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean check(ItemStack stack) {
|
||||
return !this.needsCheck() || check(stack, this.filterInventory, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectMod, this.respectOredict);
|
||||
return !this.needsCheck() || check(stack, this.filterInventory, this.isWhitelist, this.respectNBT, this.respectMod);
|
||||
}
|
||||
|
||||
public boolean needsCheck() {
|
||||
for (int i = 0; i < this.filterInventory.getSlots(); i++) {
|
||||
if (StackUtil.isValid(this.filterInventory.getStackInSlot(i))) {
|
||||
if (!this.filterInventory.getStackInSlot(i).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
|
|||
import de.ellpeck.actuallyadditions.mod.items.DrillItem;
|
||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
@ -32,8 +31,8 @@ import javax.annotation.Nullable;
|
|||
|
||||
public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem implements IButtonReactor, INamedContainerProvider {
|
||||
|
||||
public FilterSettings leftFilter = new FilterSettings(12, true, true, false, false, 0, -1000);
|
||||
public FilterSettings rightFilter = new FilterSettings(12, true, true, false, false, 0, -2000);
|
||||
public FilterSettings leftFilter = new FilterSettings(12, true, false, false);
|
||||
public FilterSettings rightFilter = new FilterSettings(12, true, false, false);
|
||||
|
||||
public TileEntityLaserRelayItemAdvanced() {
|
||||
super(ActuallyBlocks.LASER_RELAY_ITEM_ADVANCED.getTileEntityType());
|
||||
|
@ -83,7 +82,7 @@ public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem i
|
|||
handler.getNormalHandler().ifPresent(itemHandler -> {
|
||||
for (int i = 0; i < itemHandler.getSlots(); i++) {
|
||||
ItemStack stack = itemHandler.getStackInSlot(i);
|
||||
if (StackUtil.isValid(stack)) {
|
||||
if (!stack.isEmpty()) {
|
||||
this.addWhitelistSmart(output, stack);
|
||||
}
|
||||
}
|
||||
|
@ -98,17 +97,17 @@ public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem i
|
|||
ItemStack copy = stack.copy();
|
||||
copy.setCount(1);
|
||||
|
||||
if (!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)) {
|
||||
if (!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectNBT, usedSettings.respectMod)) {
|
||||
for (int k = 0; k < usedSettings.filterInventory.getSlots(); k++) {
|
||||
ItemStack slot = usedSettings.filterInventory.getStackInSlot(k);
|
||||
if (StackUtil.isValid(slot)) {
|
||||
if (!slot.isEmpty()) {
|
||||
if (SlotFilter.isFilter(slot)) {
|
||||
ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerFilter.SLOT_AMOUNT);
|
||||
DrillItem.loadSlotsFromNBT(inv, slot);
|
||||
|
||||
boolean did = false;
|
||||
for (int j = 0; j < inv.getSlots(); j++) {
|
||||
if (!StackUtil.isValid(inv.getStackInSlot(j))) {
|
||||
if (inv.getStackInSlot(j).isEmpty()) {
|
||||
inv.setStackInSlot(j, copy);
|
||||
did = true;
|
||||
break;
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.util.List;
|
|||
public class TileEntityRangedCollector extends TileEntityInventoryBase implements IButtonReactor, INamedContainerProvider {
|
||||
|
||||
public static final int RANGE = 6;
|
||||
public FilterSettings filter = new FilterSettings(12, true, true, false, false, 0, -1000);
|
||||
public FilterSettings filter = new FilterSettings(12, true, false, false);
|
||||
|
||||
public TileEntityRangedCollector() {
|
||||
super(ActuallyBlocks.RANGED_COLLECTOR.getTileEntityType(), 6);
|
||||
|
@ -65,7 +65,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
|
|||
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AxisAlignedBB(this.worldPosition.getX() - RANGE, this.worldPosition.getY() - RANGE, this.worldPosition.getZ() - RANGE, this.worldPosition.getX() + RANGE, this.worldPosition.getY() + RANGE, this.worldPosition.getZ() + RANGE));
|
||||
if (!items.isEmpty()) {
|
||||
for (ItemEntity item : items) {
|
||||
if (item.isAlive() && !item.hasPickUpDelay() && StackUtil.isValid(item.getItem())) {
|
||||
if (item.isAlive() && !item.hasPickUpDelay() && !item.getItem().isEmpty()) {
|
||||
ItemStack toAdd = item.getItem().copy();
|
||||
if (this.filter.check(toAdd)) {
|
||||
ArrayList<ItemStack> checkList = new ArrayList<>();
|
||||
|
@ -102,8 +102,8 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
|
|||
|
||||
@Override
|
||||
public void onButtonPressed(int buttonID, PlayerEntity player) {
|
||||
this.filter.onButtonPressed(buttonID);
|
||||
}
|
||||
//this.filter.onButtonPressed(buttonID);
|
||||
} //TODO
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
|
|
Loading…
Reference in a new issue