2024-03-14 05:09:55 +00:00
|
|
|
package pm.c7.scout.screen;
|
|
|
|
|
|
|
|
import net.minecraft.block.ShulkerBoxBlock;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.inventory.Inventory;
|
|
|
|
import net.minecraft.item.BlockItem;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.screen.slot.Slot;
|
2024-03-16 02:01:13 +00:00
|
|
|
import pm.c7.scout.config.ScoutConfig;
|
2024-03-14 05:09:55 +00:00
|
|
|
import pm.c7.scout.item.BaseBagItem;
|
|
|
|
|
|
|
|
public class BagSlot extends Slot {
|
2024-03-14 06:12:23 +00:00
|
|
|
private final int index;
|
|
|
|
public Inventory inventory;
|
|
|
|
private boolean enabled = false;
|
2024-03-14 05:09:55 +00:00
|
|
|
private int realX;
|
|
|
|
private int realY;
|
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
public BagSlot(int index, int x, int y) {
|
|
|
|
super(null, index, x, y);
|
|
|
|
this.index = index;
|
2024-03-14 05:09:55 +00:00
|
|
|
this.realX = x;
|
|
|
|
this.realY = y;
|
2024-03-14 06:12:23 +00:00
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
public void setInventory(Inventory inventory) {
|
|
|
|
this.inventory = inventory;
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
public void setEnabled(boolean state) {
|
|
|
|
enabled = state;
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
@Override
|
|
|
|
public boolean canInsert(ItemStack stack) {
|
|
|
|
if (stack.getItem() instanceof BaseBagItem)
|
|
|
|
return false;
|
2024-03-14 05:09:55 +00:00
|
|
|
|
|
|
|
if (stack.getItem() instanceof BlockItem blockItem) {
|
|
|
|
if (blockItem.getBlock() instanceof ShulkerBoxBlock)
|
2024-03-16 02:01:13 +00:00
|
|
|
return enabled && inventory != null && ScoutConfig.allowShulkers;
|
2024-03-14 05:09:55 +00:00
|
|
|
}
|
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
return enabled && inventory != null;
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
@Override
|
|
|
|
public boolean canTakeItems(PlayerEntity playerEntity) {
|
|
|
|
return enabled && inventory != null;
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return enabled && inventory != null;
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
@Override
|
|
|
|
public ItemStack getStack() {
|
|
|
|
return enabled && this.inventory != null ? this.inventory.getStack(this.index) : ItemStack.EMPTY;
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
|
|
|
@Override
|
2024-03-14 06:12:23 +00:00
|
|
|
public void setStack(ItemStack stack) {
|
2024-03-14 05:09:55 +00:00
|
|
|
if (enabled && this.inventory != null) {
|
|
|
|
this.inventory.setStack(this.index, stack);
|
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
@Override
|
|
|
|
public void markDirty() {
|
|
|
|
if (enabled && this.inventory != null) {
|
|
|
|
this.inventory.markDirty();
|
|
|
|
}
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
2024-03-14 06:12:23 +00:00
|
|
|
@Override
|
|
|
|
public ItemStack takeStack(int amount) {
|
|
|
|
return enabled && this.inventory != null ? this.inventory.removeStack(this.index, amount) : ItemStack.EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxItemCount() {
|
|
|
|
return enabled && this.inventory != null ? this.inventory.getMaxCountPerStack() : 0;
|
|
|
|
}
|
2024-03-14 05:09:55 +00:00
|
|
|
|
|
|
|
public int getX() {
|
|
|
|
return this.realX;
|
|
|
|
}
|
|
|
|
public int getY() {
|
|
|
|
return this.realY;
|
|
|
|
}
|
|
|
|
public void setX(int x) {
|
|
|
|
this.realX = x;
|
|
|
|
}
|
|
|
|
public void setY(int y) {
|
|
|
|
this.realY = y;
|
|
|
|
}
|
|
|
|
}
|