Floppies work! Inserting is a bit jank and the disk drives state is NOT FULLY SAVED.

main
Astoria 7 months ago
parent 9fcbfa755c
commit 1e611348b8

@ -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<CpuEntity> CPU_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, modloc("cpu_block_entity"), FabricBlockEntityTypeBuilder.create(CpuEntity::new, CPU).build());
public static final BlockEntityType<TerminalEntity> TERMINAL_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, modloc("monitor_block_entity"), FabricBlockEntityTypeBuilder.create(TerminalEntity::new, TERMINAL).build());
public static final BlockEntityType<DriveEntity> 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(() -> {

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

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

@ -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"

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "redcontrol:item/basic_floppy_disk"
}
}

@ -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" }
]
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "redcontrol:item/read_only_floppy_disk"
}
}

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "redcontrol:item/slideshow_floppy_disk"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 B

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 303 B

After

Width:  |  Height:  |  Size: 302 B

Loading…
Cancel
Save