Added Armory Cabinet
This commit is contained in:
parent
d7e59cc82b
commit
3be6c491ac
|
@ -1,5 +1,6 @@
|
||||||
package com.buuz135.functionalstorage;
|
package com.buuz135.functionalstorage;
|
||||||
|
|
||||||
|
import com.buuz135.functionalstorage.block.ArmoryCabinetBlock;
|
||||||
import com.buuz135.functionalstorage.block.CompactingDrawerBlock;
|
import com.buuz135.functionalstorage.block.CompactingDrawerBlock;
|
||||||
import com.buuz135.functionalstorage.block.DrawerBlock;
|
import com.buuz135.functionalstorage.block.DrawerBlock;
|
||||||
import com.buuz135.functionalstorage.block.DrawerControllerBlock;
|
import com.buuz135.functionalstorage.block.DrawerControllerBlock;
|
||||||
|
@ -59,6 +60,7 @@ public class FunctionalStorage extends ModuleController {
|
||||||
public static HashMap<DrawerType, List<RegistryObject<Block>>> DRAWER_TYPES = new HashMap<>();
|
public static HashMap<DrawerType, List<RegistryObject<Block>>> DRAWER_TYPES = new HashMap<>();
|
||||||
public static RegistryObject<Block> COMPACTING_DRAWER;
|
public static RegistryObject<Block> COMPACTING_DRAWER;
|
||||||
public static RegistryObject<Block> DRAWER_CONTROLLER;
|
public static RegistryObject<Block> DRAWER_CONTROLLER;
|
||||||
|
public static RegistryObject<Block> ARMORY_CABINET;
|
||||||
|
|
||||||
public static RegistryObject<Item> LINKING_TOOL;
|
public static RegistryObject<Item> LINKING_TOOL;
|
||||||
public static HashMap<StorageUpgradeItem.StorageTier, RegistryObject<Item>> STORAGE_UPGRADES = new HashMap<>();
|
public static HashMap<StorageUpgradeItem.StorageTier, RegistryObject<Item>> STORAGE_UPGRADES = new HashMap<>();
|
||||||
|
@ -94,6 +96,7 @@ public class FunctionalStorage extends ModuleController {
|
||||||
PULLING_UPGRADE = getRegistries().register(Item.class, "puller_upgrade", () -> new UpgradeItem(new Item.Properties(), UpgradeItem.Type.UTILITY));
|
PULLING_UPGRADE = getRegistries().register(Item.class, "puller_upgrade", () -> new UpgradeItem(new Item.Properties(), UpgradeItem.Type.UTILITY));
|
||||||
PUSHING_UPGRADE = getRegistries().register(Item.class, "pusher_upgrade", () -> new UpgradeItem(new Item.Properties(), UpgradeItem.Type.UTILITY));
|
PUSHING_UPGRADE = getRegistries().register(Item.class, "pusher_upgrade", () -> new UpgradeItem(new Item.Properties(), UpgradeItem.Type.UTILITY));
|
||||||
VOID_UPGRADE = getRegistries().register(Item.class, "void_upgrade", () -> new UpgradeItem(new Item.Properties(), UpgradeItem.Type.UTILITY));
|
VOID_UPGRADE = getRegistries().register(Item.class, "void_upgrade", () -> new UpgradeItem(new Item.Properties(), UpgradeItem.Type.UTILITY));
|
||||||
|
ARMORY_CABINET = getRegistries().register(Block.class, "armory_cabinet", ArmoryCabinetBlock::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum DrawerType{
|
public enum DrawerType{
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.buuz135.functionalstorage.block;
|
||||||
|
|
||||||
|
import com.buuz135.functionalstorage.block.tile.ArmoryCabinetTile;
|
||||||
|
import com.hrznstudio.titanium.block.RotatableBlock;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ArmoryCabinetBlock extends RotatableBlock<ArmoryCabinetTile> {
|
||||||
|
|
||||||
|
public ArmoryCabinetBlock() {
|
||||||
|
super("armory_cabinet", Properties.copy(Blocks.IRON_BLOCK), ArmoryCabinetTile.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockEntityType.BlockEntitySupplier<?> getTileEntityFactory() {
|
||||||
|
return (p_155268_, p_155269_) -> new ArmoryCabinetTile(this, p_155268_, p_155269_);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public RotationType getRotationType() {
|
||||||
|
return RotationType.FOUR_WAY;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.buuz135.functionalstorage.block.tile;
|
||||||
|
|
||||||
|
import com.buuz135.functionalstorage.inventory.ArmoryCabinetInventoryHandler;
|
||||||
|
import com.buuz135.functionalstorage.inventory.CompactingInventoryHandler;
|
||||||
|
import com.hrznstudio.titanium.annotation.Save;
|
||||||
|
import com.hrznstudio.titanium.block.BasicTileBlock;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class ArmoryCabinetTile extends ControllableDrawerTile<ArmoryCabinetTile>{
|
||||||
|
|
||||||
|
@Save
|
||||||
|
public ArmoryCabinetInventoryHandler handler;
|
||||||
|
private final LazyOptional<IItemHandler> lazyStorage;
|
||||||
|
|
||||||
|
public ArmoryCabinetTile(BasicTileBlock<ArmoryCabinetTile> base, BlockPos pos, BlockState state) {
|
||||||
|
super(base, pos, state);
|
||||||
|
this.handler = new ArmoryCabinetInventoryHandler() {
|
||||||
|
@Override
|
||||||
|
public void onChange() {
|
||||||
|
ArmoryCabinetTile.this.markForUpdate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.lazyStorage = LazyOptional.of(() -> handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public <U> LazyOptional<U> getCapability(@Nonnull Capability<U> cap, @Nullable Direction side) {
|
||||||
|
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||||
|
return lazyStorage.cast();
|
||||||
|
}
|
||||||
|
return super.getCapability(cap, side);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IItemHandler getStorage() {
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LazyOptional<IItemHandler> getOptional() {
|
||||||
|
return lazyStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ArmoryCabinetTile getSelf() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
package com.buuz135.functionalstorage.inventory;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraftforge.common.util.INBTSerializable;
|
||||||
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class ArmoryCabinetInventoryHandler implements IItemHandler, INBTSerializable<CompoundTag> {
|
||||||
|
|
||||||
|
public static final int SLOTS = 8192;
|
||||||
|
//TODO NERF AND POSSIBLY CONFIG
|
||||||
|
|
||||||
|
public List<ItemStack> stackList;
|
||||||
|
|
||||||
|
public ArmoryCabinetInventoryHandler() {
|
||||||
|
this.stackList = create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSlots() {
|
||||||
|
return SLOTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ItemStack getStackInSlot(int slot) {
|
||||||
|
if (slot < this.stackList.size()){
|
||||||
|
return this.stackList.get(slot);
|
||||||
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
|
||||||
|
if (isItemValid(slot, stack)) {
|
||||||
|
if (!simulate){
|
||||||
|
this.stackList.set(slot, stack);
|
||||||
|
onChange();
|
||||||
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void onChange();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||||
|
if (!simulate){
|
||||||
|
ItemStack stack = this.stackList.set(slot, ItemStack.EMPTY);
|
||||||
|
onChange();
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
return this.stackList.get(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSlotLimit(int slot) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
|
||||||
|
return !stack.isEmpty() && this.stackList.get(slot).isEmpty() && isCertifiedStack(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCertifiedStack(ItemStack stack){
|
||||||
|
if (stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).isPresent()) return false;
|
||||||
|
return stack.hasTag() || stack.isDamageableItem() || stack.isEnchantable() || stack.getMaxStackSize() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag serializeNBT() {
|
||||||
|
CompoundTag compoundTag = new CompoundTag();
|
||||||
|
for (int i = 0; i < this.stackList.size(); i++) {
|
||||||
|
ItemStack stack = this.stackList.get(i);
|
||||||
|
if (!stack.isEmpty()){
|
||||||
|
compoundTag.put(i + "", stack.serializeNBT());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return compoundTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ItemStack> create(){
|
||||||
|
List<ItemStack> stackList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < SLOTS; i++) {
|
||||||
|
stackList.add(ItemStack.EMPTY);
|
||||||
|
}
|
||||||
|
return stackList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deserializeNBT(CompoundTag nbt) {
|
||||||
|
this.stackList = create();
|
||||||
|
for (String allKey : nbt.getAllKeys()) {
|
||||||
|
this.stackList.set(Integer.parseInt(allKey), ItemStack.of(nbt.getCompound(allKey)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user