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