Compare commits
22 Commits
b2247125b2
...
main
Author | SHA1 | Date | |
---|---|---|---|
1e38561f5e
|
|||
0c7094f01d
|
|||
fc5b5470b8
|
|||
f87a0c6c14
|
|||
d8c4773424
|
|||
5a45506bd9
|
|||
a0f12ed4b1
|
|||
00fef620d5
|
|||
fb52a6580f
|
|||
c1648f1e13 | |||
92838e6c50 | |||
998a6b7b04 | |||
|
61428a1c9c | ||
|
31a7fc9d03 | ||
4be669f41f
|
|||
f1dd6b9c3c | |||
af56360fad | |||
7cea6fbf83 | |||
9956589189 | |||
51ce3a9774 | |||
2c40d3ae3f | |||
f63a5a36d7 |
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.6-SNAPSHOT'
|
||||
id 'fabric-loom' version '1.11-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
|
@@ -3,19 +3,19 @@ org.gradle.jvmargs=-Xmx1G
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
|
||||
minecraft_version=1.21.1
|
||||
yarn_mappings=1.21.1+build.3
|
||||
loader_version=0.16.0
|
||||
minecraft_version=1.21.8
|
||||
yarn_mappings=1.21.8+build.1
|
||||
loader_version=0.16.14
|
||||
|
||||
# Fabric API
|
||||
fabric_version=0.102.1+1.21.1
|
||||
fabric_version=0.129.0+1.21.8
|
||||
|
||||
# Mod Properties
|
||||
mod_version=3.1.2
|
||||
mod_version=3.3.7
|
||||
maven_group=systems.brn
|
||||
archives_base_name=Serverstorage
|
||||
|
||||
# Dependencies
|
||||
polymer_version=0.9.9+1.21
|
||||
server_translations_api_version=2.3.1+1.21-pre2
|
||||
servergui_version=1.6.0+1.21
|
||||
polymer_version=0.13.7+1.21.8
|
||||
server_translations_api_version=2.5.1+1.21.5
|
||||
servergui_version=1.10.2+1.21.8
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
@@ -2,6 +2,7 @@ package systems.brn.serverstorage;
|
||||
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.player.UseItemCallback;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
@@ -9,27 +10,35 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.GameRules;
|
||||
import systems.brn.serverstorage.blockentities.HardDriveContainerBlockEntity;
|
||||
import systems.brn.serverstorage.blockentities.InventoryInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.blockentities.StorageInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.blocks.BusConnectorBlock;
|
||||
import systems.brn.serverstorage.blocks.HardDriveContainerBlock;
|
||||
import systems.brn.serverstorage.blocks.InventoryInterfaceBlock;
|
||||
import systems.brn.serverstorage.blocks.StorageInterfaceBlock;
|
||||
import systems.brn.serverstorage.blockentities.*;
|
||||
import systems.brn.serverstorage.blocks.*;
|
||||
import systems.brn.serverstorage.items.HardDriveItem;
|
||||
import systems.brn.serverstorage.items.SimpleBlockItem;
|
||||
import systems.brn.serverstorage.items.SimpleItem;
|
||||
import systems.brn.serverstorage.items.WirelessTerminalItem;
|
||||
import systems.brn.serverstorage.lib.Antenna;
|
||||
import systems.brn.serverstorage.lib.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ServerStorage implements ModInitializer {
|
||||
public static final List<String> moduleList = Arrays.asList("bus", "configuration", "container", "display", "drive", "filtering", "inventory", "pagination", "pcb", "transport", "netherite_upgrade");
|
||||
public static final List<String> moduleList = Arrays.asList("bus", "configuration", "container", "display", "drive", "filtering", "inventory", "pagination", "pcb", "transport", "antenna", "radio", "antenna_connector", "modem", "netherite_upgrade");
|
||||
public static final List<String> tiers = Arrays.asList("iron", "golden", "diamond", "netherite");
|
||||
public static final List<String> tiersAntenna = Arrays.asList("iron", "golden", "diamond", "netherite", "ender");
|
||||
public static final List<String> tiersDrive = Arrays.asList("iron", "golden", "diamond", "netherite", "creative");
|
||||
public static final List<String> materialList = Arrays.asList("pcb", "pcb_substrate", "cpu", "cpu_substrate", "drive_controller", "drive_casing");
|
||||
|
||||
public static final String MOD_ID = "serverstorage";
|
||||
|
||||
public static final String WIRELESS_TERMINAL_ID = "wireless_terminal";
|
||||
|
||||
public static final String DISPLAY_BLOCK_MODEL_ID = "display_block";
|
||||
public static DisplayBlock DISPLAY_BLOCK;
|
||||
public static BlockEntityType<DisplayBlockEntity> DISPLAY_BLOCK_ENTITY;
|
||||
|
||||
public static final String BUS_CONNECTOR_MODEL_ID = "bus_connector";
|
||||
public static BusConnectorBlock BUS_CONNECTOR_BLOCK;
|
||||
|
||||
@@ -37,6 +46,10 @@ public class ServerStorage implements ModInitializer {
|
||||
public static BlockEntityType<HardDriveContainerBlockEntity> HARD_DRIVE_CONTAINER_BLOCK_ENTITY;
|
||||
public static HardDriveContainerBlock HARD_DRIVE_CONTAINER_BLOCK;
|
||||
|
||||
public static final String RADIO_INTERFACE_BLOCK_MODEL_ID = "radio_interface";
|
||||
public static BlockEntityType<RadioInterfaceBlockEntity> RADIO_INTERFACE_BLOCK_ENTITY;
|
||||
public static RadioInterfaceBlock RADIO_INTERFACE_BLOCK;
|
||||
|
||||
public static final String STORAGE_MODEL_ID = "storage";
|
||||
public static StorageInterfaceBlock STORAGE_INTERFACE_BLOCK;
|
||||
public static BlockEntityType<StorageInterfaceBlockEntity> STORAGE_INTERFACE_BLOCK_ENTITY;
|
||||
@@ -60,6 +73,10 @@ public class ServerStorage implements ModInitializer {
|
||||
public static List<Item> PLATTERS;
|
||||
public static List<Item> DRIVES;
|
||||
public static List<Item> HEADS;
|
||||
public static List<Item> ANTENNA_LIST = new ArrayList<>();
|
||||
public static final HashMap<Item, Integer> ANTENNA_RANGES = new HashMap<>();
|
||||
|
||||
public static Item WIRELESS_TERMINAL;
|
||||
|
||||
|
||||
public static Identifier id(String path) {
|
||||
@@ -80,13 +97,26 @@ public class ServerStorage implements ModInitializer {
|
||||
InventoryInterfaceBlock.register();
|
||||
SimpleBlockItem.register(INVENTORY_INTERFACE_BLOCK);
|
||||
|
||||
RadioInterfaceBlock.register();
|
||||
SimpleBlockItem.register(RADIO_INTERFACE_BLOCK);
|
||||
|
||||
DisplayBlock.register();
|
||||
SimpleBlockItem.register(DISPLAY_BLOCK);
|
||||
|
||||
MATERIALS = SimpleItem.register("material", materialList, false, ItemGroups.INGREDIENTS);
|
||||
MODULES = SimpleItem.register("module", moduleList, false, ItemGroups.INGREDIENTS);
|
||||
|
||||
HEADS = SimpleItem.register("head", tiers, ItemGroups.INGREDIENTS);
|
||||
PLATTERS = SimpleItem.register("platter", tiers, ItemGroups.INGREDIENTS);
|
||||
|
||||
DRIVES = HardDriveItem.register(tiers);
|
||||
DRIVES = HardDriveItem.register(tiersDrive);
|
||||
|
||||
ANTENNA_LIST = Antenna.register(tiersAntenna);
|
||||
|
||||
WIRELESS_TERMINAL = WirelessTerminalItem.register();
|
||||
|
||||
|
||||
UseItemCallback.EVENT.register(EventHandler::onItemUse);
|
||||
|
||||
systems.brn.serverstorage.lib.ItemGroups.register();
|
||||
PolymerResourcePackUtils.addModAssets(MOD_ID);
|
||||
|
@@ -0,0 +1,143 @@
|
||||
package systems.brn.serverstorage.blockentities;
|
||||
|
||||
import eu.pb4.polymer.virtualentity.api.ElementHolder;
|
||||
import eu.pb4.polymer.virtualentity.api.attachment.ChunkAttachment;
|
||||
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
|
||||
import eu.pb4.polymer.virtualentity.api.elements.TextDisplayElement;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.storage.ReadView;
|
||||
import net.minecraft.storage.WriteView;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import org.joml.Vector3f;
|
||||
import systems.brn.serverstorage.lib.SortMode;
|
||||
import systems.brn.serverstorage.lib.StorageNetwork;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.DISPLAY_BLOCK_ENTITY;
|
||||
import static systems.brn.serverstorage.blocks.DisplayBlock.FACING;
|
||||
|
||||
public class DisplayBlockEntity extends BlockEntity {
|
||||
public ItemStack targetItem;
|
||||
public int itemCount;
|
||||
public StorageNetwork network;
|
||||
|
||||
private final ElementHolder holder = new ElementHolder();
|
||||
public final ItemDisplayElement itemElement = new ItemDisplayElement();
|
||||
public final TextDisplayElement textDisplayElement = new TextDisplayElement();
|
||||
|
||||
private boolean attached = false;
|
||||
|
||||
public void reindexDrives() {
|
||||
if (this.network != null) {
|
||||
this.network.searchString = "*";
|
||||
this.network.reindexNetwork();
|
||||
} else {
|
||||
this.network = new StorageNetwork(world, this.pos, SortMode.NUMERICALLY_REVERSE, "*", false);
|
||||
}
|
||||
}
|
||||
|
||||
public DisplayBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(DISPLAY_BLOCK_ENTITY, pos, state);
|
||||
targetItem = ItemStack.EMPTY;
|
||||
itemCount = 1;
|
||||
itemElement.setItem(targetItem);
|
||||
textDisplayElement.setText(Text.of(String.valueOf(itemCount)));
|
||||
// You can offset to make it float in front of the block
|
||||
Vector3f vec = new Vector3f(0.5f, 0.5f, 0.5f); // mutable
|
||||
|
||||
// Get the block's facing direction as a Vec3d
|
||||
Vec3d facingVec = state.get(FACING).getDoubleVector(); // Example: NORTH = (0, 0, -1)
|
||||
|
||||
// Calculate outward offset for the item
|
||||
Vec3d itemOffset = facingVec.multiply(0.5);
|
||||
itemElement.setOffset(itemOffset);
|
||||
|
||||
// Define global "up"
|
||||
Vec3d up = new Vec3d(0, 1, 0);
|
||||
|
||||
// Compute perpendicular "down" relative to the block face
|
||||
Vec3d down = facingVec.crossProduct(up).normalize().multiply(0.3);
|
||||
|
||||
// Final text offset: outward from face + downward relative to face
|
||||
Vec3d textOffset = facingVec.normalize().multiply(0.5).add(down);
|
||||
textDisplayElement.setOffset(textOffset.add(0,0.25,0));
|
||||
|
||||
switch (state.get(FACING)) {
|
||||
case NORTH -> textDisplayElement.setRotation(0, 180);
|
||||
case SOUTH -> textDisplayElement.setRotation(0, 0);
|
||||
case WEST -> textDisplayElement.setRotation(0, 90);
|
||||
case EAST -> textDisplayElement.setRotation(0, 270);
|
||||
case UP -> textDisplayElement.setRotation(-90, 0); // text points down
|
||||
case DOWN -> textDisplayElement.setRotation(90, 0); // text points up
|
||||
}
|
||||
|
||||
// assign to const interface
|
||||
itemElement.setScale(vec); // Optional
|
||||
holder.addElement(itemElement);
|
||||
holder.addElement(textDisplayElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(ReadView view) {
|
||||
super.readData(view);
|
||||
this.targetItem = ItemStack.EMPTY;
|
||||
this.itemCount = 0;
|
||||
view.read("TargetItem", ItemStack.CODEC).ifPresent(itemStack -> this.targetItem = itemStack.copy());
|
||||
this.itemCount = view.getInt("TargetItemCount", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registries) {
|
||||
return createNbt(registries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markRemoved() {
|
||||
textDisplayElement.setText(Text.of(""));
|
||||
itemElement.setItem(Items.AIR.getDefaultStack());
|
||||
super.markRemoved();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(WriteView view) {
|
||||
super.writeData(view);
|
||||
|
||||
view.putInt("TargetItemCount", itemCount);
|
||||
view.putNullable("TargetItem", ItemStack.CODEC, targetItem.copy());
|
||||
}
|
||||
|
||||
public static <T extends BlockEntity> void tick(World world, BlockPos blockPos, BlockState blockState, T t) {
|
||||
if (t instanceof DisplayBlockEntity displayBlockEntity) {
|
||||
if (!world.isClient()) {
|
||||
if (displayBlockEntity.network == null) {
|
||||
displayBlockEntity.reindexDrives();
|
||||
displayBlockEntity.itemCount = 0;
|
||||
for(Map.Entry<ItemStack, Integer> entry : displayBlockEntity.network.itemStackMap.entrySet()) {
|
||||
ItemStack key = entry.getKey();
|
||||
Integer value = entry.getValue();
|
||||
if (ItemStack.areItemsAndComponentsEqual(key, displayBlockEntity.targetItem)) {
|
||||
displayBlockEntity.itemCount = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
displayBlockEntity.itemElement.setItem(displayBlockEntity.targetItem);
|
||||
displayBlockEntity.textDisplayElement.setText(Text.of(String.valueOf(displayBlockEntity.itemCount)));
|
||||
}
|
||||
if (!displayBlockEntity.attached) {
|
||||
displayBlockEntity.attached = true;
|
||||
ChunkAttachment.ofTicking(displayBlockEntity.holder, (ServerWorld) world, blockPos.toCenterPos());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,9 +5,9 @@ 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.storage.ReadView;
|
||||
import net.minecraft.storage.WriteView;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -61,19 +61,19 @@ public class HardDriveContainerBlockEntity extends LootableContainerBlockEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
|
||||
super.readNbt(nbt, registryLookup);
|
||||
protected void readData(ReadView view) {
|
||||
super.readData(view);
|
||||
this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY);
|
||||
if (!this.readLootTable(nbt)) {
|
||||
Inventories.readNbt(nbt, this.inventory, registryLookup);
|
||||
if (!this.readLootTable(view)) {
|
||||
Inventories.readData(view, this.inventory);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
|
||||
super.writeNbt(nbt, registryLookup);
|
||||
if (!this.writeLootTable(nbt)) {
|
||||
Inventories.writeNbt(nbt, this.inventory, registryLookup);
|
||||
protected void writeData(WriteView view) {
|
||||
super.writeData(view);
|
||||
if (!this.writeLootTable(view)) {
|
||||
Inventories.writeData(view, this.inventory);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,13 +4,15 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.storage.ReadView;
|
||||
import net.minecraft.storage.WriteView;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import systems.brn.serverstorage.lib.ConnectionType;
|
||||
import systems.brn.serverstorage.lib.SortMode;
|
||||
import systems.brn.serverstorage.lib.StorageNetwork;
|
||||
import systems.brn.serverstorage.screens.SettingsScreen;
|
||||
|
||||
@@ -46,7 +48,7 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
|
||||
this.network.searchString = query;
|
||||
this.network.reindexNetwork();
|
||||
} else {
|
||||
this.network = new StorageNetwork(world, this.pos, false, query);
|
||||
this.network = new StorageNetwork(world, this.pos, SortMode.NUMERICALLY_REVERSE, query, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,29 +59,29 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
|
||||
}
|
||||
|
||||
public void nextDirection() {
|
||||
int newId = (direction.getId() + 1) % 6;
|
||||
direction = Direction.byId(newId);
|
||||
int newId = (direction.getIndex() + 1) % 6;
|
||||
direction = Direction.byIndex(newId);
|
||||
}
|
||||
|
||||
// Serialize the BlockEntity
|
||||
@Override
|
||||
public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
|
||||
public void writeData(WriteView view) {
|
||||
// Save the current value of the number to the nbt
|
||||
nbt.putBoolean("isOutput", isOutput);
|
||||
nbt.putInt("direction", direction.getId());
|
||||
nbt.putInt("tickCounter", tickCounter);
|
||||
nbt.putString("query", query);
|
||||
super.writeNbt(nbt, wrapperLookup);
|
||||
view.putBoolean("isOutput", isOutput);
|
||||
view.putInt("direction", direction.getIndex());
|
||||
view.putInt("tickCounter", tickCounter);
|
||||
view.putString("query", query);
|
||||
super.writeData(view);
|
||||
}
|
||||
|
||||
// Deserialize the BlockEntity
|
||||
@Override
|
||||
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
|
||||
super.readNbt(nbt, wrapperLookup);
|
||||
isOutput = nbt.getBoolean("isOutput");
|
||||
direction = Direction.byId(nbt.getInt("direction"));
|
||||
tickCounter = nbt.getInt("tickCounter");
|
||||
query = nbt.getString("query");
|
||||
public void readData(ReadView view) {
|
||||
super.readData(view);
|
||||
isOutput = view.getBoolean("isOutput", false);
|
||||
direction = Direction.byIndex(view.getInt("direction", Direction.NORTH.getIndex()));
|
||||
tickCounter = view.getInt("tickCounter", 0);
|
||||
query = view.getString("query", "");
|
||||
}
|
||||
|
||||
private static int processIncomingInternal(ItemStack stack, int count, InventoryInterfaceBlockEntity blockEntity, Inventory targetedBlockEntityInventory) {
|
||||
@@ -94,7 +96,7 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
|
||||
ItemStack cappedStack = insertedStack.copy();
|
||||
cappedStack.setCount(Math.min(insertedStack.getMaxCount(), remainingToInsert));
|
||||
|
||||
ItemStack remaining = insertStackIntoInventory(targetedBlockEntityInventory, cappedStack.copy());
|
||||
ItemStack remaining = insertStackIntoInventory(targetedBlockEntityInventory, cappedStack.copy(), false);
|
||||
if (!remaining.isEmpty()) {
|
||||
ItemStack reverseStack = stack.copy();
|
||||
reverseStack.setCount(remaining.getCount() + remainingToInsert);
|
||||
@@ -107,7 +109,7 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
|
||||
}
|
||||
|
||||
public int processIncoming(ItemStack stack, int count) {
|
||||
if (world != null && world.getGameRules().getBoolean(ServerStorage_Interface_Enable) && isOutput && filterItem(stack.getItem(), query)) {
|
||||
if (world != null && ((ServerWorld) world).getGameRules().getBoolean(ServerStorage_Interface_Enable) && isOutput && filterItem(stack.getItem(), query)) {
|
||||
BlockPos targetedPos = pos.offset(direction);
|
||||
BlockEntity targetedBlockEntity = world.getBlockEntity(targetedPos);
|
||||
EnumProperty<ConnectionType> connectionType = getPropertyForDirection(direction);
|
||||
@@ -124,7 +126,7 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
|
||||
}
|
||||
|
||||
public static <T extends BlockEntity> void tick(World world, BlockPos blockPos, BlockState ignoredState, T ignoredt) {
|
||||
if (!world.getGameRules().getBoolean(ServerStorage_Interface_Enable)) {
|
||||
if (!((ServerWorld) world).getGameRules().getBoolean(ServerStorage_Interface_Enable)) {
|
||||
return;
|
||||
}
|
||||
InventoryInterfaceBlockEntity blockEntity = (InventoryInterfaceBlockEntity) world.getBlockEntity(blockPos);
|
||||
@@ -149,7 +151,7 @@ public class InventoryInterfaceBlockEntity extends BlockEntity {
|
||||
} else {
|
||||
Map<ItemStack, Integer> targetedBlockInventoryMap = new HashMap<>();
|
||||
addInventoryToMap(targetedBlockEntityInventory, targetedBlockInventoryMap);
|
||||
targetedBlockInventoryMap = sortAndFilterMap(targetedBlockInventoryMap, false, blockEntity.query);
|
||||
targetedBlockInventoryMap = sortAndFilterMap(targetedBlockInventoryMap, SortMode.NUMERICALLY_REVERSE, blockEntity.query, false);
|
||||
for (Map.Entry<ItemStack, Integer> entry : targetedBlockInventoryMap.entrySet()) {
|
||||
ItemStack stack = entry.getKey();
|
||||
int count = entry.getValue();
|
||||
|
@@ -0,0 +1,124 @@
|
||||
package systems.brn.serverstorage.blockentities;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.storage.ReadView;
|
||||
import net.minecraft.storage.WriteView;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import systems.brn.serverstorage.lib.Session;
|
||||
import systems.brn.serverstorage.screenhandlers.RadioInterfaceScreenHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.ANTENNA_RANGES;
|
||||
import static systems.brn.serverstorage.ServerStorage.RADIO_INTERFACE_BLOCK_ENTITY;
|
||||
import static systems.brn.serverstorage.lib.Session.SESSION_LIST_CODEC;
|
||||
|
||||
public class RadioInterfaceBlockEntity extends LootableContainerBlockEntity {
|
||||
public DefaultedList<ItemStack> inventory;
|
||||
public int antennaRange = 0;
|
||||
public final ArrayList<Session> sessions = new ArrayList<>();
|
||||
public static final int INVENTORY_SIZE = 1;
|
||||
|
||||
public RadioInterfaceBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(RADIO_INTERFACE_BLOCK_ENTITY, pos, state);
|
||||
this.inventory = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY);
|
||||
updateAntenna();
|
||||
}
|
||||
|
||||
public boolean isSessionAuthorized(UUID sessionKey, UUID playerUUID) {
|
||||
for (Session session : sessions) {
|
||||
if (session.sessionKey().equals(sessionKey) && session.playerUUID().equals(playerUUID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void authorizeSession(UUID sessionKey, ServerPlayerEntity player) {
|
||||
if (!isSessionAuthorized(sessionKey, player.getUuid())) {
|
||||
sessions.add(new Session(sessionKey, player.getUuid()));
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void deAuthorizeSession(UUID sessionKey, UUID playerUUID) {
|
||||
for (Session session : sessions) {
|
||||
if (session.sessionKey().equals(sessionKey) && session.playerUUID().equals(playerUUID)) {
|
||||
sessions.remove(session);
|
||||
markDirty();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAntenna() {
|
||||
ItemStack stack = inventory.getFirst();
|
||||
if (!stack.isEmpty()) {
|
||||
Item antennaItem = stack.getItem();
|
||||
antennaRange = ANTENNA_RANGES.getOrDefault(antennaItem, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Text getContainerName() {
|
||||
return Text.translatable("block.serverstorage.radio_interface");
|
||||
}
|
||||
|
||||
@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 RadioInterfaceScreenHandler(syncId, playerInventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return INVENTORY_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(ReadView view) {
|
||||
super.readData(view);
|
||||
this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY);
|
||||
this.antennaRange = view.getInt("AntennaRange", 0);
|
||||
if (!this.readLootTable(view)) {
|
||||
Inventories.readData(view, this.inventory);
|
||||
}
|
||||
updateAntenna();
|
||||
// Deserialize sessions list
|
||||
this.sessions.clear();
|
||||
|
||||
Optional<List<Session>> sessionsTmp = view.read("Sessions", SESSION_LIST_CODEC);
|
||||
sessionsTmp.ifPresent(this.sessions::addAll);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(WriteView view) {
|
||||
super.writeData(view);
|
||||
view.putInt("AntennaRange", antennaRange);
|
||||
if (!this.writeLootTable(view)) {
|
||||
Inventories.writeData(view, this.inventory);
|
||||
}
|
||||
view.put("Sessions", SESSION_LIST_CODEC, sessions);
|
||||
}
|
||||
}
|
@@ -2,9 +2,10 @@ package systems.brn.serverstorage.blockentities;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.storage.ReadView;
|
||||
import net.minecraft.storage.WriteView;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import systems.brn.serverstorage.lib.SortMode;
|
||||
import systems.brn.serverstorage.lib.StorageNetwork;
|
||||
import systems.brn.serverstorage.screens.CraftingScreen;
|
||||
import systems.brn.serverstorage.screens.StorageScreen;
|
||||
@@ -15,8 +16,9 @@ import static systems.brn.serverstorage.ServerStorage.STORAGE_INTERFACE_BLOCK_EN
|
||||
|
||||
public class StorageInterfaceBlockEntity extends BlockEntity {
|
||||
|
||||
public Boolean sortAlphabetically = false;
|
||||
public SortMode sortAlphabetically = SortMode.NUMERICALLY_REVERSE;
|
||||
public String searchString = "";
|
||||
public Boolean groupSimilar = false;
|
||||
public int page = 0;
|
||||
public StorageNetwork network;
|
||||
|
||||
@@ -30,10 +32,17 @@ public class StorageInterfaceBlockEntity extends BlockEntity {
|
||||
public void reindexDrives() {
|
||||
if (this.network != null) {
|
||||
this.network.searchString = searchString;
|
||||
this.network.sortAlphabetically = sortAlphabetically;
|
||||
this.network.sortMode = sortAlphabetically;
|
||||
this.network.groupSimilar = groupSimilar;
|
||||
this.network.reindexNetwork();
|
||||
} else {
|
||||
this.network = new StorageNetwork(world, this.pos, sortAlphabetically, searchString);
|
||||
this.network = new StorageNetwork(world, this.pos, sortAlphabetically, searchString, groupSimilar);
|
||||
}
|
||||
}
|
||||
|
||||
public void enforceNetwork() {
|
||||
if (this.network == null) {
|
||||
this.network = new StorageNetwork(world, this.pos, sortAlphabetically, searchString, groupSimilar);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,22 +62,24 @@ public class StorageInterfaceBlockEntity extends BlockEntity {
|
||||
|
||||
// Serialize the BlockEntity
|
||||
@Override
|
||||
public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
|
||||
public void writeData(WriteView view) {
|
||||
// Save the current value of the number to the nbt
|
||||
nbt.putInt("page", page);
|
||||
nbt.putBoolean("sortAlphabetically", sortAlphabetically);
|
||||
nbt.putString("searchString", searchString);
|
||||
view.putInt("page", page);
|
||||
view.putInt("sortAlphabetically", sortAlphabetically.getId());
|
||||
view.putString("searchString", searchString);
|
||||
view.putBoolean("groupSimilar", groupSimilar);
|
||||
|
||||
super.writeNbt(nbt, wrapperLookup);
|
||||
super.writeData(view);
|
||||
}
|
||||
|
||||
// Deserialize the BlockEntity
|
||||
@Override
|
||||
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
|
||||
super.readNbt(nbt, wrapperLookup);
|
||||
public void readData(ReadView view) {
|
||||
super.readData(view);
|
||||
|
||||
page = nbt.getInt("page");
|
||||
sortAlphabetically = nbt.getBoolean("sortAlphabetically");
|
||||
searchString = nbt.getString("searchString");
|
||||
page = view.getInt("page", 0);
|
||||
sortAlphabetically = SortMode.fromId(view.getInt("sortAlphabetically", SortMode.NUMERICALLY_REVERSE.getId()));
|
||||
searchString = view.getString("searchString", "");
|
||||
groupSimilar = view.getBoolean("groupSimilar", false);
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,10 @@ import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.*;
|
||||
|
||||
@@ -27,14 +30,14 @@ public class BusConnectorBlock extends ConnectedBlock implements PolymerTextured
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
public BlockState getPolymerBlockState(BlockState state, PacketContext packetContext) {
|
||||
return this.polymerBlockState;
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = id(BUS_CONNECTOR_MODEL_ID);
|
||||
BUS_CONNECTOR_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new BusConnectorBlock(AbstractBlock.Settings.copy(Blocks.WHITE_WOOL), modId));
|
||||
new BusConnectorBlock(AbstractBlock.Settings.copy(Blocks.WHITE_WOOL).registryKey(RegistryKey.of(RegistryKeys.BLOCK, modId)), modId));
|
||||
BUS_CONNECTOR_BLOCK.setDefaultState();
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package systems.brn.serverstorage.blocks;
|
||||
|
||||
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.core.api.block.SimplePolymerBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -9,11 +12,15 @@ import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.block.WireOrientation;
|
||||
import systems.brn.serverstorage.lib.ConnectionType;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnectedBlock extends SimplePolymerBlock {
|
||||
|
||||
public static final EnumProperty<ConnectionType> NORTH = EnumProperty.of("north", ConnectionType.class);
|
||||
@@ -23,6 +30,39 @@ public class ConnectedBlock extends SimplePolymerBlock {
|
||||
public static final EnumProperty<ConnectionType> UP = EnumProperty.of("up", ConnectionType.class);
|
||||
public static final EnumProperty<ConnectionType> DOWN = EnumProperty.of("down", ConnectionType.class);
|
||||
|
||||
// Function to get Y-axis rotation for North, South, East, and West directions
|
||||
public static int getRotationFromDirection(Direction direction) {
|
||||
if (direction == Direction.EAST) {
|
||||
return 90;
|
||||
} else if (direction == Direction.SOUTH) {
|
||||
return 180;
|
||||
} else if (direction == Direction.WEST) {
|
||||
return 270;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to get X-axis rotation for Up and Down directions
|
||||
public static int getXRotationFromDirection(Direction direction) {
|
||||
if (direction == Direction.UP) {
|
||||
return 270;
|
||||
} else if (direction == Direction.DOWN) {
|
||||
return 90;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<Direction, BlockState> generateRotations(Identifier identifier) {
|
||||
Identifier modelIdentifier = identifier.withPath("block/" + identifier.getPath());
|
||||
HashMap<Direction, BlockState> rotations = new HashMap<>();
|
||||
for (Direction direction : Direction.values()) {
|
||||
rotations.put(direction, PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(modelIdentifier, getXRotationFromDirection(direction), getRotationFromDirection(direction))));
|
||||
}
|
||||
return rotations;
|
||||
}
|
||||
|
||||
public void setDefaultState() {
|
||||
setDefaultState(getStateManager().getDefaultState()
|
||||
.with(NORTH, ConnectionType.NONE)
|
||||
@@ -53,9 +93,9 @@ public class ConnectedBlock extends SimplePolymerBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, WireOrientation wireOrientation, boolean notify) {
|
||||
updateBlockState(world, pos, state);
|
||||
super.neighborUpdate(state, world, pos, block, fromPos, notify);
|
||||
super.neighborUpdate(state, world, pos, block, wireOrientation, notify);
|
||||
}
|
||||
|
||||
private BlockState updateState(BlockState state, World world, BlockPos pos) {
|
||||
@@ -66,9 +106,9 @@ public class ConnectedBlock extends SimplePolymerBlock {
|
||||
BlockEntity blockEntity = world.getBlockEntity(neighborPos);
|
||||
boolean isConnectedToInventory = blockEntity instanceof Inventory;
|
||||
ConnectionType connectionType = ConnectionType.NONE;
|
||||
if (isConnectedToBus){
|
||||
if (isConnectedToBus) {
|
||||
connectionType = ConnectionType.BUS;
|
||||
} else if (isConnectedToInventory){
|
||||
} else if (isConnectedToInventory) {
|
||||
connectionType = ConnectionType.INVENTORY;
|
||||
}
|
||||
|
||||
|
221
src/main/java/systems/brn/serverstorage/blocks/DisplayBlock.java
Normal file
221
src/main/java/systems/brn/serverstorage/blocks/DisplayBlock.java
Normal file
@@ -0,0 +1,221 @@
|
||||
package systems.brn.serverstorage.blocks;
|
||||
|
||||
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
|
||||
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
|
||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
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.serverstorage.blockentities.DisplayBlockEntity;
|
||||
import systems.brn.serverstorage.screens.DisplayBlockMangementScreen;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.*;
|
||||
import static systems.brn.serverstorage.lib.StorageOperations.*;
|
||||
|
||||
|
||||
public class DisplayBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
final Identifier identifier;
|
||||
public static final EnumProperty<Direction> FACING = FacingBlock.FACING;
|
||||
private final HashMap<Direction, BlockState> rotations;
|
||||
|
||||
public DisplayBlock(Settings settings, Identifier identifier) {
|
||||
super(settings, Blocks.NOTE_BLOCK);
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
|
||||
this.rotations = generateRotations(identifier);
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state, PacketContext packetContext) {
|
||||
Direction direction = state.get(FACING);
|
||||
return rotations.get(direction);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = id(DISPLAY_BLOCK_MODEL_ID);
|
||||
DISPLAY_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new DisplayBlock(Settings.copy(Blocks.WHITE_WOOL).registryKey(RegistryKey.of(RegistryKeys.BLOCK, modId)), modId));
|
||||
UseBlockCallback.EVENT.register(DisplayBlock::onUse);
|
||||
DISPLAY_BLOCK.setDefaultState();
|
||||
|
||||
DISPLAY_BLOCK_ENTITY = Registry.register(
|
||||
Registries.BLOCK_ENTITY_TYPE,
|
||||
modId,
|
||||
FabricBlockEntityTypeBuilder.create(DisplayBlockEntity::new, DISPLAY_BLOCK).build(null)
|
||||
);
|
||||
|
||||
DISPLAY_BLOCK_ENTITY.addSupportedBlock(DISPLAY_BLOCK);
|
||||
AttackBlockCallback.EVENT.register(DisplayBlock::onAttack);
|
||||
PolymerBlockUtils.registerBlockEntity(DISPLAY_BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
private static ActionResult onAttack(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
||||
BlockEntity storageBlockEntity = world.getBlockEntity(pos);
|
||||
if (storageBlockEntity instanceof DisplayBlockEntity displayBlockEntity) {
|
||||
displayBlockEntity.reindexDrives();
|
||||
int maxFit = howMuchFits(displayBlockEntity.targetItem, player.getInventory());
|
||||
int finalCount = Math.min(player.isSneaking() ? displayBlockEntity.targetItem.getMaxCount() : 1, maxFit);
|
||||
ItemStack insertedStack = displayBlockEntity.targetItem.copy();
|
||||
insertedStack.setCount(finalCount);
|
||||
|
||||
displayBlockEntity.itemCount = 0;
|
||||
for (Map.Entry<ItemStack, Integer> entry : displayBlockEntity.network.itemStackMap.entrySet()) {
|
||||
ItemStack key = entry.getKey();
|
||||
Integer value = entry.getValue();
|
||||
if (ItemStack.areItemsAndComponentsEqual(key, displayBlockEntity.targetItem)) {
|
||||
displayBlockEntity.itemCount = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
finalCount -= displayBlockEntity.network.removeItemStack(insertedStack).getCount();
|
||||
displayBlockEntity.network.updateDisplays();
|
||||
|
||||
displayBlockEntity.itemCount -= finalCount;
|
||||
|
||||
displayBlockEntity.itemElement.setItem(displayBlockEntity.targetItem);
|
||||
displayBlockEntity.textDisplayElement.setText(Text.of(String.valueOf(displayBlockEntity.itemCount)));
|
||||
|
||||
int remainingToInsert = finalCount;
|
||||
for (int i = 0; i < Math.ceilDivExact(finalCount, displayBlockEntity.targetItem.getMaxCount()); i++) {
|
||||
ItemStack cappedStack = insertedStack.copy();
|
||||
cappedStack.setCount(Math.min(insertedStack.getMaxCount(), remainingToInsert));
|
||||
|
||||
ItemStack remaining = insertStackIntoInventory(player.getInventory(), cappedStack.copy(), true);
|
||||
if (!remaining.isEmpty()) {
|
||||
ItemStack reverseStack = displayBlockEntity.targetItem.copy();
|
||||
reverseStack.setCount(remaining.getCount() + remainingToInsert);
|
||||
displayBlockEntity.network.putItemStackRemainder(reverseStack);
|
||||
break;
|
||||
}
|
||||
remainingToInsert -= cappedStack.getCount();
|
||||
}
|
||||
displayBlockEntity.itemCount += remainingToInsert;
|
||||
displayBlockEntity.itemElement.setItem(displayBlockEntity.targetItem);
|
||||
displayBlockEntity.textDisplayElement.setText(Text.of(String.valueOf(displayBlockEntity.itemCount)));
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
private static ActionResult onUse(PlayerEntity plr, World world, Hand hand, BlockHitResult hitResult) {
|
||||
BlockPos pos = hitResult.getBlockPos();
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block instanceof DisplayBlock) {
|
||||
if (!world.isClient && !plr.isSpectator() && plr instanceof ServerPlayerEntity player && hand == Hand.MAIN_HAND) {
|
||||
BlockEntity storageBlockEntity = world.getBlockEntity(pos);
|
||||
if (storageBlockEntity instanceof DisplayBlockEntity displayBlockEntity) {
|
||||
displayBlockEntity.reindexDrives();
|
||||
displayBlockEntity.itemCount = 0;
|
||||
for (Map.Entry<ItemStack, Integer> entry : displayBlockEntity.network.itemStackMap.entrySet()) {
|
||||
ItemStack key = entry.getKey();
|
||||
Integer value = entry.getValue();
|
||||
if (ItemStack.areItemsAndComponentsEqual(key, displayBlockEntity.targetItem)) {
|
||||
displayBlockEntity.itemCount = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
if (stack.isEmpty() && !player.isSneaking()) {
|
||||
DisplayBlockMangementScreen displayBlockMangementScreen = new DisplayBlockMangementScreen(player, displayBlockEntity);
|
||||
displayBlockMangementScreen.updateDisplay();
|
||||
displayBlockMangementScreen.open();
|
||||
} else {
|
||||
ItemStack stack1;
|
||||
boolean wasEmpty = false;
|
||||
if (!stack.isEmpty()) {
|
||||
stack1 = stack.copy();
|
||||
} else {
|
||||
stack1 = displayBlockEntity.targetItem.copy();
|
||||
wasEmpty = true;
|
||||
}
|
||||
int canPutInTemp = 0;
|
||||
if (wasEmpty) {
|
||||
for (int i = 9; i < 45; i++) {
|
||||
ItemStack stack2 = player.getInventory().getStack(i);
|
||||
if (!ItemStack.areItemsAndComponentsEqual(stack1, stack2)) {
|
||||
continue;
|
||||
}
|
||||
stack1.setCount(player.isSneaking() ? (stack1.getCount() == 0 ? stack1.getMaxCount() : stack1.getCount()) : 1);
|
||||
int canPutIn = stack1.getCount() - displayBlockEntity.network.putItemStackRemainder(stack1);
|
||||
if (canPutIn > 0) {
|
||||
removeFromInventory(player.getInventory(), stack2, canPutIn);
|
||||
}
|
||||
canPutInTemp += canPutIn;
|
||||
}
|
||||
} else {
|
||||
if (ItemStack.areItemsAndComponentsEqual(stack1, stack)) {
|
||||
stack1.setCount(player.isSneaking() ? (stack1.getCount() == 0 ? stack1.getMaxCount() : stack1.getCount()) : 1);
|
||||
int canPutIn = stack1.getCount() - displayBlockEntity.network.putItemStackRemainder(stack1);
|
||||
if (canPutIn > 0) {
|
||||
removeFromInventory(player.getInventory(), stack, canPutIn);
|
||||
}
|
||||
canPutInTemp += canPutIn;
|
||||
}
|
||||
}
|
||||
displayBlockEntity.itemElement.setItem(displayBlockEntity.targetItem);
|
||||
displayBlockEntity.itemCount += canPutInTemp;
|
||||
displayBlockEntity.textDisplayElement.setText(Text.of(String.valueOf(displayBlockEntity.itemCount)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new DisplayBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
|
||||
// Make sure to check world.isClient if you only want to tick only on serverside.
|
||||
return world instanceof ServerWorld && type == DISPLAY_BLOCK_ENTITY ? DisplayBlockEntity::tick : null;
|
||||
}
|
||||
}
|
@@ -1,20 +1,20 @@
|
||||
package systems.brn.serverstorage.blocks;
|
||||
|
||||
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 net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
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.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -25,26 +25,30 @@ import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.serverstorage.blockentities.HardDriveContainerBlockEntity;
|
||||
import systems.brn.serverstorage.lib.SortMode;
|
||||
import systems.brn.serverstorage.lib.StorageNetwork;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.*;
|
||||
|
||||
public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
|
||||
final Identifier identifier;
|
||||
public static final DirectionProperty FACING = FacingBlock.FACING;
|
||||
private final BlockState polymerBlockState;
|
||||
public static final EnumProperty<Direction> FACING = FacingBlock.FACING;
|
||||
private final HashMap<Direction, BlockState> rotations;
|
||||
|
||||
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())));
|
||||
this.rotations = generateRotations(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
||||
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,14 +58,15 @@ public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTe
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return this.polymerBlockState;
|
||||
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
|
||||
Direction direction = state.get(FACING);
|
||||
return rotations.get(direction);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = id(HARD_DRIVE_CONTAINER_BLOCK_MODEL_ID);
|
||||
HARD_DRIVE_CONTAINER_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new HardDriveContainerBlock(Settings.copy(Blocks.WHITE_WOOL), modId));
|
||||
new HardDriveContainerBlock(Settings.copy(Blocks.WHITE_WOOL).registryKey(RegistryKey.of(RegistryKeys.BLOCK, modId)), modId));
|
||||
UseBlockCallback.EVENT.register(HardDriveContainerBlock::onUse);
|
||||
|
||||
HARD_DRIVE_CONTAINER_BLOCK.setDefaultState();
|
||||
@@ -69,7 +74,7 @@ public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTe
|
||||
HARD_DRIVE_CONTAINER_BLOCK_ENTITY = Registry.register(
|
||||
Registries.BLOCK_ENTITY_TYPE,
|
||||
modId,
|
||||
BlockEntityType.Builder.create(HardDriveContainerBlockEntity::new, HARD_DRIVE_CONTAINER_BLOCK).build(null)
|
||||
FabricBlockEntityTypeBuilder.create(HardDriveContainerBlockEntity::new, HARD_DRIVE_CONTAINER_BLOCK).build(null)
|
||||
);
|
||||
PolymerBlockUtils.registerBlockEntity(HARD_DRIVE_CONTAINER_BLOCK_ENTITY);
|
||||
}
|
||||
@@ -85,7 +90,7 @@ public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTe
|
||||
BlockEntity storageBlockEntity = world.getBlockEntity(pos);
|
||||
if (storageBlockEntity instanceof HardDriveContainerBlockEntity driveContainerBlockEntity) {
|
||||
if (driveContainerBlockEntity.network == null){
|
||||
driveContainerBlockEntity.network = new StorageNetwork(world, pos, false, "");
|
||||
driveContainerBlockEntity.network = new StorageNetwork(world, pos, SortMode.NUMERICALLY_REVERSE, "", false);
|
||||
}
|
||||
player.openHandledScreen(driveContainerBlockEntity);
|
||||
}
|
||||
@@ -106,8 +111,8 @@ public class HardDriveContainerBlock extends ConnectedBlock implements PolymerTe
|
||||
}
|
||||
|
||||
@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);
|
||||
protected void onStateReplaced(BlockState state, ServerWorld world, BlockPos pos, boolean moved) {
|
||||
ItemScatterer.onStateReplaced(state, world, pos);
|
||||
super.onStateReplaced(state, world, pos, moved);
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,10 @@
|
||||
package systems.brn.serverstorage.blocks;
|
||||
|
||||
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.sgui.api.elements.GuiElementBuilder;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
@@ -16,10 +14,12 @@ import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
@@ -34,25 +34,28 @@ import systems.brn.serverstorage.blockentities.InventoryInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.lib.PagedGui;
|
||||
import systems.brn.serverstorage.screens.SearchScreen;
|
||||
import systems.brn.serverstorage.screens.SettingsScreen;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.*;
|
||||
import static systems.brn.serverstorage.lib.PagedGui.*;
|
||||
|
||||
public class InventoryInterfaceBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
final Identifier identifier;
|
||||
public static final DirectionProperty FACING = FacingBlock.FACING;
|
||||
private final BlockState polymerBlockState;
|
||||
public static final EnumProperty<Direction> FACING = FacingBlock.FACING;
|
||||
private final HashMap<Direction, BlockState> rotations;
|
||||
|
||||
public InventoryInterfaceBlock(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())));
|
||||
this.rotations = generateRotations(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
||||
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,21 +65,23 @@ public class InventoryInterfaceBlock extends ConnectedBlock implements PolymerTe
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return this.polymerBlockState;
|
||||
public BlockState getPolymerBlockState(BlockState state, PacketContext packetContext) {
|
||||
Direction direction = state.get(FACING);
|
||||
return rotations.get(direction);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = id(INVENTORY_INTERFACE_BLOCK_MODEL_ID);
|
||||
INVENTORY_INTERFACE_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new InventoryInterfaceBlock(Settings.copy(Blocks.WHITE_WOOL), modId));
|
||||
new InventoryInterfaceBlock(Settings.copy(Blocks.WHITE_WOOL).registryKey(RegistryKey.of(RegistryKeys.BLOCK, modId)), modId));
|
||||
UseBlockCallback.EVENT.register(InventoryInterfaceBlock::onUse);
|
||||
INVENTORY_INTERFACE_BLOCK.setDefaultState();
|
||||
INVENTORY_INTERFACE_BLOCK_ENTITY = Registry.register(
|
||||
Registries.BLOCK_ENTITY_TYPE,
|
||||
modId,
|
||||
BlockEntityType.Builder.create(InventoryInterfaceBlockEntity::new, INVENTORY_INTERFACE_BLOCK).build(null)
|
||||
FabricBlockEntityTypeBuilder.create(InventoryInterfaceBlockEntity::new, INVENTORY_INTERFACE_BLOCK).build(null)
|
||||
);
|
||||
INVENTORY_INTERFACE_BLOCK_ENTITY.addSupportedBlock(INVENTORY_INTERFACE_BLOCK);
|
||||
PolymerBlockUtils.registerBlockEntity(INVENTORY_INTERFACE_BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
@@ -150,7 +155,7 @@ public class InventoryInterfaceBlock extends ConnectedBlock implements PolymerTe
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block instanceof InventoryInterfaceBlock) {
|
||||
if (!world.getGameRules().getBoolean(ServerStorage_Interface_Enable)){
|
||||
if (!((ServerWorld) world).getGameRules().getBoolean(ServerStorage_Interface_Enable)) {
|
||||
playerEntity.sendMessage(Text.translatable("message.serverstorage.block_disabled"), true);
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
@@ -0,0 +1,156 @@
|
||||
package systems.brn.serverstorage.blocks;
|
||||
|
||||
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
|
||||
import eu.pb4.polymer.core.api.block.PolymerBlockUtils;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
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.serverstorage.blockentities.RadioInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.items.WirelessTerminalItem;
|
||||
import systems.brn.serverstorage.lib.SessionStorageClass;
|
||||
import systems.brn.serverstorage.lib.WirelessTerminalComponents;
|
||||
import systems.brn.serverstorage.screens.RadioBlockPlayerMangementScreen;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.*;
|
||||
import static systems.brn.serverstorage.lib.Util.removePosition;
|
||||
|
||||
public class RadioInterfaceBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
final Identifier identifier;
|
||||
public static final EnumProperty<Direction> FACING = FacingBlock.FACING;
|
||||
private final HashMap<Direction, BlockState> rotations;
|
||||
|
||||
public RadioInterfaceBlock(Settings settings, Identifier identifier) {
|
||||
super(settings, Blocks.NOTE_BLOCK);
|
||||
this.identifier = identifier;
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
|
||||
this.rotations = generateRotations(identifier);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state, PacketContext packetContext) {
|
||||
Direction direction = state.get(FACING);
|
||||
return rotations.get(direction);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = id(RADIO_INTERFACE_BLOCK_MODEL_ID);
|
||||
RADIO_INTERFACE_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new RadioInterfaceBlock(Settings.copy(Blocks.WHITE_WOOL).registryKey(RegistryKey.of(RegistryKeys.BLOCK, modId)), modId));
|
||||
UseBlockCallback.EVENT.register(RadioInterfaceBlock::onUse);
|
||||
|
||||
RADIO_INTERFACE_BLOCK.setDefaultState();
|
||||
|
||||
RADIO_INTERFACE_BLOCK_ENTITY = Registry.register(
|
||||
Registries.BLOCK_ENTITY_TYPE,
|
||||
modId,
|
||||
FabricBlockEntityTypeBuilder.create(RadioInterfaceBlockEntity::new, RADIO_INTERFACE_BLOCK).build(null)
|
||||
);
|
||||
RADIO_INTERFACE_BLOCK_ENTITY.addSupportedBlock(RADIO_INTERFACE_BLOCK);
|
||||
PolymerBlockUtils.registerBlockEntity(RADIO_INTERFACE_BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
private static ActionResult onUse(PlayerEntity plr, World world, Hand hand, BlockHitResult hitResult) {
|
||||
BlockPos pos = hitResult.getBlockPos();
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block instanceof RadioInterfaceBlock) {
|
||||
if (!world.isClient && !plr.isSpectator() && plr instanceof ServerPlayerEntity player && hand == Hand.MAIN_HAND) {
|
||||
BlockEntity storageBlockEntity = world.getBlockEntity(pos);
|
||||
if (storageBlockEntity instanceof RadioInterfaceBlockEntity radioInterfaceBlockEntity) {
|
||||
if (!player.isSneaking()) {
|
||||
RadioBlockPlayerMangementScreen radioBlockPlayerMangementScreen = new RadioBlockPlayerMangementScreen(player, radioInterfaceBlockEntity);
|
||||
radioBlockPlayerMangementScreen.updateDisplay();
|
||||
radioBlockPlayerMangementScreen.open();
|
||||
} else {
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
Item item = stack.getItem();
|
||||
if (item == WIRELESS_TERMINAL) {
|
||||
WirelessTerminalItem.ensureUUID(stack, player.getServer());
|
||||
UUID wirelessTerminalSession = stack.getOrDefault(WirelessTerminalComponents.SESSION_KEY, null);
|
||||
List<SessionStorageClass> wirelessTerminalSessions = new ArrayList<>(stack.getOrDefault(WirelessTerminalComponents.SESSIONS, new ArrayList<>()));
|
||||
if (wirelessTerminalSession != null) {
|
||||
if (radioInterfaceBlockEntity.isSessionAuthorized(wirelessTerminalSession, player.getUuid())) {
|
||||
radioInterfaceBlockEntity.deAuthorizeSession(wirelessTerminalSession, player.getUuid());
|
||||
removePosition(pos, stack);
|
||||
} else {
|
||||
radioInterfaceBlockEntity.authorizeSession(wirelessTerminalSession, player);
|
||||
SessionStorageClass sessionStorageClass = null;
|
||||
for (SessionStorageClass sessionStorageClassLoop : wirelessTerminalSessions) {
|
||||
if (sessionStorageClassLoop.getTerminalPos().equals(pos)) {
|
||||
sessionStorageClass = sessionStorageClassLoop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sessionStorageClass == null || !sessionStorageClass.getPlayerUUID().equals(player.getUuid())) {
|
||||
sessionStorageClass = new SessionStorageClass(player.getUuid(), player.getWorld(), pos);
|
||||
wirelessTerminalSessions.add(sessionStorageClass);
|
||||
}
|
||||
stack.set(WirelessTerminalComponents.SESSIONS, wirelessTerminalSessions);
|
||||
}
|
||||
}
|
||||
WirelessTerminalItem.updateLore(stack, player.getServer());
|
||||
player.setStackInHand(hand, stack);
|
||||
} else {
|
||||
player.openHandledScreen(radioInterfaceBlockEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new RadioInterfaceBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStateReplaced(BlockState state, ServerWorld world, BlockPos pos, boolean moved) {
|
||||
ItemScatterer.onStateReplaced(state, world, pos);
|
||||
super.onStateReplaced(state, world, pos, moved);
|
||||
}
|
||||
}
|
@@ -1,14 +1,11 @@
|
||||
package systems.brn.serverstorage.blocks;
|
||||
|
||||
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 net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
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;
|
||||
@@ -17,9 +14,12 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.text.RawFilteredPair;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@@ -32,7 +32,9 @@ import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.serverstorage.blockentities.StorageInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.screens.StorageScreen;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.*;
|
||||
@@ -40,19 +42,19 @@ import static systems.brn.serverstorage.lib.Util.generateBookContent;
|
||||
|
||||
public class StorageInterfaceBlock extends ConnectedBlock implements PolymerTexturedBlock, BlockEntityProvider {
|
||||
final Identifier identifier;
|
||||
public static final DirectionProperty FACING = FacingBlock.FACING;
|
||||
private final BlockState polymerBlockState;
|
||||
public static final EnumProperty<Direction> FACING = FacingBlock.FACING;
|
||||
private final HashMap<Direction, BlockState> rotations;
|
||||
|
||||
public StorageInterfaceBlock(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())));
|
||||
this.rotations = generateRotations(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
||||
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,21 +64,23 @@ public class StorageInterfaceBlock extends ConnectedBlock implements PolymerText
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return this.polymerBlockState;
|
||||
public BlockState getPolymerBlockState(BlockState state, PacketContext packetContext) {
|
||||
Direction direction = state.get(FACING);
|
||||
return rotations.get(direction);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
var modId = id(STORAGE_MODEL_ID);
|
||||
STORAGE_INTERFACE_BLOCK = Registry.register(Registries.BLOCK, modId,
|
||||
new StorageInterfaceBlock(AbstractBlock.Settings.copy(Blocks.WHITE_WOOL), modId));
|
||||
new StorageInterfaceBlock(AbstractBlock.Settings.copy(Blocks.WHITE_WOOL).registryKey(RegistryKey.of(RegistryKeys.BLOCK, modId)), modId));
|
||||
UseBlockCallback.EVENT.register(StorageInterfaceBlock::onUse);
|
||||
STORAGE_INTERFACE_BLOCK.setDefaultState();
|
||||
STORAGE_INTERFACE_BLOCK_ENTITY = Registry.register(
|
||||
Registries.BLOCK_ENTITY_TYPE,
|
||||
modId,
|
||||
BlockEntityType.Builder.create(StorageInterfaceBlockEntity::new, STORAGE_INTERFACE_BLOCK).build(null)
|
||||
FabricBlockEntityTypeBuilder.create(StorageInterfaceBlockEntity::new, STORAGE_INTERFACE_BLOCK).build(null)
|
||||
);
|
||||
STORAGE_INTERFACE_BLOCK_ENTITY.addSupportedBlock(STORAGE_INTERFACE_BLOCK);
|
||||
PolymerBlockUtils.registerBlockEntity(STORAGE_INTERFACE_BLOCK_ENTITY);
|
||||
}
|
||||
|
||||
@@ -86,7 +90,7 @@ public class StorageInterfaceBlock extends ConnectedBlock implements PolymerText
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block instanceof StorageInterfaceBlock) {
|
||||
if (!world.getGameRules().getBoolean(ServerStorage_Terminal_Enable)){
|
||||
if (!((ServerWorld) world).getGameRules().getBoolean(ServerStorage_Terminal_Enable)){
|
||||
player.sendMessage(Text.translatable("message.serverstorage.block_disabled"), true);
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
@@ -52,6 +52,10 @@ public class HardDrive {
|
||||
tier = 3;
|
||||
maxItems = 131072;
|
||||
break;
|
||||
case "creative_drive":
|
||||
tier = 4;
|
||||
maxItems = Integer.MAX_VALUE;
|
||||
break;
|
||||
default:
|
||||
tier = -1;
|
||||
maxItems = 0;
|
||||
|
@@ -5,6 +5,8 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
import systems.brn.serverstorage.lib.DriveComponents;
|
||||
|
||||
@@ -25,7 +27,7 @@ public class HardDriveItem extends SimpleItem {
|
||||
Identifier identifier = id(tier + "_drive");
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleItem(new Settings()
|
||||
.maxCount(1)
|
||||
.component(DriveComponents.ITEMSTACK_MAP, new HashMap<>())
|
||||
.component(DriveComponents.ITEMSTACK_MAP, new HashMap<>()).registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier))
|
||||
, identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
items.add(item);
|
||||
|
@@ -2,8 +2,6 @@ package systems.brn.serverstorage.items;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerBlockItem;
|
||||
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.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -12,33 +10,34 @@ 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.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.id;
|
||||
|
||||
public class SimpleBlockItem extends PolymerBlockItem implements PolymerItem {
|
||||
private final PolymerModelData polymerModel;
|
||||
private final Identifier polymerModel;
|
||||
|
||||
public SimpleBlockItem(Item.Settings settings, Block block, Identifier identifier) {
|
||||
super(block, settings, Items.BARRIER);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier.withPath("item/" + identifier.getPath()));
|
||||
this.polymerModel = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return this.polymerModel.item();
|
||||
public Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||
return this.polymerModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return this.polymerModel.value();
|
||||
public Item getPolymerItem(ItemStack itemStack, PacketContext player) {
|
||||
return Items.BARRIER;
|
||||
}
|
||||
|
||||
public static void register(Block block) {
|
||||
Identifier identifier = id(block.getRegistryEntry().registryKey().getValue().getPath());
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleBlockItem(new Item.Settings(), block, identifier));
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleBlockItem(new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)), block, identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
}
|
||||
}
|
||||
|
@@ -2,16 +2,17 @@ package systems.brn.serverstorage.items;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||
import eu.pb4.polymer.core.api.item.SimplePolymerItem;
|
||||
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.*;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -19,21 +20,21 @@ import java.util.List;
|
||||
import static systems.brn.serverstorage.ServerStorage.id;
|
||||
|
||||
public class SimpleItem extends SimplePolymerItem implements PolymerItem {
|
||||
private final PolymerModelData polymerModel;
|
||||
private final Identifier polymerModel;
|
||||
|
||||
public SimpleItem(Settings settings, Identifier identifier) {
|
||||
super(settings, Items.BARRIER);
|
||||
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier.withPath("item/" + identifier.getPath()));
|
||||
super(settings, Items.STICK);
|
||||
this.polymerModel = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return this.polymerModel.item();
|
||||
public Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||
return this.polymerModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
|
||||
return this.polymerModel.value();
|
||||
public Item getPolymerItem(ItemStack itemStack, PacketContext player) {
|
||||
return Items.STICK;
|
||||
}
|
||||
|
||||
public static Item register(String name, RegistryKey<ItemGroup> group){
|
||||
@@ -42,7 +43,7 @@ public class SimpleItem extends SimplePolymerItem implements PolymerItem {
|
||||
|
||||
public static Item register(String name, int maxCount, RegistryKey<ItemGroup> group) {
|
||||
Identifier identifier = id(name);
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleItem(new Settings().maxCount(maxCount), identifier));
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleItem(new Settings().maxCount(maxCount).registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier)), identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(group).register(content -> content.add(item));
|
||||
return item;
|
||||
}
|
||||
|
@@ -0,0 +1,255 @@
|
||||
package systems.brn.serverstorage.items;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.LoreComponent;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import systems.brn.serverstorage.blockentities.RadioInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.lib.*;
|
||||
import systems.brn.serverstorage.screens.StorageScreen;
|
||||
import systems.brn.serverstorage.screens.WirelessTerminalSelectorScreen;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.*;
|
||||
|
||||
public class WirelessTerminalItem extends SimpleItem {
|
||||
public WirelessTerminalItem(Settings settings, Identifier identifier) {
|
||||
super(settings, identifier);
|
||||
}
|
||||
|
||||
public static Item register() {
|
||||
Identifier identifier = id(WIRELESS_TERMINAL_ID);
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new SimpleItem(
|
||||
new Settings()
|
||||
.maxCount(1)
|
||||
.component(WirelessTerminalComponents.SESSION_KEY, null)
|
||||
.component(WirelessTerminalComponents.SESSIONS, new ArrayList<>())
|
||||
.component(WirelessTerminalComponents.SELECTED_POSITION, -1)
|
||||
.component(WirelessTerminalComponents.SORT_MODE, SortMode.NUMERICALLY_REVERSE)
|
||||
.component(WirelessTerminalComponents.GROUP_SIMILAR, false)
|
||||
.component(WirelessTerminalComponents.QUERY_STRING, "")
|
||||
.component(WirelessTerminalComponents.PAGE, 0)
|
||||
.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier))
|
||||
, identifier));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
return item;
|
||||
}
|
||||
|
||||
public static RadioInterfaceBlockEntity getRadioInterface(BlockPos pos, ServerWorld world) {
|
||||
if (world.getBlockState(pos).getBlock() == RADIO_INTERFACE_BLOCK && world.getBlockEntity(pos) instanceof RadioInterfaceBlockEntity radioInterfaceBlockEntity) {
|
||||
return radioInterfaceBlockEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RadioDistance getDistance(ServerPlayerEntity player, RadioInterfaceBlockEntity radioInterfaceBlockEntity) {
|
||||
Vec3d playerTempPos = player.getPos();
|
||||
BlockPos playerPos = player.getBlockPos();
|
||||
BlockPos pos = radioInterfaceBlockEntity.getPos();
|
||||
ServerWorld playerWorld = player.getWorld();
|
||||
ServerWorld terminalWorld = playerWorld;
|
||||
int finalDistance = 0;
|
||||
int actualDistance = 0;
|
||||
if (radioInterfaceBlockEntity.getWorld() instanceof ServerWorld terminalWorldTemp) {
|
||||
terminalWorld = terminalWorldTemp;
|
||||
if (playerWorld.getRegistryKey() != terminalWorld.getRegistryKey()) {
|
||||
int playerWorldScale = (int) playerWorld.getDimension().coordinateScale();
|
||||
int terminalWorldScale = (int) terminalWorld.getDimension().coordinateScale();
|
||||
playerTempPos = new Vec3d(playerTempPos.getX() * playerWorldScale, playerTempPos.getY(), playerTempPos.getZ() * terminalWorldScale);
|
||||
playerTempPos = new Vec3d(playerTempPos.getX() / terminalWorldScale, playerTempPos.getY(), playerTempPos.getZ() / terminalWorldScale);
|
||||
}
|
||||
playerPos = BlockPos.ofFloored(playerTempPos);
|
||||
finalDistance = Math.max(radioInterfaceBlockEntity.antennaRange, 1);
|
||||
actualDistance = (int) Math.sqrt(playerPos.getSquaredDistance(pos));
|
||||
}
|
||||
return new RadioDistance(radioInterfaceBlockEntity, finalDistance, actualDistance, playerPos, pos, playerWorld, terminalWorld);
|
||||
}
|
||||
|
||||
public static boolean openTerminal(BlockPos pos, ServerPlayerEntity player, ItemStack stack, ServerWorld world) {
|
||||
|
||||
ServerWorld playerWorld = player.getWorld();
|
||||
String playerWorldName = playerWorld.getRegistryKey().getValue().toString();
|
||||
String terminalWorldName = world.getRegistryKey().getValue().toString();
|
||||
if (stack.getItem() == WIRELESS_TERMINAL) {
|
||||
RadioInterfaceBlockEntity radioInterfaceBlockEntity = WirelessTerminalItem.getRadioInterface(pos, world);
|
||||
if (radioInterfaceBlockEntity != null) {
|
||||
RadioDistance radioDistance = getDistance(player, radioInterfaceBlockEntity);
|
||||
if (radioInterfaceBlockEntity.antennaRange < 0 || (radioInterfaceBlockEntity.antennaRange > 0 && radioDistance.actualDistance() <= radioDistance.finalDistance())) {
|
||||
player.sendMessage(Text.translatable("gui.serverstorage.radio_connected", pos.toShortString(), terminalWorldName, radioDistance.playerPos().toShortString(), playerWorldName, radioDistance.actualDistance(), radioDistance.finalDistance()), true);
|
||||
UUID wirelessTerminalSession = stack.getOrDefault(WirelessTerminalComponents.SESSION_KEY, null);
|
||||
if (radioInterfaceBlockEntity.isSessionAuthorized(wirelessTerminalSession, player.getUuid())) {
|
||||
SortMode sortMode = stack.getOrDefault(WirelessTerminalComponents.SORT_MODE, SortMode.NUMERICALLY_REVERSE);
|
||||
boolean groupSimilar = stack.getOrDefault(WirelessTerminalComponents.GROUP_SIMILAR, false);
|
||||
String searchQuery = stack.getOrDefault(WirelessTerminalComponents.QUERY_STRING, "");
|
||||
StorageNetwork storageNetwork = new StorageNetwork(world, pos, sortMode, searchQuery, groupSimilar);
|
||||
StorageScreen storageScreen = new StorageScreen(player, stack, storageNetwork, radioInterfaceBlockEntity);
|
||||
storageScreen.updateDisplay();
|
||||
storageScreen.open();
|
||||
} else {
|
||||
player.sendMessage(Text.translatable("gui.serverstorage.radio_unauthorized", pos.toShortString(), terminalWorldName), true);
|
||||
player.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_BASS.value(), SoundCategory.PLAYERS, 1f, 1f);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(Text.translatable("gui.serverstorage.radio_out_of_range", pos.toShortString(), terminalWorldName, radioDistance.playerPos().toShortString(), playerWorldName, radioDistance.actualDistance(), radioDistance.finalDistance()), true);
|
||||
player.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_COW_BELL.value(), SoundCategory.PLAYERS, 1f, 1f);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(Text.translatable("gui.serverstorage.radio_not_found", pos.toShortString(), terminalWorldName, player.getBlockPos().toShortString(), playerWorldName), true);
|
||||
player.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_SNARE.value(), SoundCategory.PLAYERS, 1f, 1f);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void setSelectedPosition(ItemStack stack, List<SessionStorageClass> sessions) {
|
||||
int selectedIndex = stack.getOrDefault(WirelessTerminalComponents.SELECTED_POSITION, -1);
|
||||
if (selectedIndex >= sessions.size()) {
|
||||
selectedIndex = sessions.size() - 1;
|
||||
}
|
||||
stack.set(WirelessTerminalComponents.SELECTED_POSITION, selectedIndex);
|
||||
}
|
||||
|
||||
public static void removePosition(BlockPos pos, ItemStack stack) {
|
||||
List<SessionStorageClass> sessions = Util.removePosition(pos, stack);
|
||||
setSelectedPosition(stack, sessions);
|
||||
}
|
||||
|
||||
public static void ensureUUID(ItemStack stack, MinecraftServer server) {
|
||||
UUID wirelessTerminalSession = stack.getOrDefault(WirelessTerminalComponents.SESSION_KEY, null);
|
||||
if (wirelessTerminalSession == null) {
|
||||
stack.set(WirelessTerminalComponents.SESSION_KEY, UUID.randomUUID());
|
||||
updateLore(stack, server);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateLore(ItemStack stack, MinecraftServer server) {
|
||||
UUID wirelessTerminalSessionKey = stack.getOrDefault(WirelessTerminalComponents.SESSION_KEY, null);
|
||||
List<SessionStorageClass> sessions = new ArrayList<>(stack.getOrDefault(WirelessTerminalComponents.SESSIONS, new ArrayList<>()));
|
||||
int selectedPositionIndex = stack.getOrDefault(WirelessTerminalComponents.SELECTED_POSITION, -1);
|
||||
Text radioPlacedAt = Text.translatable("gui.serverstorage.radio_position_error");
|
||||
Text ownedBy = Text.translatable("gui.serverstorage.player_management_session_owner_error");
|
||||
if (selectedPositionIndex >= 0 && !sessions.isEmpty()) {
|
||||
SessionStorageClass session = sessions.get(selectedPositionIndex);
|
||||
BlockPos pos = session.getTerminalPos();
|
||||
radioPlacedAt = Text.translatable("gui.serverstorage.radio_position", pos.toShortString(), session.getWorldKey().getValue().getPath());
|
||||
GameProfile owner = session.getPlayerProfile(server);
|
||||
String ownerName = owner != null ? owner.getName() : "No one";
|
||||
ownedBy = Text.translatable("gui.serverstorage.player_management_session_owner", ownerName);
|
||||
}
|
||||
int page = stack.getOrDefault(WirelessTerminalComponents.PAGE, 0);
|
||||
SortMode sortMode = stack.getOrDefault(WirelessTerminalComponents.SORT_MODE, SortMode.NUMERICALLY_REVERSE);
|
||||
boolean groupSimilar = stack.getOrDefault(WirelessTerminalComponents.GROUP_SIMILAR, false);
|
||||
String searchQuery = stack.getOrDefault(WirelessTerminalComponents.QUERY_STRING, "*");
|
||||
if (selectedPositionIndex < 0 && !sessions.isEmpty()) {
|
||||
selectedPositionIndex = sessions.size() - 1;
|
||||
stack.set(WirelessTerminalComponents.SELECTED_POSITION, selectedPositionIndex);
|
||||
}
|
||||
stack.set(DataComponentTypes.LORE, new LoreComponent(List.of(
|
||||
Text.translatable("gui.serverstorage.player_management_session_key", wirelessTerminalSessionKey == null ? "Missing UUID" : wirelessTerminalSessionKey.toString()),
|
||||
Text.translatable("gui.serverstorage.wireless_terminal_link_count", sessions.size()),
|
||||
ownedBy,
|
||||
Text.translatable("gui.serverstorage.wireless_terminal_link_index", selectedPositionIndex),
|
||||
Text.translatable("gui.serverstorage.wireless_terminal_page", page),
|
||||
Text.translatable("gui.serverstorage.wireless_terminal_search_query", searchQuery),
|
||||
sortMode.getSortingText(),
|
||||
Text.translatable(groupSimilar ? "gui.serverstorage.group_similar" : "gui.serverstorage.dont_group_similar"),
|
||||
radioPlacedAt
|
||||
)));
|
||||
}
|
||||
|
||||
public static boolean stackMatches(ItemStack stack, ItemStack stack2) {
|
||||
UUID stack1UUID = stack.getOrDefault(WirelessTerminalComponents.SESSION_KEY, null);
|
||||
UUID stack2UUID = stack2.getOrDefault(WirelessTerminalComponents.SESSION_KEY, null);
|
||||
return stack.getItem() == WIRELESS_TERMINAL && stack2.getItem() == WIRELESS_TERMINAL && stack1UUID != null && stack1UUID.equals(stack2UUID);
|
||||
}
|
||||
|
||||
public static void saveStack(ItemStack changedStack, ItemStack originalStack, ServerPlayerEntity player) {
|
||||
ItemStack stackInMainHand = player.getMainHandStack();
|
||||
ItemStack stackInOffHand = player.getOffHandStack();
|
||||
if (stackMatches(originalStack, stackInMainHand)) {
|
||||
player.setStackInHand(Hand.MAIN_HAND, changedStack);
|
||||
} else if (stackMatches(originalStack, stackInOffHand)) {
|
||||
player.setStackInHand(Hand.OFF_HAND, changedStack);
|
||||
} else {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
for (int i = 0; i < playerInventory.size(); i++) {
|
||||
ItemStack stackInSlot = playerInventory.getStack(i);
|
||||
if (stackMatches(stackInSlot, stackInMainHand)) {
|
||||
playerInventory.setStack(i, changedStack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean useItem(ServerWorld world, ServerPlayerEntity playerEntity, ItemStack stack) {
|
||||
MinecraftServer server = world.getServer();
|
||||
ensureUUID(stack, server);
|
||||
updateLore(stack, server);
|
||||
if (!playerEntity.isSneaking()) {
|
||||
List<SessionStorageClass> wirelessTerminalPositions = new ArrayList<>(stack.getOrDefault(WirelessTerminalComponents.SESSIONS, new ArrayList<>()));
|
||||
int selectedPosition = stack.getOrDefault(WirelessTerminalComponents.SELECTED_POSITION, -1);
|
||||
|
||||
if (selectedPosition < 0 && !wirelessTerminalPositions.isEmpty()) {
|
||||
selectedPosition = wirelessTerminalPositions.size() - 1;
|
||||
stack.set(WirelessTerminalComponents.SELECTED_POSITION, selectedPosition);
|
||||
saveStack(stack, stack, playerEntity);
|
||||
}
|
||||
|
||||
if (wirelessTerminalPositions.isEmpty()) {
|
||||
stack.remove(WirelessTerminalComponents.SELECTED_POSITION);
|
||||
saveStack(stack, stack, playerEntity);
|
||||
selectedPosition = -1;
|
||||
}
|
||||
|
||||
if (selectedPosition < 0) {
|
||||
WirelessTerminalSelectorScreen wirelessTerminalSelectorScreen = new WirelessTerminalSelectorScreen(playerEntity, null);
|
||||
wirelessTerminalSelectorScreen.open();
|
||||
return false;
|
||||
}
|
||||
|
||||
SessionStorageClass sessionStorageClass = wirelessTerminalPositions.get(selectedPosition);
|
||||
BlockPos selectedPos = sessionStorageClass.getTerminalPos();
|
||||
|
||||
if (sessionStorageClass.getPlayerUUID().equals(playerEntity.getUuid()) && sessionStorageClass.getWorld(server).getBlockEntity(selectedPos) instanceof RadioInterfaceBlockEntity) {
|
||||
boolean success = openTerminal(selectedPos, playerEntity, stack, sessionStorageClass.getWorld(server));
|
||||
if (!success) {
|
||||
removePosition(selectedPos, stack);
|
||||
saveStack(stack, stack, playerEntity);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
removePosition(selectedPos, stack);
|
||||
saveStack(stack, stack, playerEntity);
|
||||
playerEntity.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_BASS.value(), SoundCategory.PLAYERS, 1f, 1f);
|
||||
WirelessTerminalSelectorScreen wirelessTerminalSelectorScreen = new WirelessTerminalSelectorScreen(playerEntity, null);
|
||||
wirelessTerminalSelectorScreen.open();
|
||||
}
|
||||
} else {
|
||||
WirelessTerminalSelectorScreen wirelessTerminalSelectorScreen = new WirelessTerminalSelectorScreen(playerEntity, null);
|
||||
wirelessTerminalSelectorScreen.open();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
53
src/main/java/systems/brn/serverstorage/lib/Antenna.java
Normal file
53
src/main/java/systems/brn/serverstorage/lib/Antenna.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.LoreComponent;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import systems.brn.serverstorage.items.SimpleItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.ANTENNA_RANGES;
|
||||
import static systems.brn.serverstorage.ServerStorage.id;
|
||||
|
||||
public class Antenna extends SimpleItem {
|
||||
public final int range;
|
||||
|
||||
public Antenna(Settings settings, Identifier identifier, int range) {
|
||||
super(settings.component(DataComponentTypes.LORE,
|
||||
new LoreComponent(List.of(
|
||||
Text.translatable("gui.serverstorage.antenna_range", range)
|
||||
))), identifier);
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
public static List<Item> register(List<String> tiers) {
|
||||
ArrayList<Item> items = new ArrayList<>();
|
||||
int range = 150;
|
||||
for (String tier : tiers) {
|
||||
Identifier identifier = id(tier + "_antenna");
|
||||
Item item = Registry.register(Registries.ITEM, identifier, new Antenna(new Settings()
|
||||
.maxCount(1).registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier))
|
||||
, identifier, range));
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
|
||||
items.add(item);
|
||||
if (Objects.equals(tier, "ender")) {
|
||||
ANTENNA_RANGES.put(item, Integer.MAX_VALUE);
|
||||
} else {
|
||||
ANTENNA_RANGES.put(item, range);
|
||||
}
|
||||
range *= 3;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
24
src/main/java/systems/brn/serverstorage/lib/AntennaSlot.java
Normal file
24
src/main/java/systems/brn/serverstorage/lib/AntennaSlot.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package systems.brn.serverstorage.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.serverstorage.ServerStorage.ANTENNA_LIST;
|
||||
|
||||
public class AntennaSlot extends Slot {
|
||||
public AntennaSlot(Inventory inventory, int index, int x, int y) {
|
||||
super(inventory, index, x, y);
|
||||
}
|
||||
|
||||
public static boolean isAntenna(Item item) {
|
||||
return ANTENNA_LIST.contains(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return isAntenna(stack.getItem());
|
||||
}
|
||||
|
||||
}
|
@@ -1,6 +1,5 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.CraftingRecipe;
|
||||
import net.minecraft.recipe.RecipeEntry;
|
||||
@@ -15,23 +14,30 @@ public class CraftingEntry {
|
||||
public final ArrayList<ItemStack> outputStacks;
|
||||
public final RecipeEntry<CraftingRecipe> recipeEntry;
|
||||
public final ArrayList<RecipeEntry<CraftingRecipe>> myCraftingRecipeEntries;
|
||||
public final int totalMax;
|
||||
public final int eachCraft;
|
||||
public final int maxCrafts;
|
||||
|
||||
public CraftingEntry(ItemStack itemStack, RecipeEntry<CraftingRecipe> recipeEntry, HashMap<ItemStack, Integer> inputs, Integer maxCount) {
|
||||
maxCrafts = maxCount;
|
||||
eachCraft = itemStack.getCount();
|
||||
totalMax = eachCraft * maxCrafts;
|
||||
ArrayList<ItemStack> tempOutputStacks = new ArrayList<>();
|
||||
ItemStack outputStack = itemStack.copy();
|
||||
outputStack.setCount(maxCount);
|
||||
outputStack = addCountToLore(itemStack.getCount() * maxCount, outputStack, "Total max: ");
|
||||
outputStack = addCountToLore(itemStack.getCount(), outputStack, "Each craft: ");
|
||||
outputStack = addCountToLore(maxCount, outputStack, "Max crafts: ");
|
||||
outputStack = addCountToLore(totalMax, outputStack, "Total max: ");
|
||||
outputStack = addCountToLore(eachCraft, outputStack, "Each craft: ");
|
||||
outputStack = addCountToLore(maxCrafts, outputStack, "Max crafts: ");
|
||||
tempOutputStacks.add(outputStack);
|
||||
for (Map.Entry<ItemStack, Integer> entry : inputs.entrySet()) {
|
||||
ItemStack stackIn = entry.getKey();
|
||||
Integer count = entry.getValue();
|
||||
if (count > 0 && stackIn.isEmpty() && stackIn.getItem().hasRecipeRemainder()) {
|
||||
Item remainderItem = stackIn.getItem().getRecipeRemainder();
|
||||
if (remainderItem != null) {
|
||||
ItemStack remainderStack = new ItemStack(stackIn.getItem().getRecipeRemainder(), count);
|
||||
tempOutputStacks.add(remainderStack);
|
||||
if (count > 0 && stackIn.isEmpty() && stackIn.getItem().getRecipeRemainder() != null) {
|
||||
ItemStack remainderStack = stackIn.getItem().getRecipeRemainder();
|
||||
if (!remainderStack.isEmpty()) {
|
||||
ItemStack remainderStackNew = remainderStack.copy();
|
||||
remainderStackNew.setCount(count);
|
||||
tempOutputStacks.add(remainderStackNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,31 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.world.World;
|
||||
import systems.brn.serverstorage.items.WirelessTerminalItem;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.WIRELESS_TERMINAL;
|
||||
|
||||
public class EventHandler {
|
||||
public static ActionResult onItemUse(PlayerEntity playerEntity, World worldTemp, Hand hand) {
|
||||
ItemStack itemStack = playerEntity.getStackInHand(hand);
|
||||
Item item = itemStack.getItem();
|
||||
if (!worldTemp.isClient) {
|
||||
if (playerEntity instanceof ServerPlayerEntity player) {
|
||||
if (worldTemp instanceof ServerWorld world) {
|
||||
if (item == WIRELESS_TERMINAL) {
|
||||
return WirelessTerminalItem.useItem(world, player, itemStack) ? ActionResult.SUCCESS : ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.UserCache;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
//inspired by: https://github.com/Patbox/get-off-my-lawn-reserved/blob/1.21/src/main/java/draylar/goml/ui/GenericPlayerListGui.java
|
||||
public class GenericPlayerListGui extends PagedGui {
|
||||
public final List<UUID> uuids = new ArrayList<>();
|
||||
|
||||
public GenericPlayerListGui(ServerPlayerEntity player, @Nullable Runnable onClose) {
|
||||
super(player, onClose);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return (this.getEntryCount()) / PAGE_SIZE;
|
||||
}
|
||||
|
||||
protected int getEntryCount() {
|
||||
return this.uuids.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement getElement(int id) {
|
||||
return getPlayerElement(id);
|
||||
}
|
||||
|
||||
protected DisplayElement getPlayerElement(int id) {
|
||||
if (this.uuids.size() > id) {
|
||||
return getPlayerElement(this.uuids.get(id));
|
||||
}
|
||||
|
||||
return DisplayElement.empty();
|
||||
}
|
||||
|
||||
protected DisplayElement getPlayerElement(UUID uuid) {
|
||||
MinecraftServer srv = this.player.getServer();
|
||||
if (srv == null) {
|
||||
return DisplayElement.empty();
|
||||
}
|
||||
UserCache userCache = srv.getUserCache();
|
||||
GameProfile gameProfile = null;
|
||||
Optional<GameProfile> gameProfileTemp;
|
||||
boolean exists = false;
|
||||
|
||||
if (userCache != null) {
|
||||
gameProfileTemp = userCache.getByUuid(uuid);
|
||||
exists = gameProfileTemp.isPresent();
|
||||
gameProfile = exists ? gameProfileTemp.get() : null;
|
||||
}
|
||||
|
||||
|
||||
var builder = new GuiElementBuilder(exists ? Items.PLAYER_HEAD : Items.SKELETON_SKULL)
|
||||
.setName(Text.literal(exists ? gameProfile.getName() : "<" + uuid.toString() + ">")
|
||||
.formatted(Formatting.WHITE)
|
||||
);
|
||||
|
||||
if (exists) {
|
||||
builder.setSkullOwner(gameProfile, null);
|
||||
} else {
|
||||
builder.setSkullOwner(PagedGui.GUI_QUESTION_MARK);
|
||||
}
|
||||
|
||||
return DisplayElement.of(builder);
|
||||
}
|
||||
}
|
@@ -16,6 +16,8 @@ public class ItemGroups {
|
||||
entries.add(HARD_DRIVE_CONTAINER_BLOCK);
|
||||
entries.add(BUS_CONNECTOR_BLOCK);
|
||||
entries.add(INVENTORY_INTERFACE_BLOCK);
|
||||
entries.add(RADIO_INTERFACE_BLOCK);
|
||||
entries.add(DISPLAY_BLOCK);
|
||||
}))
|
||||
.build();
|
||||
|
||||
@@ -36,6 +38,10 @@ public class ItemGroups {
|
||||
entries.add(HEADS.get(i));
|
||||
}
|
||||
}
|
||||
for (Item antenna : ANTENNA_LIST) {
|
||||
entries.add(antenna);
|
||||
}
|
||||
entries.add(WIRELESS_TERMINAL);
|
||||
}))
|
||||
.build();
|
||||
|
||||
|
@@ -28,8 +28,18 @@ public abstract class PagedGui extends SimpleGui {
|
||||
public static final String GUI_NEXT_PAGE_BLOCKED = "ewogICJ0aW1lc3RhbXAiIDogMTY0MDYxNjExMDQ4OCwKICAicHJvZmlsZUlkIiA6ICIxZjEyNTNhYTVkYTQ0ZjU5YWU1YWI1NmFhZjRlNTYxNyIsCiAgInByb2ZpbGVOYW1lIiA6ICJOb3RNaUt5IiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzdlNTc3MjBhNDg3OGM4YmNhYjBlOWM5YzQ3ZDllNTUxMjhjY2Q3N2JhMzQ0NWE1NGE5MWUzZTFlMWEyNzM1NmUiLAogICAgICAibWV0YWRhdGEiIDogewogICAgICAgICJtb2RlbCIgOiAic2xpbSIKICAgICAgfQogICAgfQogIH0KfQ==";
|
||||
public static final String GUI_QUESTION_MARK = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmM4ZWExZjUxZjI1M2ZmNTE0MmNhMTFhZTQ1MTkzYTRhZDhjM2FiNWU5YzZlZWM4YmE3YTRmY2I3YmFjNDAifX19";
|
||||
public static final String GUI_REFRESH = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc1ZDNkYjAzZGMyMWU1NjNiMDM0MTk3ZGE0MzViNzllY2ZlZjRiOGUyZWNkYjczMGUzNzBjMzE2NjI5ZDM2ZiJ9fX0=";
|
||||
|
||||
public static final String GUI_A = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGU0MTc0ODEyMTYyNmYyMmFlMTZhNGM2NjRjNzMwMWE5ZjhlYTU5MWJmNGQyOTg4ODk1NzY4MmE5ZmRhZiJ9fX0=";
|
||||
public static final String GUI_1 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2E1MTZmYmFlMTYwNThmMjUxYWVmOWE2OGQzMDc4NTQ5ZjQ4ZjZkNWI2ODNmMTljZjVhMTc0NTIxN2Q3MmNjIn19fQ==";
|
||||
public static final String GUI_Z = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzBkNDRmZWUwMzAzZjZkMzdmYWNhN2U5YzMxNTMwOTU1NmZhM2RmMzc5YmRkNTgyMzE3YWEzNjhhYTg0M2UifX19";
|
||||
public static final String GUI_9 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDZhYmM2MWRjYWVmYmQ1MmQ5Njg5YzA2OTdjMjRjN2VjNGJjMWFmYjU2YjhiMzc1NWU2MTU0YjI0YTVkOGJhIn19fQ==";
|
||||
|
||||
public static final String GUI_A_B = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTdkZDM0OTI0ZDJiNmEyMTNhNWVkNDZhZTU3ODNmOTUzNzNhOWVmNWNlNWM4OGY5ZDczNjcwNTk4M2I5NyJ9fX0=";
|
||||
public static final String GUI_1_B = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDJhNmYwZTg0ZGFlZmM4YjIxYWE5OTQxNWIxNmVkNWZkYWE2ZDhkYzBjM2NkNTkxZjQ5Y2E4MzJiNTc1In19fQ==";
|
||||
public static final String GUI_Z_B = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzk5MmM3NTNiZjljNjI1ODUzY2UyYTBiN2IxNzRiODlhNmVjMjZiYjVjM2NjYjQ3M2I2YTIwMTI0OTYzMTIifX19";
|
||||
public static final String GUI_9_B = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWY3YWEwZDk3OTgzY2Q2N2RmYjY3YjdkOWQ5YzY0MWJjOWFhMzRkOTY2MzJmMzcyZDI2ZmVlMTlmNzFmOGI3In19fQ==";
|
||||
|
||||
|
||||
public static final String GUI_STORE_ALL = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWFkNmM4MWY4OTlhNzg1ZWNmMjZiZTFkYzQ4ZWFlMmJjZmU3NzdhODYyMzkwZjU3ODVlOTViZDgzYmQxNGQifX19";
|
||||
public static final String GUI_SETTINGS = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTRkNDliYWU5NWM3OTBjM2IxZmY1YjJmMDEwNTJhNzE0ZDYxODU0ODFkNWIxYzg1OTMwYjNmOTlkMjMyMTY3NCJ9fX0=";
|
||||
public static final String GUI_CRAFTING = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYWQyYzBjZWRmYzMyZTNiZWVlOTU1Y2FiZDY2ZmQ0ZDc2NWVlZGEzYWRjYzg0YmM0NTFjOWZkYmVjZjNjYjdjMiJ9fX0=";
|
||||
@@ -61,8 +71,12 @@ public abstract class PagedGui extends SimpleGui {
|
||||
}
|
||||
}
|
||||
|
||||
protected void nextPage() {
|
||||
protected void nextPage(boolean allTheWay) {
|
||||
if (allTheWay) {
|
||||
this.page = this.getPageAmount() - 1;
|
||||
} else {
|
||||
this.page = Math.min(this.getPageAmount() - 1, this.page + 1);
|
||||
}
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
@@ -70,8 +84,12 @@ public abstract class PagedGui extends SimpleGui {
|
||||
return this.getPageAmount() > this.page + 1;
|
||||
}
|
||||
|
||||
protected void previousPage() {
|
||||
protected void previousPage(boolean allTheWay) {
|
||||
if (allTheWay) {
|
||||
this.page = 0;
|
||||
} else {
|
||||
this.page = Math.max(0, this.page - 1);
|
||||
}
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
@@ -146,19 +164,19 @@ public abstract class PagedGui extends SimpleGui {
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
protected DisplayElement search(){
|
||||
protected DisplayElement search() {
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
protected DisplayElement sorting(){
|
||||
protected DisplayElement sorting() {
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
protected DisplayElement storeAll(){
|
||||
protected DisplayElement storeAll() {
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
protected DisplayElement settings(){
|
||||
protected DisplayElement settings() {
|
||||
return DisplayElement.filler();
|
||||
}
|
||||
|
||||
@@ -187,18 +205,18 @@ public abstract class PagedGui extends SimpleGui {
|
||||
if (gui.canNextPage()) {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("createWorld.customize.custom.next").formatted(Formatting.WHITE))
|
||||
.setName(Text.translatable("spectatorMenu.next_page").formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_NEXT_PAGE)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(gui.player);
|
||||
gui.nextPage();
|
||||
gui.nextPage(y.shift);
|
||||
})
|
||||
);
|
||||
} else {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("createWorld.customize.custom.next").formatted(Formatting.DARK_GRAY))
|
||||
.setName(Text.translatable("spectatorMenu.next_page").formatted(Formatting.DARK_GRAY))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_NEXT_PAGE_BLOCKED)
|
||||
);
|
||||
@@ -209,18 +227,18 @@ public abstract class PagedGui extends SimpleGui {
|
||||
if (gui.canPreviousPage()) {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("createWorld.customize.custom.prev").formatted(Formatting.WHITE))
|
||||
.setName(Text.translatable("spectatorMenu.previous_page").formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_PREVIOUS_PAGE)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(gui.player);
|
||||
gui.previousPage();
|
||||
gui.previousPage(y.shift);
|
||||
})
|
||||
);
|
||||
} else {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("createWorld.customize.custom.prev").formatted(Formatting.DARK_GRAY))
|
||||
.setName(Text.translatable("spectatorMenu.previous_page").formatted(Formatting.DARK_GRAY))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_PREVIOUS_PAGE_BLOCKED)
|
||||
);
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import systems.brn.serverstorage.blockentities.RadioInterfaceBlockEntity;
|
||||
|
||||
public record RadioDistance(
|
||||
RadioInterfaceBlockEntity radioInterfaceBlockEntity,
|
||||
int finalDistance,
|
||||
int actualDistance,
|
||||
BlockPos playerPos,
|
||||
BlockPos terminalPos,
|
||||
ServerWorld playerWorld,
|
||||
ServerWorld terminalWorld
|
||||
) {
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
public interface Searchable {
|
||||
public void doSearch(String searchText);
|
||||
}
|
43
src/main/java/systems/brn/serverstorage/lib/Session.java
Normal file
43
src/main/java/systems/brn/serverstorage/lib/Session.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.util.Uuids;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static systems.brn.serverstorage.lib.Util.getUUID;
|
||||
import static systems.brn.serverstorage.lib.Util.putUUID;
|
||||
|
||||
public record Session(UUID sessionKey, UUID playerUUID) {
|
||||
|
||||
// Serialize to NBT
|
||||
public NbtCompound toNbt() {
|
||||
NbtCompound nbt = new NbtCompound();
|
||||
putUUID(nbt, "SessionKey", this.sessionKey);
|
||||
putUUID(nbt, "PlayerUUID", this.playerUUID);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
// Deserialize from NBT
|
||||
public static Session fromNbt(NbtCompound nbt) {
|
||||
Optional<UUID> sessionKey = getUUID(nbt, "SessionKey");
|
||||
Optional<UUID> playerUUID = getUUID(nbt, "PlayerUUID");
|
||||
if (sessionKey.isPresent() && playerUUID.isPresent()) {
|
||||
return new Session(sessionKey.get(), playerUUID.get());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final Codec<Session> SESSION_CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
Uuids.CODEC.fieldOf("SessionKey").forGetter(Session::sessionKey),
|
||||
Uuids.CODEC.fieldOf("PlayerUUID").forGetter(Session::playerUUID)
|
||||
).apply(instance, Session::new));
|
||||
|
||||
public static final Codec<List<Session>> SESSION_LIST_CODEC = SESSION_CODEC.listOf();
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static systems.brn.serverstorage.lib.Util.getGameProfile;
|
||||
|
||||
public class SessionStorageClass {
|
||||
private final BlockPos terminalPos;
|
||||
private final UUID playerUUID;
|
||||
private final RegistryKey<World> worldKey;
|
||||
|
||||
public SessionStorageClass(UUID playerUUID, ServerWorld world, BlockPos terminalPos) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.worldKey = world.getRegistryKey();
|
||||
this.terminalPos = terminalPos;
|
||||
}
|
||||
|
||||
public SessionStorageClass(UUID playerUUID, RegistryKey<World> worldKey, BlockPos terminalPos) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.worldKey = worldKey;
|
||||
this.terminalPos = terminalPos;
|
||||
}
|
||||
|
||||
public BlockPos getTerminalPos() {
|
||||
return terminalPos;
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID() {
|
||||
return playerUUID;
|
||||
}
|
||||
|
||||
public GameProfile getPlayerProfile(MinecraftServer server) {
|
||||
return getGameProfile(playerUUID, server);
|
||||
}
|
||||
|
||||
public RegistryKey<World> getWorldKey() {
|
||||
return worldKey;
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(MinecraftServer server) {
|
||||
return server.getWorld(this.worldKey);
|
||||
}
|
||||
}
|
65
src/main/java/systems/brn/serverstorage/lib/SortMode.java
Normal file
65
src/main/java/systems/brn/serverstorage/lib/SortMode.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import static systems.brn.serverstorage.lib.PagedGui.*;
|
||||
|
||||
public enum SortMode {
|
||||
ALPHABETICALLY(0),
|
||||
ALPHABETICALLY_REVERSE(1),
|
||||
NUMERICALLY(2),
|
||||
NUMERICALLY_REVERSE(3);
|
||||
|
||||
private final int id;
|
||||
|
||||
SortMode(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static SortMode fromId(int id) {
|
||||
for (SortMode mode : values()) {
|
||||
if (mode.getId() == id) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown SortMode id: " + id);
|
||||
}
|
||||
|
||||
public SortMode nextSort() {
|
||||
int nextOrdinal = (this.ordinal() + 1) % SortMode.values().length;
|
||||
return SortMode.values()[nextOrdinal];
|
||||
}
|
||||
|
||||
public MutableText getSortingText() {
|
||||
return switch (this) {
|
||||
case ALPHABETICALLY -> Text.translatable("gui.serverstorage.sorting_alphabetically");
|
||||
case ALPHABETICALLY_REVERSE -> Text.translatable("gui.serverstorage.sorting_alphabetically_reversed");
|
||||
case NUMERICALLY -> Text.translatable("gui.serverstorage.sorting_numerically");
|
||||
case NUMERICALLY_REVERSE -> Text.translatable("gui.serverstorage.sorting_numerically_reversed");
|
||||
};
|
||||
}
|
||||
|
||||
public String getSortingIcon(boolean groupSimilar) {
|
||||
if (groupSimilar) {
|
||||
return switch (this) {
|
||||
case ALPHABETICALLY -> GUI_A_B;
|
||||
case ALPHABETICALLY_REVERSE -> GUI_Z_B;
|
||||
case NUMERICALLY -> GUI_1_B;
|
||||
case NUMERICALLY_REVERSE -> GUI_9_B;
|
||||
};
|
||||
}
|
||||
return switch (this) {
|
||||
case ALPHABETICALLY -> GUI_A;
|
||||
case ALPHABETICALLY_REVERSE -> GUI_Z;
|
||||
case NUMERICALLY -> GUI_1;
|
||||
case NUMERICALLY_REVERSE -> GUI_9;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,8 @@ public class StorageNetwork {
|
||||
|
||||
public final World world;
|
||||
public final BlockPos startPos;
|
||||
public boolean sortAlphabetically;
|
||||
public SortMode sortMode;
|
||||
public boolean groupSimilar;
|
||||
public String searchString;
|
||||
|
||||
public int driveContainerCount;
|
||||
@@ -41,11 +42,12 @@ public class StorageNetwork {
|
||||
public int driveUsedSlots;
|
||||
public int driveFreeSlots;
|
||||
|
||||
public StorageNetwork(World world, BlockPos startPos, boolean sortAlphabetically, String searchString) {
|
||||
public StorageNetwork(World world, BlockPos startPos, SortMode sortMode, String searchString, boolean groupSimilar) {
|
||||
this.world = world;
|
||||
this.startPos = startPos;
|
||||
this.sortAlphabetically = sortAlphabetically;
|
||||
this.sortMode = sortMode;
|
||||
this.searchString = searchString;
|
||||
this.groupSimilar = groupSimilar;
|
||||
reindexNetwork();
|
||||
}
|
||||
|
||||
@@ -65,7 +67,7 @@ public class StorageNetwork {
|
||||
|
||||
countStuff();
|
||||
|
||||
filteredItemStackMap = getCombinedMap(sortAlphabetically, searchString);
|
||||
filteredItemStackMap = getCombinedMap(sortMode, searchString, groupSimilar);
|
||||
}
|
||||
|
||||
private void countStuff() {
|
||||
@@ -163,12 +165,12 @@ public class StorageNetwork {
|
||||
}
|
||||
|
||||
// Modify getCombinedInventoryFromChests to include item metadata and combine stacks
|
||||
private TreeMap<ItemStack, Integer> getCombinedMap(boolean sortAlphabetically, String query) {
|
||||
private TreeMap<ItemStack, Integer> getCombinedMap(SortMode sortAlphabetically, String query, boolean groupSimilar) {
|
||||
itemStackMap = new HashMap<>();
|
||||
for (HardDrive drive : drives) {
|
||||
itemStackMap = drive.addToMap(itemStackMap);
|
||||
}
|
||||
return sortAndFilterMap(itemStackMap, sortAlphabetically, query);
|
||||
return sortAndFilterMap(itemStackMap, sortAlphabetically, query, groupSimilar);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -6,21 +6,19 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
public class StorageOperations {
|
||||
// Modify getSimpleInventory to include item metadata and sort conditionally
|
||||
public static TreeMap<ItemStack, Integer> sortAndFilterMap(Map<ItemStack, Integer> itemStackMap, boolean sortAlphabetically, String query) {
|
||||
TreeMap<ItemStack, Integer> sortedMap = getItemStackIntegerTreeMap(itemStackMap, sortAlphabetically);
|
||||
public static TreeMap<ItemStack, Integer> sortAndFilterMap(Map<ItemStack, Integer> itemStackMap, SortMode sortAlphabetically, String query, boolean groupSimilar) {
|
||||
TreeMap<ItemStack, Integer> sortedMap = getItemStackIntegerTreeMap(itemStackMap, sortAlphabetically, groupSimilar);
|
||||
|
||||
if (query == null || query.isEmpty() || query.equals("*")) {
|
||||
sortedMap.putAll(itemStackMap);
|
||||
} else {
|
||||
Map<ItemStack, Integer> filteredMap = new HashMap<>();
|
||||
for (Map.Entry<ItemStack, Integer> entry : itemStackMap.entrySet()) {
|
||||
if (filterItem(entry.getKey().getItem(), query)){
|
||||
if (filterItem(entry.getKey().getItem(), query)) {
|
||||
ItemStack stack = entry.getKey();
|
||||
stack.setCount(Math.min(entry.getValue(), stack.getMaxCount()));
|
||||
filteredMap.put(stack, entry.getValue());
|
||||
@@ -31,7 +29,24 @@ public class StorageOperations {
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
public static boolean filterItem(Item item, String query){
|
||||
public static TreeSet<CraftingEntry> sortAndFilterEntries(ArrayList<CraftingEntry> craftingEntries, SortMode sortAlphabetically, String query) {
|
||||
TreeSet<CraftingEntry> sortedSet = getTreeSetCraftingEntries(sortAlphabetically);
|
||||
|
||||
if (query == null || query.isEmpty() || query.equals("*")) {
|
||||
sortedSet.addAll(craftingEntries);
|
||||
} else {
|
||||
ArrayList<CraftingEntry> filteredSet = new ArrayList<>();
|
||||
for (CraftingEntry entry : craftingEntries) {
|
||||
if (!entry.outputStacks.isEmpty() && filterItem(entry.outputStacks.getFirst().getItem(), query)) {
|
||||
filteredSet.add(entry);
|
||||
}
|
||||
}
|
||||
sortedSet.addAll(filteredSet);
|
||||
}
|
||||
return sortedSet;
|
||||
}
|
||||
|
||||
public static boolean filterItem(Item item, String query) {
|
||||
if (item != null) {
|
||||
String itemName = String.valueOf(item);
|
||||
return itemName == null || itemName.contains(query);
|
||||
@@ -39,29 +54,153 @@ public class StorageOperations {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static @NotNull TreeMap<ItemStack, Integer> getItemStackIntegerTreeMap(Map<ItemStack, Integer> itemStackMap, boolean sortAlphabetically) {
|
||||
private static @NotNull TreeMap<ItemStack, Integer> getItemStackIntegerTreeMap(Map<ItemStack, Integer> itemStackMap, SortMode sortMode, boolean groupSimilar) {
|
||||
TreeMap<ItemStack, Integer> sortedMap;
|
||||
|
||||
if (sortAlphabetically) {
|
||||
switch (sortMode) {
|
||||
case ALPHABETICALLY:
|
||||
// Sort alphabetically by item name
|
||||
sortedMap = new TreeMap<>((o1, o2) -> {
|
||||
String name1 = String.valueOf(o1.getItem());
|
||||
String name2 = String.valueOf(o2.getItem());
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
});
|
||||
} else {
|
||||
sortedMap = new TreeMap<>((o1, o2) -> sortAlpha(groupSimilar, o1, o2));
|
||||
break;
|
||||
|
||||
case ALPHABETICALLY_REVERSE:
|
||||
// Sort alphabetically by item name in reverse order
|
||||
sortedMap = new TreeMap<>((o1, o2) -> sortAlpha(groupSimilar, o2, o1)); // Reverse comparison
|
||||
break;
|
||||
|
||||
case NUMERICALLY:
|
||||
// Sort by count in descending order
|
||||
sortedMap = new TreeMap<>((o1, o2) -> {
|
||||
int count1 = itemStackMap.get(o1);
|
||||
int count2 = itemStackMap.get(o2);
|
||||
int countCompare = Integer.compare(count2, count1);
|
||||
// If counts are equal, compare items alphabetically by name
|
||||
return countCompare == 0 ? String.valueOf(o1.getItem()).compareToIgnoreCase(String.valueOf(o2.getItem())) : countCompare;
|
||||
});
|
||||
if (countCompare != 0) {
|
||||
return countCompare;
|
||||
}
|
||||
return sortAlpha(groupSimilar, o1, o2);
|
||||
});
|
||||
break;
|
||||
|
||||
case NUMERICALLY_REVERSE:
|
||||
// Sort by count in ascending order
|
||||
sortedMap = new TreeMap<>((o1, o2) -> {
|
||||
int count1 = itemStackMap.get(o1);
|
||||
int count2 = itemStackMap.get(o2);
|
||||
int countCompare = Integer.compare(count1, count2); // Reverse comparison
|
||||
// If counts are equal, compare items alphabetically by name
|
||||
if (countCompare != 0) {
|
||||
return countCompare;
|
||||
}
|
||||
return sortAlpha(groupSimilar, o1, o2);
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid sort mode: " + sortMode);
|
||||
}
|
||||
|
||||
// Populate the sorted map with entries from the original map
|
||||
sortedMap.putAll(itemStackMap);
|
||||
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
|
||||
private static int sortAlpha(boolean groupSimilar, ItemStack o1, ItemStack o2) {
|
||||
String name1, name2;
|
||||
if (groupSimilar) {
|
||||
name1 = String.valueOf(o1.getItem());
|
||||
name2 = String.valueOf(o2.getItem());
|
||||
} else {
|
||||
name1 = o1.getItem() + o1.getComponents().toString();
|
||||
name2 = o2.getItem() + o2.getComponents().toString();
|
||||
}
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
}
|
||||
|
||||
private static @NotNull TreeSet<CraftingEntry> getTreeSetCraftingEntries(SortMode sortMode) {
|
||||
TreeSet<CraftingEntry> sortedSet;
|
||||
|
||||
switch (sortMode) {
|
||||
case ALPHABETICALLY:
|
||||
// Sort alphabetically by item name
|
||||
sortedSet = new TreeSet<>((o1, o2) -> {
|
||||
if (o1.outputStacks.isEmpty()) {
|
||||
return 1;
|
||||
} else if (o2.outputStacks.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
String name1 = String.valueOf(o1.outputStacks.getFirst().getItem());
|
||||
String name2 = String.valueOf(o2.outputStacks.getFirst().getItem());
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
});
|
||||
break;
|
||||
|
||||
case ALPHABETICALLY_REVERSE:
|
||||
// Sort alphabetically by item name in reverse order
|
||||
sortedSet = new TreeSet<>((o1, o2) -> {
|
||||
if (o1.outputStacks.isEmpty()) {
|
||||
return 1;
|
||||
} else if (o2.outputStacks.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
String name1 = String.valueOf(o1.outputStacks.getFirst().getItem());
|
||||
String name2 = String.valueOf(o2.outputStacks.getFirst().getItem());
|
||||
return name2.compareToIgnoreCase(name1); // Reverse comparison
|
||||
});
|
||||
break;
|
||||
|
||||
case NUMERICALLY:
|
||||
// Sort by count in descending order
|
||||
sortedSet = new TreeSet<>((o1, o2) -> {
|
||||
if (o1.outputStacks.isEmpty()) {
|
||||
return 1;
|
||||
} else if (o2.outputStacks.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
int count1 = o1.totalMax;
|
||||
int count2 = o2.totalMax;
|
||||
int countCompare = Integer.compare(count2, count1);
|
||||
// If counts are equal, compare items alphabetically by name
|
||||
if (countCompare == 0) {
|
||||
String name1 = String.valueOf(o1.outputStacks.getFirst().getItem());
|
||||
String name2 = String.valueOf(o2.outputStacks.getFirst().getItem());
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
}
|
||||
return countCompare;
|
||||
});
|
||||
break;
|
||||
|
||||
case NUMERICALLY_REVERSE:
|
||||
// Sort by count in ascending order
|
||||
sortedSet = new TreeSet<>((o1, o2) -> {
|
||||
if (o1.outputStacks.isEmpty()) {
|
||||
return 1;
|
||||
} else if (o2.outputStacks.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
int count1 = o1.totalMax;
|
||||
int count2 = o2.totalMax;
|
||||
int countCompare = Integer.compare(count1, count2); // Reverse comparison
|
||||
// If counts are equal, compare items alphabetically by name
|
||||
if (countCompare == 0) {
|
||||
String name1 = String.valueOf(o1.outputStacks.getFirst().getItem());
|
||||
String name2 = String.valueOf(o2.outputStacks.getFirst().getItem());
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
}
|
||||
return countCompare;
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid sort mode: " + sortMode);
|
||||
}
|
||||
|
||||
return sortedSet;
|
||||
}
|
||||
|
||||
|
||||
public static int canInsertToStack(ItemStack stack1, ItemStack stack2, int maxInsert) {
|
||||
if (stack1.isEmpty() || ItemStack.areItemsEqual(stack1, stack2)) {
|
||||
int remainingSpace = stack1.isEmpty() ? stack2.getMaxCount() : stack1.getMaxCount() - stack1.getCount();
|
||||
@@ -80,8 +219,8 @@ public class StorageOperations {
|
||||
|
||||
if (inventory instanceof PlayerInventory playerInventory) {
|
||||
// Iterate through the slots in the player's inventory
|
||||
for (int i = 0; i < playerInventory.main.size(); i++) {
|
||||
ItemStack slotStack = playerInventory.main.get(i);
|
||||
for (int i = 0; i < playerInventory.getMainStacks().size(); i++) {
|
||||
ItemStack slotStack = playerInventory.getMainStacks().get(i);
|
||||
maxInsert = canInsertToStack(slotStack, itemStack, maxInsert);
|
||||
}
|
||||
} else {
|
||||
@@ -94,9 +233,15 @@ public class StorageOperations {
|
||||
return maxInsert; // Return the maximum insertion count
|
||||
}
|
||||
|
||||
public static ItemStack insertStackIntoInventory(Inventory inventory, ItemStack stack) {
|
||||
public static ItemStack insertStackIntoInventory(Inventory inventory, ItemStack stack, boolean mainOnly) {
|
||||
int startSlot = 0;
|
||||
int endSlot = inventory.size();
|
||||
if (mainOnly) {
|
||||
startSlot = 9;
|
||||
endSlot = 45;
|
||||
}
|
||||
// First, try to merge with existing stacks
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
for (int i = startSlot; i < endSlot; i++) {
|
||||
ItemStack slotStack = inventory.getStack(i);
|
||||
if (canCombine(slotStack, stack)) {
|
||||
int transferAmount = Math.min(stack.getCount(), slotStack.getMaxCount() - slotStack.getCount());
|
||||
@@ -112,7 +257,7 @@ public class StorageOperations {
|
||||
}
|
||||
|
||||
// Next, try to find an empty slot
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
for (int i = startSlot; i < endSlot; i++) {
|
||||
ItemStack slotStack = inventory.getStack(i);
|
||||
if (slotStack.isEmpty()) {
|
||||
inventory.setStack(i, stack.copy());
|
||||
@@ -145,7 +290,7 @@ public class StorageOperations {
|
||||
}
|
||||
}
|
||||
|
||||
public static int howMuchFits(ItemStack stack, Inventory inventory){
|
||||
public static int howMuchFits(ItemStack stack, Inventory inventory) {
|
||||
int out = 0;
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
ItemStack slotStack = inventory.getStack(i);
|
||||
|
@@ -1,20 +1,28 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.LoreComponent;
|
||||
import net.minecraft.component.type.TooltipDisplayComponent;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.*;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.recipe.CraftingRecipe;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.RecipeEntry;
|
||||
import net.minecraft.recipe.ServerRecipeManager;
|
||||
import net.minecraft.recipe.input.CraftingRecipeInput;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.text.RawFilteredPair;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.UserCache;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Util {
|
||||
@@ -86,6 +94,31 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static GameProfile getGameProfile(UUID playerUUID, MinecraftServer server) {
|
||||
UserCache userCache = server.getUserCache();
|
||||
GameProfile gameProfile = null;
|
||||
Optional<GameProfile> gameProfileTemp;
|
||||
|
||||
if (userCache != null) {
|
||||
gameProfileTemp = userCache.getByUuid(playerUUID);
|
||||
boolean exists = gameProfileTemp.isPresent();
|
||||
gameProfile = exists ? gameProfileTemp.get() : null;
|
||||
}
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
public static List<SessionStorageClass> removePosition(BlockPos pos, ItemStack stack) {
|
||||
List<SessionStorageClass> sessions = new ArrayList<>(stack.getOrDefault(WirelessTerminalComponents.SESSIONS, new ArrayList<>()));
|
||||
for (SessionStorageClass session : sessions) {
|
||||
if (session.getTerminalPos().equals(pos)) {
|
||||
sessions.remove(session);
|
||||
break;
|
||||
}
|
||||
}
|
||||
stack.set(WirelessTerminalComponents.SESSIONS, sessions);
|
||||
return sessions;
|
||||
}
|
||||
|
||||
public static ItemStack removeCountFromLore(ItemStack stack) {
|
||||
LoreComponent oldLore = stack.get(DataComponentTypes.LORE);
|
||||
|
||||
@@ -97,7 +130,9 @@ public class Util {
|
||||
|
||||
LoreComponent newLore = new LoreComponent(filteredLines);
|
||||
|
||||
|
||||
newStack.set(DataComponentTypes.LORE, newLore);
|
||||
newStack.set(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplayComponent.DEFAULT);
|
||||
return newStack;
|
||||
} else {
|
||||
return stack;
|
||||
@@ -105,40 +140,42 @@ public class Util {
|
||||
}
|
||||
|
||||
public static ArrayList<CraftingEntry> getCraftableRecipes(Map<ItemStack, Integer> itemStackMap, MinecraftServer server) {
|
||||
RecipeManager recipeManager = server.getRecipeManager();
|
||||
List<RecipeEntry<CraftingRecipe>> allRecipes = recipeManager.listAllOfType(RecipeType.CRAFTING);
|
||||
ServerRecipeManager recipeManager = server.getRecipeManager();
|
||||
List<RecipeEntry<?>> allRecipes = (List<RecipeEntry<?>>) recipeManager.values();
|
||||
|
||||
ArrayList<CraftingEntry> craftingEntries = new ArrayList<>();
|
||||
|
||||
for (RecipeEntry<CraftingRecipe> recipe : allRecipes) {
|
||||
for (RecipeEntry<?> recipex : allRecipes) {
|
||||
if (!(recipex.value() instanceof CraftingRecipe)) {
|
||||
continue;
|
||||
}
|
||||
RecipeEntry<CraftingRecipe> recipe = (RecipeEntry<CraftingRecipe>) recipex;
|
||||
int maxAmount = Integer.MAX_VALUE;
|
||||
boolean canMake = true;
|
||||
HashMap<ItemStack, Integer> finalInputs = new HashMap<>();
|
||||
Map<Item, Integer> ingredientCounts = new HashMap<>();
|
||||
|
||||
// Count the occurrences of each ingredient in the recipe
|
||||
for (Ingredient ingredient : recipe.value().getIngredients()) {
|
||||
for (ItemStack stack : ingredient.getMatchingStacks()) {
|
||||
if (stack.isEmpty()) continue;
|
||||
ingredientCounts.put(stack.getItem(), ingredientCounts.getOrDefault(stack.getItem(), 0) + 1);
|
||||
for (Ingredient ingredient : recipe.value().getIngredientPlacement().getIngredients()) {
|
||||
for (RegistryEntry<Item> item : ingredient.getMatchingItems().toList()) {
|
||||
ingredientCounts.put(item.value(), ingredientCounts.getOrDefault(item.value(), 0) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
boolean usesAnyIngredient = false;
|
||||
|
||||
for (Ingredient ingredient : recipe.value().getIngredients()) {
|
||||
for (Ingredient ingredient : recipe.value().getIngredientPlacement().getIngredients()) {
|
||||
int totalAvailable = 0;
|
||||
HashMap<ItemStack, Integer> inputsTemp = new HashMap<>();
|
||||
|
||||
for (ItemStack stack : ingredient.getMatchingStacks()) {
|
||||
if (stack.isEmpty()) continue;
|
||||
for (RegistryEntry<Item> item : ingredient.getMatchingItems().toList()) {
|
||||
for (Map.Entry<ItemStack, Integer> entry : itemStackMap.entrySet()) {
|
||||
ItemStack inventoryStack = entry.getKey();
|
||||
int inventoryCount = entry.getValue();
|
||||
|
||||
if (ItemStack.areItemsEqual(stack, inventoryStack)) {
|
||||
if (item.value() == inventoryStack.getItem()) {
|
||||
totalAvailable += inventoryCount;
|
||||
inputsTemp.put(stack, inventoryCount);
|
||||
inputsTemp.put(item.value().getDefaultStack(), inventoryCount);
|
||||
usesAnyIngredient = true;
|
||||
}
|
||||
}
|
||||
@@ -148,10 +185,13 @@ public class Util {
|
||||
canMake = false;
|
||||
break;
|
||||
}
|
||||
|
||||
int requiredCount = ingredient.getMatchingStacks()[0].getCount();
|
||||
int occurrences = ingredientCounts.get(ingredient.getMatchingStacks()[0].getItem());
|
||||
maxAmount = Math.min(maxAmount, totalAvailable / (requiredCount * occurrences));
|
||||
// int occurrences = ingredientCounts.getOrDefault(ingredient.getMatchingItems().getFirst(),0);
|
||||
// if (occurrences == 0) {
|
||||
// canMake = false;
|
||||
// break;
|
||||
// }
|
||||
// maxAmount = Math.min(maxAmount, totalAvailable / occurrences);
|
||||
maxAmount = Math.min(maxAmount, totalAvailable);
|
||||
|
||||
for (Map.Entry<ItemStack, Integer> entry : inputsTemp.entrySet()) {
|
||||
ItemStack stackIn = entry.getKey();
|
||||
@@ -161,11 +201,44 @@ public class Util {
|
||||
}
|
||||
|
||||
if (canMake && maxAmount > 0 && usesAnyIngredient) {
|
||||
ItemStack outputItem = recipe.value().getResult(server.getRegistryManager()).copy();
|
||||
List<ItemStack> stacks = finalInputs.keySet().stream().toList();
|
||||
CraftingRecipeInput input = CraftingRecipeInput.create(stacks.size(), 1, stacks);
|
||||
ItemStack outputItem = recipe.value().craft(input, server.getRegistryManager()).copy();
|
||||
CraftingEntry finalEntry = new CraftingEntry(outputItem, recipe, finalInputs, maxAmount);
|
||||
craftingEntries.add(finalEntry);
|
||||
}
|
||||
}
|
||||
return craftingEntries;
|
||||
}
|
||||
|
||||
public static void putUUID(NbtCompound nbtCompound, String name, UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "UUID cannot be null");
|
||||
ByteBuffer buffer = ByteBuffer.allocate(16);
|
||||
buffer.putLong(uuid.getMostSignificantBits());
|
||||
buffer.putLong(uuid.getLeastSignificantBits());
|
||||
nbtCompound.putByteArray(name, buffer.array());
|
||||
}
|
||||
|
||||
public static Optional<UUID> getUUID(NbtCompound nbtCompound, String name) {
|
||||
Optional<byte[]> bytesOpt = nbtCompound.getByteArray(name);
|
||||
if (bytesOpt.isPresent()) {
|
||||
byte[] bytes = bytesOpt.get();
|
||||
if (bytes.length == 16) {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
||||
long mostSigBits = buffer.getLong();
|
||||
long leastSigBits = buffer.getLong();
|
||||
return Optional.of(new UUID(mostSigBits, leastSigBits));
|
||||
}
|
||||
} else {
|
||||
Optional<int[]> intsOpt = nbtCompound.getIntArray(name);
|
||||
if (intsOpt.isPresent() && intsOpt.get().length == 4) {
|
||||
int[] ints = intsOpt.get();
|
||||
long mostSigBits = ((long) ints[0] << 32) | (ints[1] & 0xFFFFFFFFL);
|
||||
long leastSigBits = ((long) ints[2] << 32) | (ints[3] & 0xFFFFFFFFL);
|
||||
return Optional.of(new UUID(mostSigBits, leastSigBits));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,76 @@
|
||||
package systems.brn.serverstorage.lib;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import eu.pb4.polymer.core.api.other.PolymerComponent;
|
||||
import net.minecraft.component.ComponentType;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static systems.brn.serverstorage.lib.DriveComponents.UUID_CODEC;
|
||||
|
||||
|
||||
public class WirelessTerminalComponents {
|
||||
|
||||
public static final Codec<SessionStorageClass> SESSION_CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
UUID_CODEC.fieldOf("playerUUID").forGetter(SessionStorageClass::getPlayerUUID),
|
||||
ServerWorld.CODEC.fieldOf("worldKey").forGetter(SessionStorageClass::getWorldKey),
|
||||
BlockPos.CODEC.fieldOf("terminalPos").forGetter(SessionStorageClass::getTerminalPos)
|
||||
).apply(instance, SessionStorageClass::new));
|
||||
|
||||
public static final Codec<List<SessionStorageClass>> SESSIONS_CODEC = Codec.list(SESSION_CODEC);
|
||||
|
||||
|
||||
public static final ComponentType<UUID> SESSION_KEY = register(
|
||||
"session_key",
|
||||
builder -> builder.codec(UUID_CODEC) // No packetCodec needed for this example
|
||||
);
|
||||
|
||||
public static final ComponentType<List<SessionStorageClass>> SESSIONS = register(
|
||||
"sessions",
|
||||
builder -> builder.codec(SESSIONS_CODEC) // No packetCodec needed for this example
|
||||
);
|
||||
|
||||
public static final ComponentType<Integer> SELECTED_POSITION = register(
|
||||
"selected_position",
|
||||
builder -> builder.codec(Codec.INT) // No packetCodec needed for this example
|
||||
);
|
||||
|
||||
public static final ComponentType<Integer> PAGE = register(
|
||||
"page",
|
||||
builder -> builder.codec(Codec.INT) // No packetCodec needed for this example
|
||||
);
|
||||
|
||||
|
||||
public static final ComponentType<SortMode> SORT_MODE = register(
|
||||
"sort_mode",
|
||||
builder -> builder.codec(Codec.INT.xmap(SortMode::fromId, SortMode::getId)) // No packetCodec needed for this example
|
||||
);
|
||||
|
||||
public static final ComponentType<Boolean> GROUP_SIMILAR = register(
|
||||
"group_similar",
|
||||
builder -> builder.codec(Codec.BOOL) // No packetCodec needed for this example
|
||||
);
|
||||
|
||||
public static final ComponentType<String> QUERY_STRING = register(
|
||||
"query_string",
|
||||
builder -> builder.codec(Codec.STRING) // 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,85 @@
|
||||
package systems.brn.serverstorage.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.serverstorage.blockentities.RadioInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.lib.AntennaSlot;
|
||||
|
||||
public class RadioInterfaceScreenHandler extends ScreenHandler {
|
||||
private final Inventory inventory;
|
||||
private final RadioInterfaceBlockEntity blockEntity;
|
||||
|
||||
public RadioInterfaceScreenHandler(int syncId, PlayerInventory playerInventory, RadioInterfaceBlockEntity blockEntity) {
|
||||
super(ScreenHandlerType.BEACON, syncId);
|
||||
this.blockEntity = blockEntity;
|
||||
checkSize(blockEntity, RadioInterfaceBlockEntity.INVENTORY_SIZE);
|
||||
this.inventory = blockEntity;
|
||||
inventory.onOpen(playerInventory.player);
|
||||
|
||||
int j;
|
||||
this.addSlot(new AntennaSlot(inventory, 0, 44, 20));
|
||||
|
||||
for (j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 9; ++k) {
|
||||
this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, j * 18 + 51));
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < 9; ++j) {
|
||||
this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 109));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return this.inventory.canPlayerUse(player);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack quickMove(PlayerEntity player, int slot) {
|
||||
return quickMoveHelper(player, slot);
|
||||
}
|
||||
|
||||
public ItemStack quickMoveHelper(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 < this.inventory.size()) {
|
||||
if (!this.insertItem(itemStack2, this.inventory.size(), this.slots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.insertItem(itemStack2, 0, this.inventory.size(), 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);
|
||||
this.blockEntity.updateAntenna();
|
||||
}
|
||||
}
|
@@ -1,31 +1,34 @@
|
||||
package systems.brn.serverstorage.screens;
|
||||
|
||||
import eu.pb4.sgui.api.ClickType;
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.recipe.CraftingRecipe;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.RecipeEntry;
|
||||
import net.minecraft.recipe.input.CraftingRecipeInput;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import systems.brn.serverstorage.blockentities.StorageInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.lib.CraftingEntry;
|
||||
import systems.brn.serverstorage.lib.PagedGui;
|
||||
import systems.brn.serverstorage.lib.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
import static systems.brn.serverstorage.lib.StorageOperations.*;
|
||||
import static systems.brn.serverstorage.lib.Util.getCraftableRecipes;
|
||||
|
||||
public class CraftingScreen extends PagedGui {
|
||||
public class CraftingScreen extends PagedGui implements Searchable {
|
||||
private final StorageScreen storageScreen;
|
||||
private ArrayList<CraftingEntry> craftingEntries;
|
||||
private final StorageInterfaceBlockEntity blockEntity;
|
||||
private ArrayList<DisplayElement> recipesList;
|
||||
public String searchQuery;
|
||||
|
||||
public CraftingScreen(StorageScreen storageScreen) {
|
||||
super(storageScreen.getPlayer(), null);
|
||||
@@ -35,13 +38,21 @@ public class CraftingScreen extends PagedGui {
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
public void reindexDrives() {
|
||||
if (blockEntity == null) {
|
||||
storageScreen.getNetwork().reindexNetwork();
|
||||
} else {
|
||||
blockEntity.reindexDrives();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
blockEntity.reindexDrives(); // Use justReindexDrives to avoid looping
|
||||
|
||||
Map<ItemStack, Integer> itemStackMap = new HashMap<>();
|
||||
addInventoryToMap(storageScreen.getPlayer().getInventory(), itemStackMap);
|
||||
itemStackMap.putAll(blockEntity.network.itemStackMap);
|
||||
Map<ItemStack, Integer> items = sortAndFilterMap(itemStackMap, false, null);
|
||||
itemStackMap.putAll(storageScreen.getNetwork().itemStackMap);
|
||||
Map<ItemStack, Integer> items = sortAndFilterMap(itemStackMap, SortMode.NUMERICALLY_REVERSE, null, getGroupSimilar());
|
||||
this.craftingEntries = getCraftableRecipes(items, Objects.requireNonNull(player.getServer()));
|
||||
this.recipesList = getAvailableRecipes();
|
||||
super.updateDisplay();
|
||||
@@ -49,15 +60,17 @@ public class CraftingScreen extends PagedGui {
|
||||
|
||||
private ArrayList<DisplayElement> getAvailableRecipes() {
|
||||
ArrayList<DisplayElement> recipes = new ArrayList<>();
|
||||
|
||||
for (CraftingEntry craftingEntry : craftingEntries) {
|
||||
TreeSet<CraftingEntry> filteredCraftingEntries = sortAndFilterEntries(craftingEntries, getSorting(), getQueryString());
|
||||
for (CraftingEntry craftingEntry : filteredCraftingEntries) {
|
||||
ItemStack stackWithCount = craftingEntry.outputStacks.getFirst().copy();
|
||||
if (stackWithCount.getCount() > stackWithCount.getMaxCount()) {
|
||||
stackWithCount.setCount(stackWithCount.getMaxCount());
|
||||
}
|
||||
if (stackWithCount.getItem() != null && filterItem(stackWithCount.getItem(), getQueryString())) {
|
||||
recipes.add(
|
||||
DisplayElement.of(new GuiElementBuilder(stackWithCount)
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
if (storageScreen.checkDistance()) {
|
||||
playClickSound(player);
|
||||
RecipeEntry<CraftingRecipe> recipeEntry = craftingEntry.recipeEntry;
|
||||
|
||||
@@ -76,10 +89,12 @@ public class CraftingScreen extends PagedGui {
|
||||
}
|
||||
}
|
||||
updateDisplay();
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return recipes;
|
||||
}
|
||||
|
||||
@@ -92,8 +107,8 @@ public class CraftingScreen extends PagedGui {
|
||||
}
|
||||
|
||||
private boolean canCraft(RecipeEntry<CraftingRecipe> recipeEntry) {
|
||||
blockEntity.reindexDrives();
|
||||
for (Ingredient ingredient : recipeEntry.value().getIngredients()) {
|
||||
reindexDrives();
|
||||
for (Ingredient ingredient : recipeEntry.value().getIngredientPlacement().getIngredients()) {
|
||||
if (findMatchingStack(ingredient) == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -102,10 +117,11 @@ public class CraftingScreen extends PagedGui {
|
||||
}
|
||||
|
||||
private boolean craftOne(PlayerEntity player, RecipeEntry<CraftingRecipe> recipeEntry, boolean toPlayerInventory) {
|
||||
this.storageScreen.refreshTerminals();
|
||||
ArrayList<ItemStack> stacksToRemove = new ArrayList<>();
|
||||
|
||||
// Check and remove ingredients for one crafting operation
|
||||
for (Ingredient ingredient : recipeEntry.value().getIngredients()) {
|
||||
for (Ingredient ingredient : recipeEntry.value().getIngredientPlacement().getIngredients()) {
|
||||
ItemStack stackToRemove = findMatchingStack(ingredient);
|
||||
if (stackToRemove == null) {
|
||||
return false; // Unable to find required ingredient
|
||||
@@ -119,7 +135,7 @@ public class CraftingScreen extends PagedGui {
|
||||
}
|
||||
|
||||
// Add crafted item to the appropriate inventory
|
||||
ItemStack outputStack = recipeEntry.value().getResult(storageScreen.getPlayer().getRegistryManager()).copy();
|
||||
ItemStack outputStack = recipeEntry.value().craft(CraftingRecipeInput.create(stacksToRemove.size(), 1, stacksToRemove), storageScreen.getPlayer().getRegistryManager()).copy();
|
||||
|
||||
if (toPlayerInventory) {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
@@ -131,8 +147,8 @@ public class CraftingScreen extends PagedGui {
|
||||
}
|
||||
} else {
|
||||
ItemStack insertStack = outputStack.copy();
|
||||
if (this.blockEntity.network.canAddItemStack(insertStack)) {
|
||||
this.blockEntity.network.putItemStackRemainder(insertStack);
|
||||
if (this.storageScreen.getNetwork().canAddItemStack(insertStack)) {
|
||||
this.storageScreen.getNetwork().putItemStackRemainder(insertStack);
|
||||
} else {
|
||||
return true; // Storage full or unable to insert all items
|
||||
}
|
||||
@@ -148,9 +164,10 @@ public class CraftingScreen extends PagedGui {
|
||||
ItemStack playerStack = playerInventory.getStack(i);
|
||||
if (ingredient.test(playerStack)) {
|
||||
ItemStack stackToRemove = playerStack.copy();
|
||||
for (ItemStack matchingStack : ingredient.getMatchingStacks()){
|
||||
if (matchingStack.getItem() == stackToRemove.getItem()) {
|
||||
stackToRemove.setCount(matchingStack.getCount()); // Set count to ingredient requirement
|
||||
for (RegistryEntry<Item> matchingItemx : ingredient.getMatchingItems().toList()) {
|
||||
Item matchingItem = matchingItemx.value();
|
||||
if (matchingItem == stackToRemove.getItem()) {
|
||||
stackToRemove.setCount(1); // Set count to ingredient requirement
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -159,10 +176,11 @@ public class CraftingScreen extends PagedGui {
|
||||
}
|
||||
|
||||
// Check storage network
|
||||
for (ItemStack stack : ingredient.getMatchingStacks()) {
|
||||
if (this.blockEntity.network.canRemove(stack)) {
|
||||
ItemStack stackToRemove = stack.copy();
|
||||
stackToRemove.setCount(ingredient.getMatchingStacks()[0].getCount()); // Set count to ingredient requirement
|
||||
for (RegistryEntry<Item> itemx : ingredient.getMatchingItems().toList()) {
|
||||
Item item = itemx.value();
|
||||
if (this.storageScreen.getNetwork().canRemove(item.getDefaultStack())) {
|
||||
ItemStack stackToRemove = item.getDefaultStack();
|
||||
stackToRemove.setCount(1); // Set count to ingredient requirement
|
||||
return stackToRemove;
|
||||
}
|
||||
}
|
||||
@@ -170,7 +188,7 @@ public class CraftingScreen extends PagedGui {
|
||||
}
|
||||
|
||||
private void removeItems(ItemStack stack) {
|
||||
ItemStack removedFromStorage = this.blockEntity.network.removeItemStack(stack);
|
||||
ItemStack removedFromStorage = this.storageScreen.getNetwork().removeItemStack(stack);
|
||||
if (removedFromStorage.getCount() > 0) {
|
||||
Inventory playerInventory = player.getInventory();
|
||||
for (int i = 0; i < playerInventory.size(); i++) {
|
||||
@@ -182,24 +200,102 @@ public class CraftingScreen extends PagedGui {
|
||||
}
|
||||
}
|
||||
|
||||
public String getQueryString() {
|
||||
if (blockEntity == null) {
|
||||
return storageScreen.itemStack.getOrDefault(WirelessTerminalComponents.QUERY_STRING, "");
|
||||
} else {
|
||||
return blockEntity.searchString == null ? "*" : blockEntity.searchString;
|
||||
}
|
||||
}
|
||||
|
||||
public void setQueryString(String queryString) {
|
||||
if (blockEntity == null) {
|
||||
storageScreen.itemStack.set(WirelessTerminalComponents.QUERY_STRING, queryString);
|
||||
} else {
|
||||
blockEntity.searchString = queryString;
|
||||
}
|
||||
}
|
||||
|
||||
public SortMode getSorting() {
|
||||
if (blockEntity == null) {
|
||||
return storageScreen.itemStack.getOrDefault(WirelessTerminalComponents.SORT_MODE, SortMode.NUMERICALLY_REVERSE);
|
||||
} else {
|
||||
return blockEntity.sortAlphabetically;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSorting(SortMode sorting) {
|
||||
if (blockEntity == null) {
|
||||
storageScreen.itemStack.set(WirelessTerminalComponents.SORT_MODE, sorting);
|
||||
} else {
|
||||
blockEntity.sortAlphabetically = sorting;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean getGroupSimilar() {
|
||||
if (blockEntity == null) {
|
||||
return storageScreen.itemStack.getOrDefault(WirelessTerminalComponents.GROUP_SIMILAR, false);
|
||||
} else {
|
||||
return blockEntity.groupSimilar;
|
||||
}
|
||||
}
|
||||
|
||||
public void setGroupSimilar(boolean groupSimilar) {
|
||||
if (blockEntity == null) {
|
||||
storageScreen.itemStack.set(WirelessTerminalComponents.GROUP_SIMILAR, groupSimilar);
|
||||
} else {
|
||||
blockEntity.groupSimilar = groupSimilar;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement sorting() {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(getSorting().getSortingText().formatted(Formatting.WHITE))
|
||||
.setLore(List.of(Text.translatable(getGroupSimilar() ? "gui.serverstorage.group_similar" : "gui.serverstorage.dont_group_similar").formatted(Formatting.DARK_PURPLE)))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(getSorting().getSortingIcon(getGroupSimilar()))
|
||||
.setCallback((x, clickType, z) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (storageScreen.checkDistance()) {
|
||||
if (clickType == ClickType.MOUSE_LEFT) {
|
||||
setSorting(getSorting().nextSort());
|
||||
} else if (clickType == ClickType.MOUSE_RIGHT) {
|
||||
setGroupSimilar(!getGroupSimilar());
|
||||
}
|
||||
updateDisplay();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open() {
|
||||
page = blockEntity.page;
|
||||
if (this.blockEntity != null) {
|
||||
this.blockEntity.openCraftingScreens.add(this);
|
||||
blockEntity.updateDisplays();
|
||||
} else {
|
||||
updateDisplay();
|
||||
}
|
||||
return super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
if (this.blockEntity != null) {
|
||||
this.blockEntity.openCraftingScreens.remove(this);
|
||||
this.blockEntity.refreshTerminals();
|
||||
}
|
||||
storageScreen.open();
|
||||
storageScreen.updateDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return Math.ceilDivExact(recipesList.size(), 9 * 6);
|
||||
return Math.ceilDivExact(recipesList.size(), PAGE_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,4 +306,35 @@ public class CraftingScreen extends PagedGui {
|
||||
return DisplayElement.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doSearch(String searchText) {
|
||||
setQueryString(searchText);
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement search() {
|
||||
String searchString = getQueryString();
|
||||
if (searchString == null || searchString.isEmpty() || searchString.equals("*")) {
|
||||
searchString = "Filter not set";
|
||||
}
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.literal(searchString).formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_QUESTION_MARK)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (storageScreen.checkDistance()) {
|
||||
if (y.isRight) {
|
||||
doSearch("");
|
||||
} else if (y.isLeft) {
|
||||
SearchScreen searchScreen = new SearchScreen(this, "");
|
||||
searchScreen.open();
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,54 @@
|
||||
package systems.brn.serverstorage.screens;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import systems.brn.serverstorage.blockentities.DisplayBlockEntity;
|
||||
import systems.brn.serverstorage.lib.PagedGui;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class DisplayBlockMangementScreen extends PagedGui {
|
||||
public final DisplayBlockEntity displayBlockEntity;
|
||||
|
||||
public DisplayBlockMangementScreen(ServerPlayerEntity player, DisplayBlockEntity displayBlockEntity) {
|
||||
super(player, null);
|
||||
this.displayBlockEntity = displayBlockEntity;
|
||||
this.setTitle(Text.translatable("gui.serverstorage.display_block_title"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement getElement(int id) {
|
||||
var builder = new GuiElementBuilder(displayBlockEntity.targetItem.getCount() > 0 ? displayBlockEntity.targetItem.getItem() : Items.AIR)
|
||||
.setName(displayBlockEntity.targetItem.getItemName())
|
||||
.setCallback((clickIndex, clickType, slotActionType) -> {
|
||||
displayBlockEntity.targetItem = getPlayer().currentScreenHandler.getCursorStack().copy();
|
||||
|
||||
displayBlockEntity.reindexDrives();
|
||||
|
||||
displayBlockEntity.itemCount = 0;
|
||||
for(Map.Entry<ItemStack, Integer> entry : displayBlockEntity.network.itemStackMap.entrySet()) {
|
||||
ItemStack key = entry.getKey();
|
||||
Integer value = entry.getValue();
|
||||
if (ItemStack.areItemsAndComponentsEqual(key, displayBlockEntity.targetItem)) {
|
||||
displayBlockEntity.itemCount = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
displayBlockEntity.itemElement.setItem(displayBlockEntity.targetItem.copy());
|
||||
displayBlockEntity.textDisplayElement.setText(Text.of(String.valueOf(displayBlockEntity.itemCount)));
|
||||
displayBlockEntity.markDirty();
|
||||
playClickSound(getPlayer());
|
||||
updateDisplay();
|
||||
});
|
||||
|
||||
return DisplayElement.of(builder);
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
package systems.brn.serverstorage.screens;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import systems.brn.serverstorage.blockentities.RadioInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.lib.PagedGui;
|
||||
import systems.brn.serverstorage.lib.Session;
|
||||
|
||||
import static systems.brn.serverstorage.lib.Util.getGameProfile;
|
||||
|
||||
public class RadioBlockPlayerMangementScreen extends PagedGui {
|
||||
public final RadioInterfaceBlockEntity radioInterfaceBlockEntity;
|
||||
|
||||
public RadioBlockPlayerMangementScreen(ServerPlayerEntity player, RadioInterfaceBlockEntity radioInterfaceBlockEntity) {
|
||||
super(player, null);
|
||||
this.radioInterfaceBlockEntity = radioInterfaceBlockEntity;
|
||||
this.setTitle(Text.translatable("gui.serverstorage.player_management"));
|
||||
}
|
||||
|
||||
protected DisplayElement getSessionElement(Session session, int index) {
|
||||
|
||||
GameProfile gameProfile = null;
|
||||
if (player != null && player.getServer() != null) {
|
||||
gameProfile = getGameProfile(session.playerUUID(), player.getServer());
|
||||
}
|
||||
|
||||
var builder = new GuiElementBuilder(gameProfile != null ? Items.PLAYER_HEAD : Items.SKELETON_SKULL)
|
||||
.setName(Text.translatable("gui.serverstorage.player_management_session", index))
|
||||
.addLoreLine(Text.translatable("gui.serverstorage.player_management_session_owner",
|
||||
gameProfile != null ? gameProfile.getName() : "<" + session.playerUUID().toString() + ">")
|
||||
.formatted(Formatting.WHITE)
|
||||
)
|
||||
.addLoreLine(Text.translatable("gui.serverstorage.player_management_session_key", session.sessionKey().toString()))
|
||||
.addLoreLine(Text.translatable("gui.serverstorage.player_management_session_click_deauthorize"))
|
||||
.setCallback((clickIndex, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
radioInterfaceBlockEntity.deAuthorizeSession(session.sessionKey(), session.playerUUID());
|
||||
updateDisplay();
|
||||
});
|
||||
|
||||
if (gameProfile != null) {
|
||||
builder.setSkullOwner(gameProfile, null);
|
||||
} else {
|
||||
builder.setSkullOwner(PagedGui.GUI_QUESTION_MARK);
|
||||
}
|
||||
|
||||
return DisplayElement.of(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return radioInterfaceBlockEntity.sessions.size() / PAGE_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement getElement(int id) {
|
||||
if (id < radioInterfaceBlockEntity.sessions.size()) {
|
||||
Session session = radioInterfaceBlockEntity.sessions.get(id);
|
||||
return getSessionElement(session, id);
|
||||
}
|
||||
return DisplayElement.empty();
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ package systems.brn.serverstorage.screens;
|
||||
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import systems.brn.serverstorage.blockentities.InventoryInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.lib.Searchable;
|
||||
|
||||
public class SearchScreen extends AnvilInputGui {
|
||||
|
||||
@@ -20,10 +21,11 @@ public class SearchScreen extends AnvilInputGui {
|
||||
super.onClose();
|
||||
parentScreen.open();
|
||||
String query = this.getInput();
|
||||
if (parentScreen instanceof StorageScreen storageScreen) {
|
||||
storageScreen.doSearch(query);
|
||||
} else if (parentScreen instanceof SettingsScreen settingsScreen && settingsScreen.blockEntity instanceof InventoryInterfaceBlockEntity inventoryInterfaceBlockEntity) {
|
||||
if (parentScreen instanceof Searchable searchable) {
|
||||
searchable.doSearch(query);
|
||||
if (parentScreen instanceof SettingsScreen settingsScreen && settingsScreen.blockEntity instanceof InventoryInterfaceBlockEntity inventoryInterfaceBlockEntity) {
|
||||
inventoryInterfaceBlockEntity.doSearch(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,10 +10,11 @@ import net.minecraft.util.Formatting;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.serverstorage.blockentities.InventoryInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.lib.PagedGui;
|
||||
import systems.brn.serverstorage.lib.Searchable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SettingsScreen extends PagedGui {
|
||||
public class SettingsScreen extends PagedGui implements Searchable {
|
||||
|
||||
private final SimpleGui parentScreen;
|
||||
|
||||
@@ -33,6 +34,10 @@ public class SettingsScreen extends PagedGui {
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
public void doSearch(String query) {
|
||||
|
||||
}
|
||||
|
||||
public SettingsScreen(StorageScreen parentScreen) {
|
||||
this(parentScreen, parentScreen.getPlayer(), parentScreen.blockEntity);
|
||||
}
|
||||
@@ -58,7 +63,7 @@ public class SettingsScreen extends PagedGui {
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return Math.ceilDivExact(settingsList.size(), 9 * 5);
|
||||
return Math.ceilDivExact(settingsList.size(), PAGE_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -8,22 +8,50 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.serverstorage.blockentities.RadioInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.blockentities.StorageInterfaceBlockEntity;
|
||||
import systems.brn.serverstorage.lib.PagedGui;
|
||||
import systems.brn.serverstorage.lib.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.ServerStorage_Crafting_Enable;
|
||||
import static systems.brn.serverstorage.items.WirelessTerminalItem.getDistance;
|
||||
import static systems.brn.serverstorage.lib.StorageOperations.*;
|
||||
import static systems.brn.serverstorage.lib.Util.addCountToLore;
|
||||
import static systems.brn.serverstorage.lib.Util.removeCountFromLore;
|
||||
|
||||
public class StorageScreen extends PagedGui {
|
||||
public class StorageScreen extends PagedGui implements Searchable {
|
||||
private final ServerPlayerEntity player;
|
||||
public final StorageInterfaceBlockEntity blockEntity;
|
||||
public final StorageNetwork network;
|
||||
public final ItemStack itemStack;
|
||||
public final ServerWorld world;
|
||||
public final RadioInterfaceBlockEntity radioInterfaceBlockEntity;
|
||||
|
||||
public boolean checkDistance() {
|
||||
if (radioInterfaceBlockEntity != null) {
|
||||
RadioDistance radioDistance = getDistance(player, radioInterfaceBlockEntity);
|
||||
if (radioDistance.actualDistance() > radioDistance.finalDistance()) {
|
||||
close();
|
||||
ServerWorld playerWorld = radioDistance.playerWorld();
|
||||
ServerWorld terminalWorld = radioDistance.terminalWorld();
|
||||
String playerWorldName = playerWorld.getRegistryKey().getValue().toString();
|
||||
String terminalWorldName = terminalWorld.getRegistryKey().getValue().toString();
|
||||
player.sendMessage(Text.translatable("gui.serverstorage.radio_out_of_range", radioDistance.terminalPos().toShortString(), terminalWorldName, player.getBlockPos().toShortString(), playerWorldName, radioDistance.actualDistance(), radioDistance.finalDistance()), true);
|
||||
player.playSoundToPlayer(SoundEvents.BLOCK_NOTE_BLOCK_COW_BELL.value(), SoundCategory.PLAYERS, 1f, 1f);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public StorageScreen(ServerPlayerEntity player, BlockPos pos, @Nullable Runnable closeCallback) {
|
||||
super(player, closeCallback);
|
||||
@@ -31,30 +59,140 @@ public class StorageScreen extends PagedGui {
|
||||
this.setLockPlayerInventory(false);
|
||||
this.blockEntity = (StorageInterfaceBlockEntity) player.getWorld().getBlockEntity(pos);
|
||||
assert blockEntity != null;
|
||||
this.network = null;
|
||||
this.itemStack = ItemStack.EMPTY;
|
||||
this.world = player.getWorld();
|
||||
this.radioInterfaceBlockEntity = null;
|
||||
}
|
||||
|
||||
public StorageScreen(ServerPlayerEntity player, ItemStack itemStack, StorageNetwork storageNetwork, RadioInterfaceBlockEntity radioInterfaceBlockEntity) {
|
||||
super(player, null);
|
||||
this.player = player;
|
||||
this.blockEntity = null;
|
||||
this.setLockPlayerInventory(false);
|
||||
this.network = storageNetwork;
|
||||
this.itemStack = itemStack;
|
||||
this.world = player.getWorld();
|
||||
this.radioInterfaceBlockEntity = radioInterfaceBlockEntity;
|
||||
}
|
||||
|
||||
public StorageNetwork getNetwork() {
|
||||
if (blockEntity != null) {
|
||||
blockEntity.enforceNetwork();
|
||||
return blockEntity.network;
|
||||
}
|
||||
return network;
|
||||
}
|
||||
|
||||
public SortMode getSorting() {
|
||||
if (blockEntity == null) {
|
||||
return itemStack.getOrDefault(WirelessTerminalComponents.SORT_MODE, SortMode.NUMERICALLY_REVERSE);
|
||||
} else {
|
||||
return blockEntity.sortAlphabetically;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getGroupSimilar() {
|
||||
if (blockEntity == null) {
|
||||
return itemStack.getOrDefault(WirelessTerminalComponents.GROUP_SIMILAR, false);
|
||||
} else {
|
||||
return blockEntity.groupSimilar;
|
||||
}
|
||||
}
|
||||
|
||||
public void setGroupSimilar(boolean groupSimilar) {
|
||||
if (blockEntity == null) {
|
||||
itemStack.set(WirelessTerminalComponents.GROUP_SIMILAR, groupSimilar);
|
||||
} else {
|
||||
blockEntity.groupSimilar = groupSimilar;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSorting(SortMode sorting) {
|
||||
if (blockEntity == null) {
|
||||
itemStack.set(WirelessTerminalComponents.SORT_MODE, sorting);
|
||||
} else {
|
||||
blockEntity.sortAlphabetically = sorting;
|
||||
}
|
||||
}
|
||||
|
||||
public String getQueryString() {
|
||||
if (blockEntity == null) {
|
||||
return itemStack.getOrDefault(WirelessTerminalComponents.QUERY_STRING, "");
|
||||
} else {
|
||||
return blockEntity.searchString;
|
||||
}
|
||||
}
|
||||
|
||||
public void setQueryString(String queryString) {
|
||||
if (blockEntity == null) {
|
||||
itemStack.set(WirelessTerminalComponents.QUERY_STRING, queryString);
|
||||
} else {
|
||||
blockEntity.searchString = queryString;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
if (blockEntity == null) {
|
||||
return itemStack.getOrDefault(WirelessTerminalComponents.PAGE, 0);
|
||||
} else {
|
||||
return blockEntity.page;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPage(int page) {
|
||||
if (page > getPageAmount()) {
|
||||
page = getPageAmount() - 1;
|
||||
}
|
||||
if (blockEntity == null) {
|
||||
itemStack.set(WirelessTerminalComponents.PAGE, page);
|
||||
} else {
|
||||
blockEntity.page = page;
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshTerminals() {
|
||||
if (blockEntity == null) {
|
||||
this.network.sortMode = getSorting();
|
||||
this.network.groupSimilar = getGroupSimilar();
|
||||
this.network.searchString = getQueryString();
|
||||
getNetwork().reindexNetwork();
|
||||
getNetwork().updateDisplays();
|
||||
updateDisplay();
|
||||
} else {
|
||||
blockEntity.refreshTerminals();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open() {
|
||||
page = blockEntity.page;
|
||||
this.blockEntity.openStorageScreens.add(this);
|
||||
page = getPage();
|
||||
if (blockEntity == null) {
|
||||
updateDisplay();
|
||||
if (!checkDistance()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
blockEntity.reindexDrives();
|
||||
blockEntity.openStorageScreens.add(this);
|
||||
blockEntity.updateDisplays();
|
||||
}
|
||||
return super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
blockEntity.reindexDrives();
|
||||
String title = blockEntity.network.driveUsedSlots +
|
||||
String title = getNetwork().driveUsedSlots +
|
||||
"u/" +
|
||||
blockEntity.network.driveTotalSlots +
|
||||
getNetwork().driveTotalSlots +
|
||||
"t(" +
|
||||
blockEntity.network.driveFreeSlots +
|
||||
getNetwork().driveFreeSlots +
|
||||
"f)" +
|
||||
"[" +
|
||||
blockEntity.network.driveContainerCount +
|
||||
getNetwork().driveContainerCount +
|
||||
"c]" +
|
||||
"[" +
|
||||
blockEntity.network.drivesCount +
|
||||
getNetwork().drivesCount +
|
||||
"d]";
|
||||
|
||||
setTitle(Text.of(title));
|
||||
@@ -63,15 +201,15 @@ public class StorageScreen extends PagedGui {
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return Math.ceilDivExact(blockEntity.network.filteredItemStackMap.size(), 9 * 5);
|
||||
return Math.ceilDivExact(getNetwork().filteredItemStackMap.size(), PAGE_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement getElement(int id) {
|
||||
if (blockEntity.network.filteredItemStackMap.size() > id) {
|
||||
ItemStack itemStackKey = (ItemStack) blockEntity.network.filteredItemStackMap.keySet().toArray()[id];
|
||||
if (getNetwork().filteredItemStackMap.size() > id) {
|
||||
ItemStack itemStackKey = (ItemStack) getNetwork().filteredItemStackMap.keySet().toArray()[id];
|
||||
ItemStack aestheticStack = itemStackKey.copy();
|
||||
int count = blockEntity.network.filteredItemStackMap.get(itemStackKey);
|
||||
int count = getNetwork().filteredItemStackMap.get(itemStackKey);
|
||||
aestheticStack.setCount(Math.min(aestheticStack.getMaxCount(), count));
|
||||
ItemStack newStack = addCountToLore(count, aestheticStack, null);
|
||||
GuiElementBuilder guiElement = new GuiElementBuilder(newStack);
|
||||
@@ -82,18 +220,21 @@ public class StorageScreen extends PagedGui {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int index, ClickType type, SlotActionType action, GuiElementInterface element) {
|
||||
if (!checkDistance()) {
|
||||
return false;
|
||||
}
|
||||
GuiElementInterface clickedElement = getSlot(index);
|
||||
ItemStack cursorStack = getPlayer().currentScreenHandler.getCursorStack();
|
||||
if (clickedElement != null && cursorStack.isEmpty()) {
|
||||
ItemStack clickedItem = clickedElement.getItemStack();
|
||||
ItemStack noLoreStack = removeCountFromLore(clickedItem);
|
||||
noLoreStack = blockEntity.network.findSimilarStack(noLoreStack);
|
||||
noLoreStack = getNetwork().findSimilarStack(noLoreStack);
|
||||
if (type.isRight) {
|
||||
if (!type.shift) {
|
||||
noLoreStack.setCount(Math.min(noLoreStack.getMaxCount(), noLoreStack.getCount() / 2)); //half stack
|
||||
} else {
|
||||
for (int i = 0; i < player.getInventory().main.size(); i++) {
|
||||
ItemStack stack = player.getInventory().main.get(i);
|
||||
for (int i = 0; i < player.getInventory().getMainStacks().size(); i++) {
|
||||
ItemStack stack = player.getInventory().getMainStacks().get(i);
|
||||
if (ItemStack.areItemsAndComponentsEqual(stack, noLoreStack)) {
|
||||
insertItem(stack, 0, getVirtualSize(), false);
|
||||
}
|
||||
@@ -110,37 +251,47 @@ public class StorageScreen extends PagedGui {
|
||||
int insertCount = canInsertItemIntoInventory(playerInventory, noLoreStack);
|
||||
ItemStack insertingStack = noLoreStack.copy();
|
||||
insertingStack.setCount(insertCount);
|
||||
blockEntity.refreshTerminals();
|
||||
if (blockEntity.network.canRemove(noLoreStack) && insertCount > 0) {
|
||||
refreshTerminals();
|
||||
if (getNetwork().canRemove(noLoreStack) && insertCount > 0) {
|
||||
playerInventory.insertStack(insertingStack.copy());
|
||||
blockEntity.network.removeItemStack(insertingStack);
|
||||
blockEntity.refreshTerminals();
|
||||
getNetwork().removeItemStack(insertingStack);
|
||||
refreshTerminals();
|
||||
}
|
||||
}
|
||||
} else if (!cursorStack.isEmpty()) {
|
||||
insertItem(cursorStack);
|
||||
insertItem(cursorStack, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void insertItem(ItemStack stack) {
|
||||
int canPutIn = stack.getCount() - blockEntity.network.putItemStackRemainder(stack);
|
||||
public void insertItem(ItemStack stack, boolean isCursor) {
|
||||
if (!checkDistance() || stack.getItem() == itemStack.getItem()) {
|
||||
return;
|
||||
}
|
||||
int canPutIn = stack.getCount() - getNetwork().putItemStackRemainder(stack);
|
||||
if (canPutIn > 0) {
|
||||
if (isCursor) {
|
||||
stack.decrement(canPutIn);
|
||||
} else {
|
||||
removeFromInventory(player.getInventory(), stack, canPutIn);
|
||||
blockEntity.refreshTerminals();
|
||||
}
|
||||
refreshTerminals();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast) {
|
||||
blockEntity.refreshTerminals();
|
||||
insertItem(stack);
|
||||
if (!checkDistance()) {
|
||||
return false;
|
||||
}
|
||||
refreshTerminals();
|
||||
insertItem(stack, true);
|
||||
return super.insertItem(stack, startIndex, endIndex, fromLast);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement search() {
|
||||
String searchString = blockEntity.searchString;
|
||||
String searchString = getQueryString();
|
||||
if (searchString == null || searchString.isEmpty() || searchString.equals("*")) {
|
||||
searchString = "Filter not set";
|
||||
}
|
||||
@@ -151,18 +302,24 @@ public class StorageScreen extends PagedGui {
|
||||
.setSkullOwner(GUI_QUESTION_MARK)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (checkDistance()) {
|
||||
if (y.isRight) {
|
||||
doSearch("");
|
||||
} else if (y.isLeft) {
|
||||
SearchScreen searchScreen = new SearchScreen(this, "");
|
||||
searchScreen.open();
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement settings() {
|
||||
if (blockEntity == null) {
|
||||
WirelessTerminalSelectorScreen wirelessTerminalSelectorScreen = new WirelessTerminalSelectorScreen(this);
|
||||
return wirelessTerminalSelectorScreen.getItem();
|
||||
}
|
||||
SettingsScreen settingsScreen = new SettingsScreen(this);
|
||||
return settingsScreen.getItem();
|
||||
}
|
||||
@@ -171,38 +328,82 @@ public class StorageScreen extends PagedGui {
|
||||
protected DisplayElement sorting() {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable(this.blockEntity.sortAlphabetically ? "A->Z" : "9->1").formatted(Formatting.WHITE))
|
||||
.setName(getSorting().getSortingText().formatted(Formatting.WHITE))
|
||||
.setLore(List.of(Text.translatable(getGroupSimilar() ? "gui.serverstorage.group_similar" : "gui.serverstorage.dont_group_similar").formatted(Formatting.DARK_PURPLE)))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(this.blockEntity.sortAlphabetically ? GUI_A : GUI_1)
|
||||
.setCallback((x, y, z) -> {
|
||||
this.blockEntity.sortAlphabetically ^= true;
|
||||
.setSkullOwner(getSorting().getSortingIcon(getGroupSimilar()))
|
||||
.setCallback((x, clickType, z) -> {
|
||||
playClickSound(getPlayer());
|
||||
this.blockEntity.refreshTerminals();
|
||||
if (checkDistance()) {
|
||||
if (clickType == ClickType.MOUSE_LEFT) {
|
||||
setSorting(getSorting().nextSort());
|
||||
} else if (clickType == ClickType.MOUSE_RIGHT) {
|
||||
setGroupSimilar(!getGroupSimilar());
|
||||
}
|
||||
this.refreshTerminals();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private int insertIntoPlayer(ItemStack stack, int count, PlayerInventory playerInventory) {
|
||||
int maxFit = howMuchFits(stack, playerInventory);
|
||||
int finalCount = Math.min(count, maxFit);
|
||||
ItemStack insertedStack = stack.copy();
|
||||
insertedStack.setCount(finalCount);
|
||||
getNetwork().removeItemStack(insertedStack);
|
||||
getNetwork().updateDisplays();
|
||||
updateDisplay();
|
||||
int remainingToInsert = finalCount;
|
||||
for (int i = 0; i < Math.ceilDivExact(finalCount, stack.getMaxCount()); i++) {
|
||||
ItemStack cappedStack = insertedStack.copy();
|
||||
cappedStack.setCount(Math.min(insertedStack.getMaxCount(), remainingToInsert));
|
||||
|
||||
ItemStack remaining = insertStackIntoInventory(playerInventory, cappedStack.copy(), true);
|
||||
if (!remaining.isEmpty()) {
|
||||
ItemStack reverseStack = stack.copy();
|
||||
reverseStack.setCount(remaining.getCount() + remainingToInsert);
|
||||
getNetwork().putItemStackRemainder(reverseStack);
|
||||
break;
|
||||
}
|
||||
remainingToInsert -= cappedStack.getCount();
|
||||
}
|
||||
return count - (finalCount - remainingToInsert);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement storeAll() {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("gui.all").formatted(Formatting.WHITE))
|
||||
.setName(Text.translatable("gui.serverstorage.store_all").formatted(Formatting.WHITE))
|
||||
.setLore(List.of(Text.translatable("gui.serverstorage.store_all.lore").formatted(Formatting.DARK_PURPLE)))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_STORE_ALL)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(player);
|
||||
for (int i = 0; i < player.getInventory().main.size(); i++) {
|
||||
ItemStack stack = player.getInventory().main.get(i);
|
||||
if (checkDistance()) {
|
||||
if (y.isLeft) {
|
||||
for (int i = y.shift ? 0 : 8; i < player.getInventory().getMainStacks().size(); i++) {
|
||||
ItemStack stack = player.getInventory().getMainStacks().get(i);
|
||||
insertItem(stack, 0, getVirtualSize(), false);
|
||||
}
|
||||
}
|
||||
if (y.isRight) {
|
||||
//give to player
|
||||
for (Map.Entry<ItemStack, Integer> entry : getNetwork().filteredItemStackMap.entrySet()) {
|
||||
int leftOver = insertIntoPlayer(entry.getKey(), entry.getValue(), player.getInventory());
|
||||
if (leftOver > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement crafting() {
|
||||
World world = blockEntity.getWorld();
|
||||
if (world != null && world.getGameRules().getBoolean(ServerStorage_Crafting_Enable)) {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
@@ -211,9 +412,11 @@ public class StorageScreen extends PagedGui {
|
||||
.setSkullOwner(GUI_CRAFTING)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(player);
|
||||
if (checkDistance()) {
|
||||
CraftingScreen craftingScreen = new CraftingScreen(this);
|
||||
playClickSound(getPlayer());
|
||||
craftingScreen.open();
|
||||
}
|
||||
})
|
||||
);
|
||||
} else {
|
||||
@@ -222,9 +425,9 @@ public class StorageScreen extends PagedGui {
|
||||
}
|
||||
|
||||
public void doSearch(String query) {
|
||||
this.blockEntity.searchString = query;
|
||||
this.blockEntity.refreshTerminals();
|
||||
this.page = 0;
|
||||
setQueryString(query);
|
||||
setPage(0);
|
||||
refreshTerminals();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,18 +439,22 @@ public class StorageScreen extends PagedGui {
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(player);
|
||||
this.page = 0;
|
||||
this.blockEntity.searchString = "";
|
||||
this.blockEntity.refreshTerminals();
|
||||
if (checkDistance()) {
|
||||
setPage(0);
|
||||
setQueryString("");
|
||||
refreshTerminals();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
this.blockEntity.page = page;
|
||||
setPage(page);
|
||||
if (blockEntity != null) {
|
||||
this.blockEntity.markDirty();
|
||||
this.blockEntity.openStorageScreens.remove(this);
|
||||
}
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,153 @@
|
||||
package systems.brn.serverstorage.screens;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import systems.brn.serverstorage.items.WirelessTerminalItem;
|
||||
import systems.brn.serverstorage.lib.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static systems.brn.serverstorage.ServerStorage.WIRELESS_TERMINAL;
|
||||
import static systems.brn.serverstorage.items.WirelessTerminalItem.saveStack;
|
||||
|
||||
public class WirelessTerminalSelectorScreen extends PagedGui {
|
||||
|
||||
final public ItemStack stack;
|
||||
final public ItemStack stackOriginal;
|
||||
public List<SessionStorageClass> sessions;
|
||||
public int selectedIndex;
|
||||
public final StorageScreen storageScreen;
|
||||
|
||||
public WirelessTerminalSelectorScreen(ServerPlayerEntity player, @Nullable StorageScreen storageScreen) {
|
||||
super(player, null);
|
||||
final ItemStack stackOriginal = player.getStackInHand(player.getActiveHand());
|
||||
final ItemStack stack = stackOriginal.copy();
|
||||
if (stack.getItem() == WIRELESS_TERMINAL) {
|
||||
this.stack = stack;
|
||||
this.stackOriginal = stackOriginal;
|
||||
this.sessions = new ArrayList<>(stack.getOrDefault(WirelessTerminalComponents.SESSIONS, new ArrayList<>()));
|
||||
this.selectedIndex = stack.getOrDefault(WirelessTerminalComponents.SELECTED_POSITION, -1);
|
||||
this.setTitle(Text.translatable("gui.serverstorage.radio_selector"));
|
||||
this.storageScreen = storageScreen;
|
||||
this.updateDisplay();
|
||||
} else {
|
||||
this.stack = ItemStack.EMPTY;
|
||||
this.stackOriginal = stack;
|
||||
this.sessions = new ArrayList<>();
|
||||
this.selectedIndex = -1;
|
||||
this.storageScreen = storageScreen;
|
||||
}
|
||||
}
|
||||
|
||||
public WirelessTerminalSelectorScreen(StorageScreen storageScreen) {
|
||||
this(storageScreen.getPlayer(), storageScreen);
|
||||
}
|
||||
|
||||
private void commitStack() {
|
||||
saveStack(stack, stackOriginal, player);
|
||||
}
|
||||
|
||||
private void setSelectedPosition() {
|
||||
if (selectedIndex >= sessions.size()) {
|
||||
selectedIndex = sessions.size() - 1;
|
||||
}
|
||||
stack.set(WirelessTerminalComponents.SELECTED_POSITION, selectedIndex);
|
||||
commitStack();
|
||||
}
|
||||
|
||||
private void removePosition(BlockPos pos) {
|
||||
this.sessions = Util.removePosition(pos, stack);
|
||||
setSelectedPosition();
|
||||
}
|
||||
|
||||
protected DisplayElement getRadioTerminal(BlockPos position, SessionStorageClass sessionStorageClass, int index) {
|
||||
if (player != null && player.getServer() != null) {
|
||||
MinecraftServer server = player.getServer();
|
||||
GameProfile gameProfile = sessionStorageClass.getPlayerProfile(server);
|
||||
|
||||
String playerName = gameProfile != null ? gameProfile.getName() : "Profile nonexistent";
|
||||
|
||||
var builder = new GuiElementBuilder(gameProfile != null ? Items.PLAYER_HEAD : Items.SKELETON_SKULL)
|
||||
.setName(Text.translatable("gui.serverstorage.radio_entry", index))
|
||||
.setSkullOwner(gameProfile, player.getServer())
|
||||
.addLoreLine(Text.translatable("gui.serverstorage.radio_position",
|
||||
position.toShortString(), sessionStorageClass.getWorldKey().getValue().getPath()
|
||||
.formatted(Formatting.WHITE)
|
||||
))
|
||||
.addLoreLine(Text.translatable("gui.serverstorage.player_management_session_owner", playerName))
|
||||
.addLoreLine(Text.translatable("gui.serverstorage.radio_session_click_select"))
|
||||
.addLoreLine(Text.translatable("gui.serverstorage.radio_session_click_open"))
|
||||
.addLoreLine(Text.translatable("gui.serverstorage.radio_session_click_delete"))
|
||||
.setCallback((clickIndex, clickType, slotActionType) -> {
|
||||
playClickSound(getPlayer());
|
||||
if (clickType.isLeft) {
|
||||
if (clickType.shift) {
|
||||
removePosition(position);
|
||||
} else {
|
||||
boolean success = WirelessTerminalItem.openTerminal(position, player, player.getStackInHand(player.getActiveHand()), sessionStorageClass.getWorld(server));
|
||||
if (!success) {
|
||||
removePosition(position);
|
||||
}
|
||||
}
|
||||
} else if (clickType.isRight) {
|
||||
this.selectedIndex = index;
|
||||
setSelectedPosition();
|
||||
boolean success = WirelessTerminalItem.openTerminal(position, player, player.getStackInHand(player.getActiveHand()), sessionStorageClass.getWorld(server));
|
||||
if (!success) {
|
||||
removePosition(position);
|
||||
}
|
||||
}
|
||||
updateDisplay();
|
||||
});
|
||||
|
||||
return DisplayElement.of(builder);
|
||||
} else {
|
||||
return DisplayElement.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPageAmount() {
|
||||
return sessions.size() / PAGE_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DisplayElement getElement(int id) {
|
||||
if (id < sessions.size()) {
|
||||
SessionStorageClass sessionStorageClass = sessions.get(id);
|
||||
return getRadioTerminal(sessionStorageClass.getTerminalPos(), sessionStorageClass, id);
|
||||
}
|
||||
return DisplayElement.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
WirelessTerminalItem.updateLore(stack, player.getServer());
|
||||
if (storageScreen != null) {
|
||||
storageScreen.open();
|
||||
}
|
||||
}
|
||||
|
||||
public DisplayElement getItem() {
|
||||
return DisplayElement.of(
|
||||
new GuiElementBuilder(Items.PLAYER_HEAD)
|
||||
.setName(Text.translatable("mco.configure.world.settings.title").formatted(Formatting.WHITE))
|
||||
.hideDefaultTooltip().noDefaults()
|
||||
.setSkullOwner(GUI_SETTINGS)
|
||||
.setCallback((x, y, z) -> {
|
||||
playClickSound(getPlayer());
|
||||
this.open();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
{
|
||||
"multipart": [
|
||||
{
|
||||
"when": { "north": "none", "south": "none", "west": "none", "east": "none", "up": "none", "down": "none" },
|
||||
"apply": { "model": "serverstorage:block/bus_connector_blank" }
|
||||
},
|
||||
{
|
||||
"when": { "north": "bus" },
|
||||
"apply": { "model": "serverstorage:block/bus_connector_bus_north" }
|
||||
},
|
||||
{
|
||||
"when": { "south": "bus" },
|
||||
"apply": { "model": "serverstorage:block/bus_connector_bus_south" }
|
||||
},
|
||||
{
|
||||
"when": { "west": "bus" },
|
||||
"apply": { "model": "serverstorage:block/bus_connector_bus_west" }
|
||||
},
|
||||
{
|
||||
"when": { "east": "bus" },
|
||||
"apply": { "model": "serverstorage:block/bus_connector_bus_east" }
|
||||
},
|
||||
{
|
||||
"when": { "up": "bus" },
|
||||
"apply": { "model": "serverstorage:block/bus_connector_bus_up" }
|
||||
},
|
||||
{
|
||||
"when": { "down": "bus" },
|
||||
"apply": { "model": "serverstorage:block/bus_connector_bus_down" }
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"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,32 +0,0 @@
|
||||
{
|
||||
"multipart": [
|
||||
{
|
||||
"when": { "north": "none", "south": "none", "west": "none", "east": "none", "up": "none", "down": "none" },
|
||||
"apply": { "model": "serverstorage:block/inventory_interface_blank" }
|
||||
},
|
||||
{
|
||||
"when": { "north": "inventory" },
|
||||
"apply": { "model": "serverstorage:block/inventory_interface_inventory_north" }
|
||||
},
|
||||
{
|
||||
"when": { "south": "inventory" },
|
||||
"apply": { "model": "serverstorage:block/inventory_interface_inventory_south" }
|
||||
},
|
||||
{
|
||||
"when": { "west": "inventory" },
|
||||
"apply": { "model": "serverstorage:block/inventory_interface_inventory_west" }
|
||||
},
|
||||
{
|
||||
"when": { "east": "inventory" },
|
||||
"apply": { "model": "serverstorage:block/inventory_interface_inventory_east" }
|
||||
},
|
||||
{
|
||||
"when": { "up": "inventory" },
|
||||
"apply": { "model": "serverstorage:block/inventory_interface_inventory_up" }
|
||||
},
|
||||
{
|
||||
"when": { "down": "inventory" },
|
||||
"apply": { "model": "serverstorage:block/inventory_interface_inventory_down" }
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:block/bus_connector"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/creative_drive"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/diamond_antenna"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/diamond_drive"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/diamond_head"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/diamond_platter"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:block/display_block"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:block/drive_container"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/ender_antenna"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/golden_antenna"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/golden_drive"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/golden_head"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/golden_platter"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:block/inventory_interface"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/iron_antenna"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/iron_drive"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/iron_head"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/iron_platter"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/material_cpu"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/material_cpu_substrate"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/material_drive_casing"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/material_drive_controller"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/material_pcb"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/material_pcb_substrate"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_antenna"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_antenna_connector"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_bus"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_configuration"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_container"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_display"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_drive"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_filtering"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_inventory"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_modem"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_netherite_upgrade"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_pagination"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_pcb"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_radio"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/module_transport"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/netherite_antenna"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/netherite_drive"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/netherite_head"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/netherite_platter"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:block/radio_interface"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:block/storage"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "serverstorage:item/wireless_terminal"
|
||||
}
|
||||
}
|
@@ -1,51 +1,105 @@
|
||||
{
|
||||
"block.serverstorage.storage": "Networked storage interface",
|
||||
"block.serverstorage.storage": "Networked Storage Interface",
|
||||
"item.serverstorage.storage": "Networked Storage Interface",
|
||||
|
||||
"block.serverstorage.inventory_interface": "Networked inventory interface",
|
||||
"block.serverstorage.display_block": "Networked Display",
|
||||
"item.serverstorage.display_block": "Networked Display",
|
||||
|
||||
"block.serverstorage.drive_container": "Hard drive container",
|
||||
"block.serverstorage.inventory_interface": "Networked Inventory Interface",
|
||||
"item.serverstorage.inventory_interface": "Networked Inventory Interface",
|
||||
|
||||
"block.serverstorage.bus_connector": "Storage network connector",
|
||||
"block.serverstorage.drive_container": "Hard Drive Container",
|
||||
"item.serverstorage.drive_container": "Hard Drive Container",
|
||||
|
||||
"item.serverstorage.iron_drive": "Iron hard drive",
|
||||
"item.serverstorage.iron_head": "Iron hard drive head",
|
||||
"item.serverstorage.iron_platter": "Iron hard drive platter",
|
||||
"block.serverstorage.bus_connector": "Storage Network Connector",
|
||||
"item.serverstorage.bus_connector": "Storage Network Connector",
|
||||
|
||||
"item.serverstorage.golden_drive": "Golden hard drive",
|
||||
"item.serverstorage.golden_head": "Golden hard drive head",
|
||||
"item.serverstorage.golden_platter": "Golden hard drive platter",
|
||||
"block.serverstorage.radio_interface": "Networked Radio Interface",
|
||||
"item.serverstorage.radio_interface": "Networked Radio Interface",
|
||||
|
||||
"item.serverstorage.diamond_drive": "Diamond hard drive",
|
||||
"item.serverstorage.diamond_head": "Diamond hard drive head",
|
||||
"item.serverstorage.diamond_platter": "Diamond hard drive platter",
|
||||
"item.serverstorage.iron_drive": "Iron Hard Drive",
|
||||
"item.serverstorage.iron_head": "Iron Hard Drive Head",
|
||||
"item.serverstorage.iron_platter": "Iron Hard Drive Platter",
|
||||
|
||||
"item.serverstorage.netherite_drive": "Netherite hard drive",
|
||||
"item.serverstorage.netherite_head": "Netherite hard drive head",
|
||||
"item.serverstorage.netherite_platter": "Netherite hard drive platter",
|
||||
"item.serverstorage.golden_drive": "Golden Hard Drive",
|
||||
"item.serverstorage.golden_head": "Golden Hard Drive Head",
|
||||
"item.serverstorage.golden_platter": "Golden Hard Drive Platter",
|
||||
|
||||
"item.serverstorage.module_bus": "Bus module",
|
||||
"item.serverstorage.module_configuration": "Configuration module",
|
||||
"item.serverstorage.module_container": "Container module",
|
||||
"item.serverstorage.module_display": "Display module",
|
||||
"item.serverstorage.module_drive": "Drive module",
|
||||
"item.serverstorage.module_filtering": "Filtering module",
|
||||
"item.serverstorage.module_inventory": "Inventory module",
|
||||
"item.serverstorage.module_pagination": "Pagination module",
|
||||
"item.serverstorage.module_transport": "Transport module",
|
||||
"item.serverstorage.module_netherite_upgrade": "Netherite upgrade module",
|
||||
"item.serverstorage.diamond_drive": "Diamond Hard Drive",
|
||||
"item.serverstorage.diamond_head": "Diamond Hard Drive Head",
|
||||
"item.serverstorage.diamond_platter": "Diamond Hard Drive Platter",
|
||||
|
||||
"item.serverstorage.netherite_drive": "Netherite Hard Drive",
|
||||
"item.serverstorage.netherite_head": "Netherite Hard Drive Head",
|
||||
"item.serverstorage.netherite_platter": "Netherite Hard Drive Platter",
|
||||
|
||||
"item.serverstorage.creative_drive": "Creative Hard Drive",
|
||||
|
||||
"item.serverstorage.module_bus": "Bus Module",
|
||||
"item.serverstorage.module_configuration": "Configuration Module",
|
||||
"item.serverstorage.module_container": "Container Module",
|
||||
"item.serverstorage.module_display": "Display Module",
|
||||
"item.serverstorage.module_drive": "Drive Module",
|
||||
"item.serverstorage.module_filtering": "Filtering Module",
|
||||
"item.serverstorage.module_inventory": "Inventory Module",
|
||||
"item.serverstorage.module_pagination": "Pagination Module",
|
||||
"item.serverstorage.module_transport": "Transport Module",
|
||||
"item.serverstorage.module_antenna": "Antenna Module",
|
||||
"item.serverstorage.module_radio": "Radio Module",
|
||||
"item.serverstorage.module_antenna_connector": "Antenna Connector Module",
|
||||
"item.serverstorage.module_modem": "MoDem Module",
|
||||
"item.serverstorage.module_netherite_upgrade": "Netherite Upgrade Module",
|
||||
|
||||
|
||||
"item.serverstorage.module_pcb": "Module PCB",
|
||||
|
||||
"item.serverstorage.material_drive_casing": "Hard drive casing",
|
||||
"item.serverstorage.material_drive_controller": "Drive controller",
|
||||
"item.serverstorage.material_drive_casing": "Hard Drive Casing",
|
||||
"item.serverstorage.material_drive_controller": "Drive Controller",
|
||||
"item.serverstorage.material_cpu": "Central Processing Unit",
|
||||
"item.serverstorage.material_cpu_substrate": "CPU substrate",
|
||||
"item.serverstorage.material_cpu_substrate": "CPU Substrate",
|
||||
"item.serverstorage.material_pcb": "Printed Circuit Board",
|
||||
"item.serverstorage.material_pcb_substrate": "PCB substrate",
|
||||
"item.serverstorage.material_pcb_substrate": "PCB Substrate",
|
||||
|
||||
"item.serverstorage.iron_antenna": "Iron Antenna",
|
||||
"item.serverstorage.golden_antenna": "Golden Antenna",
|
||||
"item.serverstorage.diamond_antenna": "Diamond Antenna",
|
||||
"item.serverstorage.netherite_antenna": "Netherite Antenna",
|
||||
"item.serverstorage.ender_antenna": "Ender Antenna",
|
||||
|
||||
"item.serverstorage.wireless_terminal": "Wireless Terminal",
|
||||
|
||||
"gui.serverstorage.store_all": "Store all items from inventory",
|
||||
"gui.serverstorage.store_all.lore": "Holding shift includes your hotbar",
|
||||
"gui.serverstorage.player_management": "Player management",
|
||||
"gui.serverstorage.player_management_session": "Session %d",
|
||||
"gui.serverstorage.player_management_session_owner": "Owned by: %s",
|
||||
"gui.serverstorage.player_management_session_owner_error": "Not owned",
|
||||
"gui.serverstorage.player_management_session_key": "Session key: %s",
|
||||
|
||||
"gui.serverstorage.display_block_title": "Display block",
|
||||
"gui.serverstorage.display_block_item": "Target item: %s",
|
||||
|
||||
"gui.serverstorage.wireless_terminal_link_count": "Linked to %d devices",
|
||||
"gui.serverstorage.wireless_terminal_link_index": "Current link index is %d",
|
||||
"gui.serverstorage.wireless_terminal_page": "Page: %d",
|
||||
"gui.serverstorage.wireless_terminal_search_query": "Search query: %s",
|
||||
"gui.serverstorage.sorting_alphabetically": "Sorting alphabetically",
|
||||
"gui.serverstorage.sorting_alphabetically_reversed": "Sorting alphabetically reversed",
|
||||
"gui.serverstorage.sorting_numerically": "Sorting numerically",
|
||||
"gui.serverstorage.sorting_numerically_reversed": "Sorting numerically reversed",
|
||||
"gui.serverstorage.antenna_range": "Range: %d blocks",
|
||||
"gui.serverstorage.player_management_session_click_deauthorize": "Click to deauthorize",
|
||||
"gui.serverstorage.radio_selector": "Radio selector",
|
||||
"gui.serverstorage.radio_entry": "Radio %d",
|
||||
"gui.serverstorage.radio_connected": "Connected to radio at %s in %s from %s in %s, distance %d/%d",
|
||||
"gui.serverstorage.radio_unauthorized": "Session unauthorized in radio at %s in %s",
|
||||
"gui.serverstorage.radio_out_of_range": "Radio out of range at %s in %s from %s in %s, distance %d/%d",
|
||||
"gui.serverstorage.radio_not_found": "Radio not found at %s in %s from %s in %s",
|
||||
"gui.serverstorage.radio_position": "Placed at %s in %s",
|
||||
"gui.serverstorage.radio_position_error": "Not Placed",
|
||||
"gui.serverstorage.radio_session_click_select": "Left click to connect",
|
||||
"gui.serverstorage.radio_session_click_open": "Right click to select",
|
||||
"gui.serverstorage.radio_session_click_delete": "Shift Left click to remove",
|
||||
"gui.serverstorage.filter": "Filter",
|
||||
"gui.serverstorage.sort_alphabetically": "Sort alphabetically",
|
||||
"gui.serverstorage.sort_descending": "Sort by count descending",
|
||||
@@ -58,9 +112,12 @@
|
||||
"gui.serverstorage.direction_up": "Up",
|
||||
"gui.serverstorage.direction_down": "Down",
|
||||
|
||||
"serverstorage.groups.blocks" : "Serverstorage blocks",
|
||||
"serverstorage.groups.materials" : "Serverstorage materials",
|
||||
"serverstorage.groups.drives" : "Serverstorage drives",
|
||||
"gui.serverstorage.group_similar": "Group Similar",
|
||||
"gui.serverstorage.dont_group_similar": "Don't Group Similar",
|
||||
|
||||
"serverstorage.groups.blocks" : "Serverstorage Blocks",
|
||||
"serverstorage.groups.materials" : "Serverstorage Materials",
|
||||
"serverstorage.groups.drives" : "Serverstorage Drives",
|
||||
|
||||
"message.serverstorage.block_disabled": "This block was disabled in a gamerule, contact admins"
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "serverstorage:block/bus_connector_blank"
|
||||
}
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "serverstorage:block/bus_connector_blank"
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user