From 1e611348b847576b7c53d3a921303e3825fda1c8 Mon Sep 17 00:00:00 2001 From: Astoria Date: Sat, 13 Apr 2024 13:41:40 -0500 Subject: [PATCH] Floppies work! Inserting is a bit jank and the disk drives state is NOT FULLY SAVED. --- .../net/brokenmoon/redcontrol/RedControl.java | 50 +++++++++++++++++- .../redcontrol/blockentities/DriveEntity.java | 18 ++++++- .../redcontrol/blocks/CpuBlock.java | 1 + .../assets/redcontrol/lang/en_us.json | 1 + .../models/item/basic_floppy_disk.json | 6 +++ .../redcontrol/models/item/floppy_disk.json | 11 ++++ .../models/item/read_only_floppy_disk.json | 6 +++ .../models/item/slideshow_floppy_disk.json | 6 +++ .../textures/item/basic_floppy_disk.png | Bin 271 -> 270 bytes .../textures/item/read_only_floppy_disk.png | Bin 0 -> 235 bytes .../textures/item/slideshow_floppy_disk.png | Bin 303 -> 302 bytes 11 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/assets/redcontrol/models/item/basic_floppy_disk.json create mode 100644 src/main/resources/assets/redcontrol/models/item/floppy_disk.json create mode 100644 src/main/resources/assets/redcontrol/models/item/read_only_floppy_disk.json create mode 100644 src/main/resources/assets/redcontrol/models/item/slideshow_floppy_disk.json create mode 100644 src/main/resources/assets/redcontrol/textures/item/read_only_floppy_disk.png diff --git a/src/main/java/net/brokenmoon/redcontrol/RedControl.java b/src/main/java/net/brokenmoon/redcontrol/RedControl.java index ff0d464..b543673 100644 --- a/src/main/java/net/brokenmoon/redcontrol/RedControl.java +++ b/src/main/java/net/brokenmoon/redcontrol/RedControl.java @@ -10,6 +10,7 @@ import net.brokenmoon.redcontrol.item.FloppyDisk; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; +import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; @@ -19,11 +20,15 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.Registry; import net.minecraft.registry.Registries; import net.minecraft.resource.Resource; import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceType; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import org.slf4j.Logger; @@ -47,14 +52,54 @@ public class RedControl implements ModInitializer { //Items public static final FloppyDisk FLOPPY_ITEM = new FloppyDisk(new FabricItemSettings().maxCount(1)); + public static final Item SQUEAKY_HAMMER = new Item(new FabricItemSettings()); + + //Item Stacks + public static final ItemStack BASIC_DISK = new ItemStack(FLOPPY_ITEM); + public static final NbtCompound BASIC_NBT = new NbtCompound(); + + public static final ItemStack SLIDESHOW_DISK = new ItemStack(FLOPPY_ITEM); + public static final NbtCompound SLIDESHOW_NBT = new NbtCompound(); + + //Item group + public static final ItemGroup ITEM_GROUP = FabricItemGroup.builder() + .icon(() -> new ItemStack(CPU)) + .displayName(Text.translatable("itemGroup.redControl.group")) + .entries(((displayContext, entries) -> { + //Peripherals + entries.add(CPU); + entries.add(TERMINAL); + entries.add(DRIVE); + + //Tools + entries.add(SQUEAKY_HAMMER); + + //Disks + //Blank + entries.add(FLOPPY_ITEM); + //Basic + BASIC_NBT.putString("uri", "img://basic.img"); + BASIC_NBT.putString("serial", "BASIC"); + BASIC_NBT.putInt("CustomModelData", 1); + BASIC_DISK.setNbt(BASIC_NBT); + BASIC_DISK.setCustomName(Text.literal("Basic boot disk")); + entries.add(BASIC_DISK); + + //Slideshow + SLIDESHOW_NBT.putString("uri", "img://slideshow.img"); + SLIDESHOW_NBT.putString("serial", "SLIDESHOW"); + SLIDESHOW_NBT.putInt("CustomModelData", 2); + SLIDESHOW_DISK.setNbt(SLIDESHOW_NBT); + SLIDESHOW_DISK.setCustomName(Text.literal("Slideshow disk")); + entries.add(SLIDESHOW_DISK); + })) + .build(); //Block Entities public static final BlockEntityType CPU_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, modloc("cpu_block_entity"), FabricBlockEntityTypeBuilder.create(CpuEntity::new, CPU).build()); public static final BlockEntityType TERMINAL_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, modloc("monitor_block_entity"), FabricBlockEntityTypeBuilder.create(TerminalEntity::new, TERMINAL).build()); public static final BlockEntityType DRIVE_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, modloc("drive_block_entity"), FabricBlockEntityTypeBuilder.create(DriveEntity::new, DRIVE).build()); - public static final Item SQUEAKY_HAMMER = new Item(new FabricItemSettings()); - @Override public void onInitialize() { // This code runs as soon as Minecraft is in a mod-load-ready state. @@ -92,6 +137,7 @@ public class RedControl implements ModInitializer { Registry.register(Registries.ITEM, modloc("disk_drive"), new BlockItem(DRIVE, new FabricItemSettings())); Registry.register(Registries.ITEM, modloc("squeaky_hammer"), SQUEAKY_HAMMER); Registry.register(Registries.ITEM, modloc("floppy_disk"), FLOPPY_ITEM); + Registry.register(Registries.ITEM_GROUP, modloc("item_group"), ITEM_GROUP); //Packets ServerPlayNetworking.registerGlobalReceiver(RedControlNetworking.CPU_START, ((server, player, handler, buf, responseSender) -> server.execute(() -> { diff --git a/src/main/java/net/brokenmoon/redcontrol/blockentities/DriveEntity.java b/src/main/java/net/brokenmoon/redcontrol/blockentities/DriveEntity.java index 1c511d5..1721cb3 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blockentities/DriveEntity.java +++ b/src/main/java/net/brokenmoon/redcontrol/blockentities/DriveEntity.java @@ -6,6 +6,8 @@ import net.brokenmoon.redcontrol.api.DriveFactory; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; @@ -87,6 +89,7 @@ public class DriveEntity extends Peripheral{ this.buffer.position(0); byte[] diskName = new byte[SECTOR_SIZE]; this.buffer.get(diskName); + this.disk.setCustomName(Text.literal(new String(diskName).trim())); this.driver.writeDiskName(diskName); this.command = 0; break; @@ -147,8 +150,21 @@ public class DriveEntity extends Peripheral{ disk = player.getStackInHand(hand).copy(); player.setStackInHand(hand, ItemStack.EMPTY); RedControl.LOGGER.info("Loading with " + disk.getNbt().get("uri")); - this.driver = DriveFactory.INSTANCE.createDriver(URI.create(disk.getNbt().getString("uri")), String.valueOf(disk.getName()),disk.getNbt().getString("serial")); + this.driver = DriveFactory.INSTANCE.createDriver(URI.create(disk.getNbt().getString("uri")), String.valueOf(disk.getName()), disk.getNbt().getString("serial")); this.buffer = ByteBuffer.allocateDirect(SECTOR_SIZE); return ActionResult.SUCCESS; } + + @Override + protected void writeNbt(NbtCompound nbt) { + //SUPER DUPER NOT DONE TODO: FINISH THIS. + disk.writeNbt(nbt); + super.writeNbt(nbt); + } + + @Override + public void readNbt(NbtCompound nbt) { + disk = ItemStack.fromNbt(nbt); + super.readNbt(nbt); + } } diff --git a/src/main/java/net/brokenmoon/redcontrol/blocks/CpuBlock.java b/src/main/java/net/brokenmoon/redcontrol/blocks/CpuBlock.java index 05581ed..858a54c 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blocks/CpuBlock.java +++ b/src/main/java/net/brokenmoon/redcontrol/blocks/CpuBlock.java @@ -53,6 +53,7 @@ public class CpuBlock extends NetworkCarrier { player.sendMessage(Text.literal(" " + Integer.toHexString(peripheral.core.cpu.getBus().getRedBus().hashCode())), false); player.sendMessage(Text.literal(" " + Integer.toHexString(peripheral.i)), false); player.sendMessage(Text.literal(" " + peripheral.core.isWaitingOnInterrupt()), false); + player.sendMessage(Text.literal(" " + peripheral.core.cpu.getCpuState().toTraceEvent())); } PacketByteBuf byteBuf = PacketByteBufs.create(); byteBuf.writeBlockPos(pos); diff --git a/src/main/resources/assets/redcontrol/lang/en_us.json b/src/main/resources/assets/redcontrol/lang/en_us.json index e81b33c..71b912a 100644 --- a/src/main/resources/assets/redcontrol/lang/en_us.json +++ b/src/main/resources/assets/redcontrol/lang/en_us.json @@ -1,5 +1,6 @@ { "item.redcontrol.squeaky_hammer": "Squeaky Hammer", + "item.redcontrol.floppy_disk": "Floppy Disk", "block.redcontrol.cpu": "Central Processing Unit", "block.redcontrol.disk_drive": "Disk drive", "block.redcontrol.monitor": "Monitor" diff --git a/src/main/resources/assets/redcontrol/models/item/basic_floppy_disk.json b/src/main/resources/assets/redcontrol/models/item/basic_floppy_disk.json new file mode 100644 index 0000000..0967b36 --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/item/basic_floppy_disk.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "redcontrol:item/basic_floppy_disk" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/item/floppy_disk.json b/src/main/resources/assets/redcontrol/models/item/floppy_disk.json new file mode 100644 index 0000000..60f8e2f --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/item/floppy_disk.json @@ -0,0 +1,11 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "redcontrol:item/floppy_disk" + }, + "overrides": [ + { "predicate": { "custom_model_data": 1}, "model": "redcontrol:item/basic_floppy_disk" }, + { "predicate": { "custom_model_data": 2}, "model": "redcontrol:item/slideshow_floppy_disk" }, + { "predicate": { "custom_model_data": 3}, "model": "redcontrol:item/read_only_floppy_disk" } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/item/read_only_floppy_disk.json b/src/main/resources/assets/redcontrol/models/item/read_only_floppy_disk.json new file mode 100644 index 0000000..331acb0 --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/item/read_only_floppy_disk.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "redcontrol:item/read_only_floppy_disk" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/item/slideshow_floppy_disk.json b/src/main/resources/assets/redcontrol/models/item/slideshow_floppy_disk.json new file mode 100644 index 0000000..20e1a1e --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/item/slideshow_floppy_disk.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "redcontrol:item/slideshow_floppy_disk" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/textures/item/basic_floppy_disk.png b/src/main/resources/assets/redcontrol/textures/item/basic_floppy_disk.png index 3cd75aa411a97f949a654316b586bd2412e2e5a0..6ebfaa3137844815836c5b950bb013df31f50172 100644 GIT binary patch delta 229 zcmV~0*(TZF@MNOL_t(IjlGaD4uU`sMc=LjZHxrzB{W=sV{jKcFT)wAxroi) zz=9AG3xycgMnIDVMWR2M>}L1p&zli|W`-<)!|}w%l3bbw&$h6o;CyS?ZzWYxuykFj zqM%fYmFIEIb9QkIfCR85)LOH)7Sv4-R4VmyI$=nu6iyg+9$o=xt*1{Rgy=^YQ;Xhq zH4;p2|0Fr~nWPy>n!OFtrb^PRBYWJ9HA?WQ2Gf%?Ye{tAM@G+Yml*gFfggPzFq_~n f0YghPy&JuENiJd6tx7TR00000NkvXXu0mjfzEWgM delta 230 zcmVAl0at!Zc=Vfw+)VYYw z-oQdaz(OOEu`!CW{stWwcA0&={pJavbSMk3T&)>d!>(xv1503p?Xh7oHPmHEe=?yi zODg9WgdzLQhS_`$fB^^$98?+F9*5=%R5^EZj+2DSImSuSN?$|(RsDPm5djeUO4y>e zzupn3&@n{w>@mv=vb=a{qQ1`Z;zD-5d;2NDyYpkaq>R+b)F>O-8YK_ngp1H9K0pG6IYw{{Ip&maA@{}k~`-6 z6{5xG7Bg^!&H6F%!10#;%)ljAE*<}(RDJDg&bNe#35#Z|n|&`Vy)JvvOWkGL-!iS{ j{HJ7)p0qZ8ZY_hkqwAk#HEPK~2QzrO`njxgN@xNA#yeZJ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/redcontrol/textures/item/slideshow_floppy_disk.png b/src/main/resources/assets/redcontrol/textures/item/slideshow_floppy_disk.png index 13c4edc53f16235bb34a5cbd52e6f526453c9208..e6f9888ca4fb0da7ec99ad73e7f78d851afecdea 100644 GIT binary patch delta 261 zcmV+g0s8*000T=~N1gm>EzX#fQN9`)SY<_9h6}77XST^(BO$3NY z_=~5H1pu{sVQ9v!{%-KFf1yj(#4MXR_jZE4id(Z5!HIbVr4B9gq9iZMqb3rnyeM~M zKYg$c5}c||_q-^7NhD3O;LT-2Op}Z>$^LF|Ho?CbbcGn22XDUt0my2l{H`E500000 LNkvXXu0mjf^n-hs delta 262 zcmV+h0r~!}0L{nN1T~+K;dk{*iHb@09Jz+!I=R*d>h&XPvdKXe1FoeYZ_kzuxuAQic)}x z#8a%^?g4206Jt9)*sm_G0hH;==WN2VT`+SuxM6Z|+d>pQOVnM@qO2&&>PHcYO;J{R zXWKnGoeqABqv}Oj?VL!K=26bymYAhES(=|N(A&Yk2plUhc8_wu0MT`8rhPVn<^TWy M07*qoM6N<$f-Pxu!vFvP