This commit is contained in:
Bruno Rybársky 2024-06-25 18:03:31 +02:00
parent 06e5f220bd
commit 1d27add23a
45 changed files with 480 additions and 103 deletions

@ -11,15 +11,19 @@ import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
import systems.brn.server_storage.blockentities.StorageBlockEntity;
import systems.brn.server_storage.blocks.HardDriveContainerBlock;
import systems.brn.server_storage.blocks.StorageBlock;
import systems.brn.server_storage.items.HardDriveContainerBlockItem;
import systems.brn.server_storage.items.HardDriveItem;
import systems.brn.server_storage.items.StorageBlockItem;
import systems.brn.server_storage.items.SimpleBlockItem;
import systems.brn.server_storage.items.SimpleItem;
import systems.brn.server_storage.items.TieredItem;
import java.util.Arrays;
import java.util.List;
public class ServerStorage implements ModInitializer {
public static final List<String> tiers = Arrays.asList("iron", "golden", "diamond", "netherite");
public static final String MOD_ID = "serverstorage";
public static final String STORAGE_MODEL_ID = "storage";
public static final String HARD_DRIVE_MODEL_ID = "drive";
public static final String HARD_DRIVE_CONTAINER_BLOCK_MODEL_ID = "drive_container";
public static BlockEntityType<HardDriveContainerBlockEntity> HARD_DRIVE_CONTAINER_BLOCK_ENTITY;
@ -40,12 +44,15 @@ public class ServerStorage implements ModInitializer {
public void onInitialize()
{
StorageBlock.register();
StorageBlockItem.register();
SimpleBlockItem.register(STORAGE_BLOCK);
HardDriveContainerBlock.register();
HardDriveContainerBlockItem.register();
SimpleBlockItem.register(HARD_DRIVE_CONTAINER_BLOCK);
HardDriveItem.register();
TieredItem.register("drive");
TieredItem.register("head");
TieredItem.register("platter");
SimpleItem.register("drive_casing");
PolymerResourcePackUtils.addModAssets(MOD_ID);
PolymerResourcePackUtils.markAsRequired();

@ -31,6 +31,7 @@ import org.jetbrains.annotations.Nullable;
import systems.brn.server_storage.ServerStorage;
import systems.brn.server_storage.blockentities.HardDriveContainerBlockEntity;
import systems.brn.server_storage.blockentities.StorageBlockEntity;
import systems.brn.server_storage.screens.DriveScreen;
import systems.brn.server_storage.screens.StorageScreen;
import java.util.List;
@ -56,7 +57,7 @@ public class HardDriveContainerBlock extends Block implements PolymerTexturedBlo
}
public static void register() {
var modId = id(STORAGE_MODEL_ID);
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), BlockModelType.FULL_BLOCK, ServerStorage.HARD_DRIVE_CONTAINER_BLOCK_MODEL_ID));
UseBlockCallback.EVENT.register(HardDriveContainerBlock::onUse);
@ -77,21 +78,9 @@ public class HardDriveContainerBlock extends Block implements PolymerTexturedBlo
if (block instanceof HardDriveContainerBlock) {
if (!world.isClient && !player.isSpectator()) {
if (!player.isSneaking()) {
StorageScreen storageScreen = new StorageScreen((ServerPlayerEntity) player, pos, null);
storageScreen.open();
DriveScreen driveScreen = new DriveScreen((ServerPlayerEntity) player, pos);
driveScreen.open();
} else if (player.getStackInHand(hand).getItem() == Items.WRITTEN_BOOK) {
ItemStack book = player.getStackInHand(hand);
StorageBlockEntity storageBlockEntity = (StorageBlockEntity) world.getBlockEntity(pos);
assert storageBlockEntity != null;
List<RawFilteredPair<Text>> generatedContent = generateBookContent(storageBlockEntity.chests.inventory);
book.set(DataComponentTypes.WRITTEN_BOOK_CONTENT, new WrittenBookContentComponent(
RawFilteredPair.of("Item Listing"),
player.getGameProfile().getName(),
0,
generatedContent,
false
));
} else {
return ActionResult.PASS;
}
@ -104,6 +93,6 @@ public class HardDriveContainerBlock extends Block implements PolymerTexturedBlo
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new StorageBlockEntity(pos, state);
return new HardDriveContainerBlockEntity(pos, state);
}
}

@ -4,11 +4,9 @@ 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.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;
@ -51,13 +49,6 @@ public class StorageBlock extends Block implements PolymerTexturedBlock, BlockEn
STORAGE_BLOCK = Registry.register(Registries.BLOCK, modId,
new StorageBlock(AbstractBlock.Settings.copy(Blocks.WHITE_WOOL), BlockModelType.FULL_BLOCK, ServerStorage.STORAGE_MODEL_ID));
UseBlockCallback.EVENT.register(StorageBlock::onUse);
STORAGE_BLOCK_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE,
modId,
BlockEntityType.Builder.create(StorageBlockEntity::new, STORAGE_BLOCK).build(null)
);
PolymerBlockUtils.registerBlockEntity(STORAGE_BLOCK_ENTITY);
}
private static ActionResult onUse(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {

@ -15,10 +15,10 @@ import systems.brn.server_storage.ServerStorage;
import static systems.brn.server_storage.ServerStorage.*;
public class HardDriveContainerBlockItem extends BlockItem implements PolymerItem {
public class SimpleBlockItem extends BlockItem implements PolymerItem {
private final PolymerModelData polymerModel;
public HardDriveContainerBlockItem(Item.Settings settings, Block block, Identifier identifier) {
public SimpleBlockItem(Item.Settings settings, Block block, Identifier identifier) {
super(block, settings);
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier);
}
@ -33,9 +33,9 @@ public class HardDriveContainerBlockItem extends BlockItem implements PolymerIte
return this.polymerModel.value();
}
public static void register() {
Identifier identifier= id(ServerStorage.HARD_DRIVE_CONTAINER_BLOCK_MODEL_ID);
Item item = Registry.register(Registries.ITEM, identifier, new HardDriveContainerBlockItem(new Item.Settings(), HARD_DRIVE_CONTAINER_BLOCK, identifier));
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));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
}
}

@ -13,14 +13,14 @@ import net.minecraft.registry.Registry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import systems.brn.server_storage.ServerStorage;
import static systems.brn.server_storage.ServerStorage.id;
import static systems.brn.server_storage.ServerStorage.tiers;
public class HardDriveItem extends Item implements PolymerItem {
public class SimpleItem extends Item implements PolymerItem {
private final PolymerModelData polymerModel;
public HardDriveItem(Settings settings, Identifier identifier) {
public SimpleItem(Settings settings, Identifier identifier) {
super(settings);
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier);
}
@ -35,9 +35,9 @@ public class HardDriveItem extends Item implements PolymerItem {
return this.polymerModel.value();
}
public static void register() {
Identifier identifier = id(ServerStorage.HARD_DRIVE_MODEL_ID);
Item item = Registry.register(Registries.ITEM, identifier, new HardDriveItem(new Settings(), identifier));
public static void register(String name) {
Identifier identifier = id(name);
Item item = Registry.register(Registries.ITEM, identifier, new SimpleItem(new Settings(), identifier));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
}
}

@ -1,42 +0,0 @@
package systems.brn.server_storage.items;
import eu.pb4.polymer.core.api.item.PolymerItem;
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.block.Block;
import net.minecraft.item.*;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import systems.brn.server_storage.ServerStorage;
import static systems.brn.server_storage.ServerStorage.STORAGE_BLOCK;
import static systems.brn.server_storage.ServerStorage.id;
public class StorageBlockItem extends BlockItem implements PolymerItem {
private final PolymerModelData polymerModel;
public StorageBlockItem(Settings settings, Block block, Identifier identifier) {
super(block, settings);
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, identifier);
}
@Override
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
return this.polymerModel.item();
}
@Override
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
return this.polymerModel.value();
}
public static void register() {
Identifier identifier = id(ServerStorage.STORAGE_MODEL_ID);
Item item = Registry.register(Registries.ITEM, identifier, new StorageBlockItem(new Item.Settings(), STORAGE_BLOCK, identifier));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> content.add(item));
}
}

@ -0,0 +1,31 @@
package systems.brn.server_storage.items;
import eu.pb4.polymer.core.api.item.PolymerItem;
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import static systems.brn.server_storage.ServerStorage.id;
import static systems.brn.server_storage.ServerStorage.tiers;
public class TieredItem extends SimpleItem implements PolymerItem {
public TieredItem(Item.Settings settings, Identifier identifier) {
super(settings, identifier);
}
public static void register(String name) {
for (String tier : tiers) {
SimpleItem.register(tier + "_" + name);
}
}
}

@ -0,0 +1,14 @@
package systems.brn.server_storage.screens;
import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
public class DriveScreen extends SimpleGui {
BlockPos pos;
public DriveScreen(ServerPlayerEntity player, BlockPos pos) {
super(ScreenHandlerType.HOPPER, player, false);
this.pos = pos;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 B

After

Width:  |  Height:  |  Size: 414 B

@ -1,5 +1,23 @@
{
"block.serverstorage.storage": "Chest storage controller",
"block.serverstorage.drive": "Hard drive",
"block.serverstorage.drive_container": "Hard drive container"
"block.serverstorage.storage": "Networked storage interface",
"block.serverstorage.drive_container": "Hard drive container",
"item.serverstorage.drive_casing": "Hard drive casing",
"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.golden_drive": "Golden hard drive",
"item.serverstorage.golden_head": "Golden hard drive head",
"item.serverstorage.golden_platter": "Golden hard drive platter",
"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"
}

@ -0,0 +1,7 @@
{
"parent": "block/orientable_vertical",
"textures": {
"front": "serverstorage:block/drive_container_front",
"side": "serverstorage:block/drive_container_side"
}
}

@ -0,0 +1,12 @@
{
"parent": "block/orientable_with_bottom",
"textures": {
"front": "serverstorage:block/controller_front",
"side": "serverstorage:block/controller_left",
"top": "serverstorage:block/controller_top",
"bottom": "serverstorage:block/controller_bottom",
"east": "serverstorage:block/controller_right",
"south": "serverstorage:block/controller_back",
"west": "serverstorage:block/controller_left"
}
}

@ -1,6 +0,0 @@
{
"parent": "block/cube_all",
"textures": {
"all": "serverstorage:block/drive_container"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/drive_diamond"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/head_diamond"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/platter_diamond"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/drive_casing"
}
}

@ -1,3 +1,3 @@
{
"parent": "storage:block/drive_container"
"parent": "serverstorage:block/drive_container"
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/drive_gold"
}
}

@ -1,6 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "minecraft:item/drive"
"layer0": "serverstorage:item/head_gold"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/platter_gold"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/drive_iron"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/head_iron"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/platter_iron"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/drive_netherite"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/head_netherite"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "serverstorage:item/platter_netherite"
}
}

@ -1,3 +1,3 @@
{
"parent": "storage:block/storage"
"parent": "serverstorage:block/storage"
}

@ -1,6 +0,0 @@
{
"parent": "block/cube_all",
"textures": {
"all": "serverstorage:block/storage"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 B

@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "serverstorage:drive_container"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
{
"item": "serverstorage:diamond_head"
},
{
"item": "serverstorage:diamond_platter"
},
{
"item": "serverstorage:drive_casing"
}
],
"result": {
"id": "serverstorage:diamond_drive",
"count": 1
}
}

@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"# ",
"## ",
" ##"
],
"key": {
"#": {
"item": "minecraft:diamond"
}
},
"result": {
"id": "serverstorage:diamond_head",
"count": 1
}
}

@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"###",
"# #",
"###"
],
"key": {
"#": {
"item": "minecraft:diamond"
}
},
"result": {
"id": "serverstorage:diamond_platter",
"count": 1
}
}

@ -0,0 +1,24 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"IRI",
"IPI",
"IRI"
],
"key": {
"I": {
"item": "minecraft:iron_ingot"
},
"R": {
"item": "minecraft:redstone"
},
"P": {
"item": "minecraft:paper"
}
},
"result": {
"id": "serverstorage:drive_casing",
"count": 1
}
}

@ -0,0 +1,27 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"IDR",
"DCD",
"RDI"
],
"key": {
"D": {
"item": "minecraft:diamond"
},
"R": {
"item": "minecraft:redstone"
},
"C": {
"item": "minecraft:chest"
},
"I": {
"item": "minecraft:iron_ingot"
}
},
"result": {
"id": "serverstorage:drive_container",
"count": 1
}
}

@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
{
"item": "serverstorage:golden_head"
},
{
"item": "serverstorage:golden_platter"
},
{
"item": "serverstorage:drive_casing"
}
],
"result": {
"id": "serverstorage:golden_drive",
"count": 1
}
}

@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"# ",
"## ",
" ##"
],
"key": {
"#": {
"item": "minecraft:gold_ingot"
}
},
"result": {
"id": "serverstorage:golden_head",
"count": 1
}
}

@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"###",
"# #",
"###"
],
"key": {
"#": {
"item": "minecraft:gold_ingot"
}
},
"result": {
"id": "serverstorage:golden_platter",
"count": 1
}
}

@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
{
"item": "serverstorage:iron_head"
},
{
"item": "serverstorage:iron_platter"
},
{
"item": "serverstorage:drive_casing"
}
],
"result": {
"id": "serverstorage:iron_drive",
"count": 1
}
}

@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"# ",
"## ",
" ##"
],
"key": {
"#": {
"item": "minecraft:iron_ingot"
}
},
"result": {
"id": "serverstorage:iron_head",
"count": 1
}
}

@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"###",
"# #",
"###"
],
"key": {
"#": {
"item": "minecraft:iron_ingot"
}
},
"result": {
"id": "serverstorage:iron_platter",
"count": 1
}
}

@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
{
"item": "serverstorage:netherite_head"
},
{
"item": "serverstorage:netherite_platter"
},
{
"item": "serverstorage:drive_casing"
}
],
"result": {
"id": "serverstorage:netherite_drive",
"count": 1
}
}

@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"# ",
"## ",
" ##"
],
"key": {
"#": {
"item": "minecraft:netherite_ingot"
}
},
"result": {
"id": "serverstorage:netherite_head",
"count": 1
}
}

@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": [
"###",
"# #",
"###"
],
"key": {
"#": {
"item": "minecraft:netherite_ingot"
}
},
"result": {
"id": "serverstorage:netherite_platter",
"count": 1
}
}