mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Sack things, moved filter to WSD.
This commit is contained in:
parent
856e07a521
commit
adce5984e4
5 changed files with 43 additions and 34 deletions
|
@ -31,7 +31,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, false);
|
private final FilterSettings filter;
|
||||||
private final ItemStackHandlerAA bagInventory;
|
private final ItemStackHandlerAA bagInventory;
|
||||||
private final Inventory inventory;
|
private final Inventory inventory;
|
||||||
public boolean autoInsert;
|
public boolean autoInsert;
|
||||||
|
@ -40,20 +40,22 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
||||||
public static final int SIZE = 28;
|
public static final int SIZE = 28;
|
||||||
|
|
||||||
public static SackContainer fromNetwork(int windowId, Inventory inv, FriendlyByteBuf data) {
|
public static SackContainer fromNetwork(int windowId, Inventory inv, FriendlyByteBuf data) {
|
||||||
return new SackContainer(windowId, inv, data.readUUID(), new ItemStackHandlerAA(28));
|
return new SackContainer(windowId, inv, new ItemStackHandlerAA(28), new FilterSettings(4, false, false, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public SackContainer(int windowId, Inventory playerInventory, UUID uuid, ItemStackHandlerAA handler) {
|
public SackContainer(int windowId, Inventory playerInventory, ItemStackHandlerAA handler, FilterSettings filterIn) {
|
||||||
super(ActuallyContainers.SACK_CONTAINER.get(), windowId);
|
super(ActuallyContainers.SACK_CONTAINER.get(), windowId);
|
||||||
|
|
||||||
this.inventory = playerInventory;
|
this.inventory = playerInventory;
|
||||||
this.bagInventory = handler;
|
this.bagInventory = handler;
|
||||||
|
this.filter = filterIn;
|
||||||
|
|
||||||
|
// Filter slots.
|
||||||
for (int row = 0; row < 4; row++) {
|
for (int row = 0; row < 4; row++) {
|
||||||
this.addSlot(new SlotFilter(this.filter, row, 155, 10 + row * 18));
|
this.addSlot(new SlotFilter(this.filter, row, 155, 10 + row * 18));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sack inventory
|
// Sack inventory.
|
||||||
for (int row = 0; row < 4; row++) {
|
for (int row = 0; row < 4; row++) {
|
||||||
for (int col = 0; col < 7; col++) {
|
for (int col = 0; col < 7; col++) {
|
||||||
this.addSlot(new SlotItemHandlerUnconditioned(this.bagInventory, col + row * 7, 10 + col * 18, 10 + row * 18) {
|
this.addSlot(new SlotItemHandlerUnconditioned(this.bagInventory, col + row * 7, 10 + col * 18, 10 + row * 18) {
|
||||||
|
@ -65,14 +67,14 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player Inventory
|
// Player Inventory.
|
||||||
for (int row = 0; row < 3; row++) {
|
for (int row = 0; row < 3; row++) {
|
||||||
for (int col = 0; col < 9; col++) {
|
for (int col = 0; col < 9; col++) {
|
||||||
this.addSlot(new Slot(playerInventory, col + row * 9 + 9, 8 + col * 18, 94 + row * 18));
|
this.addSlot(new Slot(playerInventory, col + row * 9 + 9, 8 + col * 18, 94 + row * 18));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player Hotbar
|
// Player Hotbar.
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
if (i == playerInventory.selected) {
|
if (i == playerInventory.selected) {
|
||||||
this.addSlot(new SlotImmovable(playerInventory, i, 8 + i * 18, 152));
|
this.addSlot(new SlotImmovable(playerInventory, i, 8 + i * 18, 152));
|
||||||
|
@ -80,17 +82,9 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact
|
||||||
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 152));
|
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 152));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = playerInventory.getSelected();
|
|
||||||
if (!stack.isEmpty() && stack.getItem() instanceof Sack) {
|
|
||||||
// if (stack.hasTag()) { TODO: IMPORTANT! RE_ENABLE FILTER READ
|
|
||||||
// CompoundTag compound = stack.getOrCreateTag();
|
|
||||||
// this.filter.readFromNBT(playerInventory.player.registryAccess(), compound, "Filter");
|
|
||||||
// this.autoInsert = compound.getBoolean("AutoInsert");
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ItemStack quickMoveStack(@Nonnull Player player, int slot) {
|
public ItemStack quickMoveStack(@Nonnull Player player, int slot) {
|
||||||
int inventoryStart = this.bagInventory.getSlots() + 4;
|
int inventoryStart = this.bagInventory.getSlots() + 4;
|
||||||
|
|
|
@ -44,6 +44,7 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Tier;
|
import net.minecraft.world.item.Tier;
|
||||||
import net.minecraft.world.item.Tiers;
|
import net.minecraft.world.item.Tiers;
|
||||||
|
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.item.enchantment.Enchantments;
|
import net.minecraft.world.item.enchantment.Enchantments;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
@ -190,14 +191,10 @@ public class DrillItem extends ItemEnergy {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(@Nonnull EquipmentSlot slot, @Nonnull ItemStack stack) {
|
public ItemAttributeModifiers getDefaultAttributeModifiers(@Nonnull ItemStack stack) {
|
||||||
if (slot == EquipmentSlot.MAINHAND) {
|
|
||||||
return this.getEnergyStored(stack) >= ENERGY_USE
|
return this.getEnergyStored(stack) >= ENERGY_USE
|
||||||
? this.attributes_powered
|
? this.attributes_powered
|
||||||
: this.attributes_unpowered;
|
: this.attributes_unpowered;
|
||||||
}
|
|
||||||
else
|
|
||||||
return super.getDefaultAttributeModifiers(slot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class Sack extends ItemBase {
|
||||||
|
|
||||||
|
|
||||||
player.openMenu(new SimpleMenuProvider((id, inv, entity) ->
|
player.openMenu(new SimpleMenuProvider((id, inv, entity) ->
|
||||||
new SackContainer(id, inv, uuid, data.getSpecialHandler()), sackStack.getHoverName()), (buffer -> buffer.writeUUID(uuid)));
|
new SackContainer(id, inv, data.getSpecialHandler(), data.getFilter()), sackStack.getHoverName()), (buffer -> buffer.writeUUID(uuid)));
|
||||||
} else
|
} else
|
||||||
player.openMenu(new SimpleMenuProvider((id, inv, entity) -> new VoidSackContainer(id, inv), sackStack.getHoverName()));
|
player.openMenu(new SimpleMenuProvider((id, inv, entity) -> new VoidSackContainer(id, inv), sackStack.getHoverName()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.sack;
|
package de.ellpeck.actuallyadditions.mod.sack;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
@ -31,6 +32,18 @@ public class SackData {
|
||||||
return inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final FilterSettings filter = new FilterSettings(4, false, false, false, false){
|
||||||
|
@Override
|
||||||
|
public void onContentsChanged() {
|
||||||
|
super.onContentsChanged();
|
||||||
|
SackManager.get().setDirty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public FilterSettings getFilter() {
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateAccessRecords(String player, long time) {
|
public void updateAccessRecords(String player, long time) {
|
||||||
if (meta.firstAccessedTime == 0) {
|
if (meta.firstAccessedTime == 0) {
|
||||||
meta.firstAccessedTime = time;
|
meta.firstAccessedTime = time;
|
||||||
|
@ -71,6 +84,9 @@ public class SackData {
|
||||||
|
|
||||||
optional = Optional.ofNullable(inventory);
|
optional = Optional.ofNullable(inventory);
|
||||||
|
|
||||||
|
if (incoming.contains("Filter"))
|
||||||
|
filter.readFromNBT(provider, incoming, "Filter");
|
||||||
|
|
||||||
if (incoming.contains("Metadata"))
|
if (incoming.contains("Metadata"))
|
||||||
meta.deserializeNBT(provider, incoming.getCompound("Metadata"));
|
meta.deserializeNBT(provider, incoming.getCompound("Metadata"));
|
||||||
}
|
}
|
||||||
|
@ -94,6 +110,8 @@ public class SackData {
|
||||||
|
|
||||||
nbt.put("Inventory", inventory.serializeNBT(provider));
|
nbt.put("Inventory", inventory.serializeNBT(provider));
|
||||||
|
|
||||||
|
filter.writeToNBT(provider, nbt, "Filter");
|
||||||
|
|
||||||
nbt.put("Metadata", meta.serializeNBT(provider));
|
nbt.put("Metadata", meta.serializeNBT(provider));
|
||||||
|
|
||||||
return nbt;
|
return nbt;
|
||||||
|
|
|
@ -113,22 +113,22 @@ public class FilterSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(HolderLookup.Provider provider, CompoundTag tag, String name) {
|
public void writeToNBT(HolderLookup.Provider provider, CompoundTag tag, String name) {
|
||||||
// CompoundTag compound = new CompoundTag(); TODO: IMPORTANT! FIX THE FILTER SETTINGS!!!
|
CompoundTag compound = new CompoundTag();
|
||||||
// compound.putBoolean("Whitelist", this.isWhitelist);
|
compound.putBoolean("Whitelist", this.isWhitelist);
|
||||||
// compound.putBoolean("Mod", this.respectMod);
|
compound.putBoolean("Mod", this.respectMod);
|
||||||
// compound.putBoolean("Damage", this.matchDamage);
|
compound.putBoolean("Damage", this.matchDamage);
|
||||||
// compound.putBoolean("NBT", this.matchNBT);
|
compound.putBoolean("NBT", this.matchNBT);
|
||||||
// compound.put("Items", filterInventory.serializeNBT());
|
compound.put("Items", filterInventory.serializeNBT(provider));
|
||||||
// tag.put(name, compound);
|
tag.put(name, compound);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromNBT(HolderLookup.Provider provider, CompoundTag tag, String name) {
|
public void readFromNBT(HolderLookup.Provider provider, 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.respectMod = compound.getBoolean("Mod");
|
this.respectMod = compound.getBoolean("Mod");
|
||||||
// this.matchDamage = compound.getBoolean("Damage");
|
this.matchDamage = compound.getBoolean("Damage");
|
||||||
// this.matchNBT = compound.getBoolean("NBT");
|
this.matchNBT = compound.getBoolean("NBT");
|
||||||
// this.filterInventory.deserializeNBT(compound.getCompound("Items"));
|
this.filterInventory.deserializeNBT(provider, compound.getCompound("Items"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needsUpdateSend() {
|
public boolean needsUpdateSend() {
|
||||||
|
|
Loading…
Reference in a new issue