Fix 2
This commit is contained in:
parent
f06f07a534
commit
7f8d4b8eb3
@ -5,15 +5,16 @@ import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.GameRules;
|
||||
import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
|
||||
import systems.brn.server_storage.blockentities.StorageBlockEntity;
|
||||
import systems.brn.server_storage.blocks.HardDriveContainerBlock;
|
||||
import systems.brn.server_storage.blocks.StorageBlock;
|
||||
import systems.brn.server_storage.items.HardDriveItem;
|
||||
import systems.brn.server_storage.items.SimpleBlockItem;
|
||||
import systems.brn.server_storage.items.SimpleItem;
|
||||
import systems.brn.server_storage.items.TieredItem;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -32,6 +33,11 @@ public class ServerStorage implements ModInitializer {
|
||||
public static StorageBlock STORAGE_BLOCK;
|
||||
public static BlockEntityType<StorageBlockEntity> STORAGE_BLOCK_ENTITY;
|
||||
|
||||
public static Item DRIVE_CASING;
|
||||
public static List<Item> PLATTERS;
|
||||
public static List<Item> DRIVES;
|
||||
public static List<Item> HEADS;
|
||||
|
||||
public static final GameRules.Key<GameRules.BooleanRule> ServerStorage_Crafting_Enable =
|
||||
GameRuleRegistry.register("enableserverstoragecrafting", GameRules.Category.MISC, GameRuleFactory.createBooleanRule(false));
|
||||
|
||||
@ -49,10 +55,10 @@ public class ServerStorage implements ModInitializer {
|
||||
HardDriveContainerBlock.register();
|
||||
SimpleBlockItem.register(HARD_DRIVE_CONTAINER_BLOCK);
|
||||
|
||||
TieredItem.register("drive");
|
||||
TieredItem.register("head");
|
||||
TieredItem.register("platter");
|
||||
SimpleItem.register("drive_casing");
|
||||
HEADS = SimpleItem.register("head", tiers);
|
||||
PLATTERS = SimpleItem.register("platter", tiers);
|
||||
DRIVE_CASING = SimpleItem.register("drive_casing");
|
||||
DRIVES = HardDriveItem.register(tiers);
|
||||
|
||||
PolymerResourcePackUtils.addModAssets(MOD_ID);
|
||||
PolymerResourcePackUtils.markAsRequired();
|
||||
|
@ -1,13 +1,68 @@
|
||||
package systems.brn.server_storage.blockentities;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import systems.brn.server_storage.screenhandlers.DriveContainerScreenHandler;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.HARD_DRIVE_CONTAINER_BLOCK_ENTITY;
|
||||
|
||||
public class HardDriveContainerBlockEntity extends BlockEntity {
|
||||
public class HardDriveContainerBlockEntity extends LootableContainerBlockEntity {
|
||||
private DefaultedList<ItemStack> inventory;
|
||||
private static final int INVENTORY_SIZE = 9;
|
||||
|
||||
public HardDriveContainerBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(HARD_DRIVE_CONTAINER_BLOCK_ENTITY, pos, state);
|
||||
this.inventory = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Text getContainerName() {
|
||||
return Text.translatable("block.serverstorage.drive_container");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultedList<ItemStack> getHeldStacks() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setHeldStacks(DefaultedList<ItemStack> inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
return new DriveContainerScreenHandler(syncId, playerInventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return INVENTORY_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
|
||||
super.readNbt(nbt, registryLookup);
|
||||
this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY);
|
||||
if (!this.readLootTable(nbt)) {
|
||||
Inventories.readNbt(nbt, this.inventory, registryLookup);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
|
||||
super.writeNbt(nbt, registryLookup);
|
||||
if (!this.writeLootTable(nbt)) {
|
||||
Inventories.writeNbt(nbt, this.inventory, registryLookup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,33 +11,50 @@ import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.ItemScatterer;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
|
||||
import systems.brn.server_storage.screens.DriveScreen;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.*;
|
||||
|
||||
public class HardDriveContainerBlock extends SimplePolymerBlock implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
|
||||
final Identifier identifier;
|
||||
public static final DirectionProperty FACING = FacingBlock.FACING;
|
||||
private final BlockState polymerBlockState;
|
||||
|
||||
public HardDriveContainerBlock(AbstractBlock.Settings settings, Identifier identifier) {
|
||||
super(settings, Blocks.NOTE_BLOCK);
|
||||
this.identifier = identifier;
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
|
||||
this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(identifier.withPath("block/" + identifier.getPath())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(identifier));
|
||||
return this.polymerBlockState;
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
@ -62,8 +79,10 @@ public class HardDriveContainerBlock extends SimplePolymerBlock implements Polym
|
||||
if (block instanceof HardDriveContainerBlock) {
|
||||
if (!world.isClient && !player.isSpectator()) {
|
||||
if (!player.isSneaking()) {
|
||||
DriveScreen driveScreen = new DriveScreen((ServerPlayerEntity) player, pos);
|
||||
driveScreen.open();
|
||||
BlockEntity storageBlockEntity = world.getBlockEntity(pos);
|
||||
if (storageBlockEntity instanceof HardDriveContainerBlockEntity) {
|
||||
player.openHandledScreen((HardDriveContainerBlockEntity) storageBlockEntity);
|
||||
}
|
||||
|
||||
} else {
|
||||
return ActionResult.PASS;
|
||||
@ -79,4 +98,10 @@ public class HardDriveContainerBlock extends SimplePolymerBlock implements Polym
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new HardDriveContainerBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
|
||||
ItemScatterer.onStateReplaced(state, newState, world, pos);
|
||||
super.onStateReplaced(state, world, pos, newState, moved);
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,23 @@ import eu.pb4.polymer.blocks.api.BlockModelType;
|
||||
import eu.pb4.polymer.blocks.api.PolymerBlockModel;
|
||||
import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils;
|
||||
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
|
||||
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
|
||||
import eu.pb4.polymer.core.api.block.SimplePolymerBlock;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.WrittenBookContentComponent;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.text.RawFilteredPair;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@ -23,6 +28,7 @@ import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.server_storage.blockentities.StorageBlockEntity;
|
||||
@ -35,15 +41,29 @@ import static systems.brn.server_storage.lib.Util.generateBookContent;
|
||||
|
||||
public class StorageBlock extends SimplePolymerBlock implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
final Identifier identifier;
|
||||
public static final DirectionProperty FACING = FacingBlock.FACING;
|
||||
private final BlockState polymerBlockState;
|
||||
|
||||
public StorageBlock(Settings settings, Identifier identifier) {
|
||||
super(settings, Blocks.NOTE_BLOCK);
|
||||
this.identifier = identifier;
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
|
||||
this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(identifier.withPath("block/" + identifier.getPath())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(identifier));
|
||||
return this.polymerBlockState;
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
@ -51,6 +71,13 @@ public class StorageBlock extends SimplePolymerBlock implements PolymerTexturedB
|
||||
STORAGE_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new StorageBlock(AbstractBlock.Settings.copy(Blocks.WHITE_WOOL), modId));
|
||||
UseBlockCallback.EVENT.register(StorageBlock::onUse);
|
||||
|
||||
STORAGE_BLOCK_ENTITY = Registry.register(
|
||||
Registries.BLOCK_ENTITY_TYPE,
|
||||
modId,
|
||||
BlockEntityType.Builder.create(StorageBlockEntity::new, STORAGE_BLOCK).build(null)
|
||||
);
|
||||
PolymerBlockUtils.registerBlockEntity(STORAGE_BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
private static ActionResult onUse(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
|
||||
|
@ -0,0 +1,39 @@
|
||||
package systems.brn.server_storage.items;
|
||||
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import systems.brn.server_storage.lib.DriveComponents;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.id;
|
||||
|
||||
public class HardDriveItem extends SimpleItem {
|
||||
public HardDriveItem(Settings settings, Identifier identifier) {
|
||||
super(settings, identifier);
|
||||
}
|
||||
|
||||
public static List<Item> register(List<String> tiers){
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
int numberItems = 128;
|
||||
for (String tier : tiers) {
|
||||
Identifier identifier = id(tier + "_drive");
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleItem(new Settings()
|
||||
.maxCount(1)
|
||||
.component(DriveComponents.MAX_ITEMS, numberItems)
|
||||
.component(DriveComponents.USED_ITEMS, 0)
|
||||
.component(DriveComponents.ITEMSTACK_MAP, new HashMap<>())
|
||||
, identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
items.add(item);
|
||||
numberItems *= 2;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ public class SimpleBlockItem extends PolymerBlockItem implements PolymerItem {
|
||||
|
||||
public SimpleBlockItem(Item.Settings settings, Block block, Identifier identifier) {
|
||||
super(block, settings, Items.BARRIER);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier.withPath("item/" + identifier.getPath()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,6 +15,9 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.id;
|
||||
|
||||
public class SimpleItem extends SimplePolymerItem implements PolymerItem {
|
||||
@ -22,7 +25,7 @@ public class SimpleItem extends SimplePolymerItem implements PolymerItem {
|
||||
|
||||
public SimpleItem(Settings settings, Identifier identifier) {
|
||||
super(settings, Items.BARRIER);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier.withPath("item/" + identifier.getPath()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,9 +38,26 @@ public class SimpleItem extends SimplePolymerItem implements PolymerItem {
|
||||
return this.polymerModel.value();
|
||||
}
|
||||
|
||||
public static void register(String name) {
|
||||
public static Item register(String name){
|
||||
return register(name, 64);
|
||||
}
|
||||
|
||||
public static Item register(String name, int maxCount) {
|
||||
Identifier identifier = id(name);
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleItem(new Settings(), identifier));
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleItem(new Settings().maxCount(maxCount), identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
return item;
|
||||
}
|
||||
|
||||
public static List<Item> register(String name, List<String> tiers) {
|
||||
return register(name, tiers, 64);
|
||||
}
|
||||
|
||||
public static List<Item> register(String name, List<String> tiers, int maxCount) {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
for (String tier : tiers) {
|
||||
items.add(SimpleItem.register(tier + "_" + name, maxCount));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
package systems.brn.server_storage.items;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.id;
|
||||
import static systems.brn.server_storage.ServerStorage.tiers;
|
||||
|
||||
public class TieredItem extends SimpleItem implements PolymerItem {
|
||||
|
||||
public TieredItem(Item.Settings settings, Identifier identifier) {
|
||||
super(settings, identifier);
|
||||
}
|
||||
|
||||
public static void register(String name) {
|
||||
for (String tier : tiers) {
|
||||
SimpleItem.register(tier + "_" + name);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,9 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
|
||||
import systems.brn.server_storage.blockentities.StorageBlockEntity;
|
||||
import systems.brn.server_storage.items.HardDriveItem;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -16,6 +18,8 @@ import static systems.brn.server_storage.lib.StorageOperations.*;
|
||||
public class ConnectedChests {
|
||||
public final List<Inventory> inventories;
|
||||
public final List<Inventory> hoppers;
|
||||
public final List<Inventory> driveContainers;
|
||||
public final List<HardDriveItem> drives;
|
||||
public final Inventory inventory;
|
||||
|
||||
public final int containerCount;
|
||||
@ -26,12 +30,16 @@ public class ConnectedChests {
|
||||
public ConnectedChests(World world, BlockPos startPos, boolean sortAlphabetically, String searchString, boolean allInventories) {
|
||||
List<Inventory> inventories = new ArrayList<>();
|
||||
List<Inventory> hoppers = new ArrayList<>();
|
||||
List<Inventory> driveContainers = new ArrayList<>();
|
||||
List<HardDriveItem> drives = new ArrayList<>();
|
||||
Set<BlockPos> visited = new HashSet<>();
|
||||
|
||||
getConnectedChestsHelper(world, startPos, inventories, hoppers, visited, allInventories);
|
||||
getConnectedChestsHelper(world, startPos, inventories, hoppers, driveContainers, drives, visited, allInventories);
|
||||
|
||||
this.inventories = inventories;
|
||||
this.hoppers = hoppers;
|
||||
this.driveContainers = driveContainers;
|
||||
this.drives = drives;
|
||||
this.containerCount = inventories.size();
|
||||
this.inventory = getCombinedInventory(sortAlphabetically, searchString);
|
||||
|
||||
@ -61,7 +69,7 @@ public class ConnectedChests {
|
||||
blockEntity instanceof ShulkerBoxBlockEntity;
|
||||
}
|
||||
|
||||
private static void getConnectedChestsHelper(World world, BlockPos pos, List<Inventory> inventories, List<Inventory> hoppers, Set<BlockPos> visited, Boolean allContainers) {
|
||||
private static void getConnectedChestsHelper(World world, BlockPos pos, List<Inventory> inventories, List<Inventory> hoppers, List<Inventory> driveContainers, List<HardDriveItem> drives, Set<BlockPos> visited, Boolean allContainers) {
|
||||
if (visited.contains(pos)) {
|
||||
return;
|
||||
}
|
||||
@ -69,6 +77,15 @@ public class ConnectedChests {
|
||||
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
|
||||
if (blockEntity instanceof HardDriveContainerBlockEntity) {
|
||||
driveContainers.add((Inventory) blockEntity);
|
||||
//loop over all items in inventory
|
||||
for (int slot = 0; slot < inventories.size(); slot++) {
|
||||
ItemStack slotStack = ((Inventory) blockEntity).getStack(slot);
|
||||
//drives.add(new HardDriveItem(slotStack, (HardDriveContainerBlockEntity) blockEntity));
|
||||
}
|
||||
}
|
||||
|
||||
if (isEnabledHopper(blockEntity)) {
|
||||
hoppers.add((Inventory) blockEntity);
|
||||
}
|
||||
@ -80,7 +97,7 @@ public class ConnectedChests {
|
||||
|
||||
for (Direction direction : Direction.values()) {
|
||||
BlockPos nextPos = pos.offset(direction);
|
||||
getConnectedChestsHelper(world, nextPos, inventories, hoppers, visited, allContainers);
|
||||
getConnectedChestsHelper(world, nextPos, inventories, hoppers, driveContainers, drives, visited, allContainers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package systems.brn.server_storage.lib;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import eu.pb4.polymer.core.api.other.PolymerComponent;
|
||||
import net.minecraft.component.ComponentType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.util.dynamic.Codecs;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
|
||||
public class DriveComponents {
|
||||
public static final Codec<Map<ItemStack, Integer>> ITEMSTACK_MAP_CODEC = Codec.unboundedMap(ItemStack.CODEC, Codec.INT);
|
||||
|
||||
public static final ComponentType<Integer> MAX_ITEMS = register(
|
||||
"max_items", builder -> builder.codec(Codecs.POSITIVE_INT).packetCodec(PacketCodecs.VAR_INT)
|
||||
);
|
||||
|
||||
public static final ComponentType<Integer> USED_ITEMS = register(
|
||||
"used_items", builder -> builder.codec(Codecs.NONNEGATIVE_INT).packetCodec(PacketCodecs.VAR_INT)
|
||||
);
|
||||
|
||||
public static final ComponentType<Map<ItemStack, Integer>> ITEMSTACK_MAP = register(
|
||||
"itemstack_map",
|
||||
builder -> builder.codec(ITEMSTACK_MAP_CODEC) // No packetCodec needed for this example
|
||||
);
|
||||
|
||||
|
||||
private static <T> ComponentType<T> register(String id, UnaryOperator<ComponentType.Builder<T>> builderOperator) {
|
||||
ComponentType<T> componentType = Registry.register(
|
||||
Registries.DATA_COMPONENT_TYPE,
|
||||
id,
|
||||
builderOperator.apply(ComponentType.builder()).build()
|
||||
);
|
||||
PolymerComponent.registerDataComponent(componentType);
|
||||
return componentType;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package systems.brn.server_storage.lib;
|
||||
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
|
||||
import static systems.brn.server_storage.ServerStorage.DRIVES;
|
||||
|
||||
public class HardDriveSlot extends Slot {
|
||||
public HardDriveSlot(Inventory inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
}
|
||||
|
||||
public static boolean isHardDrive(Item item){
|
||||
return DRIVES.contains(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return isHardDrive(stack.getItem());
|
||||
}
|
||||
|
||||
}
|
84
src/main/java/systems/brn/server_storage/screenhandlers/DriveContainerScreenHandler.java
Normal file
84
src/main/java/systems/brn/server_storage/screenhandlers/DriveContainerScreenHandler.java
Normal file
@ -0,0 +1,84 @@
|
||||
package systems.brn.server_storage.screenhandlers;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import systems.brn.server_storage.lib.HardDriveSlot;
|
||||
|
||||
public class DriveContainerScreenHandler extends ScreenHandler {
|
||||
private static final int CONTAINER_SIZE = 9;
|
||||
private static final int INVENTORY_START = 9;
|
||||
private static final int INVENTORY_END = 36;
|
||||
private static final int HOTBAR_START = 36;
|
||||
private static final int HOTBAR_END = 45;
|
||||
private final Inventory inventory;
|
||||
|
||||
public DriveContainerScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory) {
|
||||
super(ScreenHandlerType.GENERIC_3X3, syncId);
|
||||
checkSize(inventory, 9);
|
||||
this.inventory = inventory;
|
||||
inventory.onOpen(playerInventory.player);
|
||||
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
for(int j = 0; j < 3; ++j) {
|
||||
this.addSlot(new HardDriveSlot(inventory, j + i * 3, 62 + j * 18, 17 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
for(int j = 0; j < 9; ++j) {
|
||||
this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 9; ++i) {
|
||||
this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return this.inventory.canPlayerUse(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMove(PlayerEntity player, int slot) {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
Slot slot2 = this.slots.get(slot);
|
||||
if (slot2.hasStack()) {
|
||||
ItemStack itemStack2 = slot2.getStack();
|
||||
itemStack = itemStack2.copy();
|
||||
if (slot < 9) {
|
||||
if (!this.insertItem(itemStack2, 9, 45, true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.insertItem(itemStack2, 0, 9, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemStack2.isEmpty()) {
|
||||
slot2.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot2.markDirty();
|
||||
}
|
||||
|
||||
if (itemStack2.getCount() == itemStack.getCount()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
slot2.onTakeItem(player, itemStack2);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed(PlayerEntity player) {
|
||||
super.onClosed(player);
|
||||
this.inventory.onClose(player);
|
||||
}
|
||||
}
|
@ -1,7 +1,27 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"facing=down": {
|
||||
"model": "serverstorage:block/drive_container",
|
||||
"x": 180
|
||||
},
|
||||
"facing=east": {
|
||||
"model": "serverstorage:block/drive_container",
|
||||
"y": 90
|
||||
},
|
||||
"facing=north": {
|
||||
"model": "serverstorage:block/drive_container"
|
||||
},
|
||||
"facing=south": {
|
||||
"model": "serverstorage:block/drive_container",
|
||||
"y": 180
|
||||
},
|
||||
"facing=up": {
|
||||
"model": "serverstorage:block/drive_container",
|
||||
"x": 90
|
||||
},
|
||||
"facing=west": {
|
||||
"model": "serverstorage:block/drive_container",
|
||||
"y": 270
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,26 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"facing=down": {
|
||||
"model": "serverstorage:block/storage",
|
||||
"x": 180
|
||||
},
|
||||
"facing=east": {
|
||||
"model": "serverstorage:block/storage",
|
||||
"y": 90
|
||||
},
|
||||
"facing=north": {
|
||||
"model": "serverstorage:block/storage"
|
||||
},
|
||||
"facing=south": {
|
||||
"model": "serverstorage:block/storage",
|
||||
"y": 180
|
||||
},
|
||||
"facing=up": {
|
||||
"model": "serverstorage:block/storage"
|
||||
},
|
||||
"facing=west": {
|
||||
"model": "serverstorage:block/storage",
|
||||
"y": 270
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user