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

View File

@@ -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();

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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));
}
}

View File

@@ -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));
}
}

View File

@@ -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));
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}