basic Screen and the networking to open it

main
Walker Fowlkes 7 months ago
parent e48a00d708
commit 18f75240dd

@ -1,10 +1,30 @@
package net.brokenmoon.redcontrol;
import net.brokenmoon.redcontrol.screen.CpuScreen;
import net.brokenmoon.redcontrol.screen.MonitorScreen;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
public class RedControlClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
ClientPlayNetworking.registerGlobalReceiver(
RedControlNetworking.CPUGUI_PACKET_ID, (client, handler, buf, responseSender) -> {
BlockPos blockPos = buf.readBlockPos();
client.execute(() -> {
client.setScreen(new CpuScreen(Text.literal("cpu")));
});
});
ClientPlayNetworking.registerGlobalReceiver(
RedControlNetworking.MONITOR_PACKET_ID, (client, handler, buf, responseSender) -> {
BlockPos blockPos = buf.readBlockPos();
client.execute(() -> {
client.setScreen(new MonitorScreen(Text.literal("monitor")));
});
});
}
}

@ -0,0 +1,17 @@
package net.brokenmoon.redcontrol.screen;
import net.brokenmoon.redcontrol.RedControl;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
public class CpuScreen extends Screen {
public CpuScreen(Text title) {
super(title);
}
@Override
protected void init() {
super.init();
RedControl.LOGGER.info("Created CPU screen");
}
}

@ -0,0 +1,17 @@
package net.brokenmoon.redcontrol.screen;
import net.brokenmoon.redcontrol.RedControl;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
public class MonitorScreen extends Screen {
public MonitorScreen(Text title) {
super(title);
}
@Override
protected void init() {
super.init();
RedControl.LOGGER.info("Opened Monitor Screen");
}
}

@ -0,0 +1,8 @@
package net.brokenmoon.redcontrol;
import net.minecraft.util.Identifier;
public class RedControlNetworking {
public static final Identifier CPUGUI_PACKET_ID = new Identifier("redcontrol", "open_cpu_gui");
public static final Identifier MONITOR_PACKET_ID = new Identifier("redcontrol", "open_monitor");
}

@ -5,9 +5,11 @@ import com.simon816.j65el02.Cpu;
import com.simon816.j65el02.CpuState;
import com.simon816.j65el02.device.Memory;
import com.simon816.j65el02.device.RedBus;
import com.simon816.j65el02.device.RedBusState;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.mixin.BusAccessor;
import net.brokenmoon.redcontrol.mixin.CpuAccessor;
import net.brokenmoon.redcontrol.mixin.MemoryAccessor;
import net.minecraft.nbt.NbtCompound;
import java.io.IOException;
@ -105,14 +107,15 @@ public class Emulator {
nbt.putLong("stepCounter", cpu.getCpuState().stepCounter);
//Redbus state write nbt
nbt.putInt("deviceId", cpu.redBusState.activeDeviceId);
nbt.putInt("offset", cpu.redBusState.offset);
nbt.putInt("memoryWindow", cpu.redBusState.memoryWindow);
nbt.putBoolean("enabled", cpu.redBusState.enabled);
nbt.putBoolean("enableWindow", cpu.redBusState.enableWindow);
RedBusState redBusState = ((CpuAccessor)cpu).getRedBusState();
nbt.putInt("deviceId", redBusState.activeDeviceId);
nbt.putInt("offset", redBusState.offset);
nbt.putInt("memoryWindow", redBusState.memoryWindow);
nbt.putBoolean("enabled", redBusState.enabled);
nbt.putBoolean("enableWindow", redBusState.enableWindow);
//Ram write nbt.
nbt.putByteArray("ramValues", this.ram.getMem());
nbt.putByteArray("ramValues", ((MemoryAccessor)this.ram).getMem());
}
public void readNbt(NbtCompound nbt) {
@ -157,13 +160,14 @@ public class Emulator {
cpu.getCpuState().stepCounter = nbt.getLong("stepCounter");
//Redbus state write nbt
cpu.redBusState.activeDeviceId = nbt.getInt("deviceId");
cpu.redBusState.offset = nbt.getInt("offset");
cpu.redBusState.memoryWindow = nbt.getInt("memoryWindow");
cpu.redBusState.enabled = nbt.getBoolean("enabled");
cpu.redBusState.enableWindow = nbt.getBoolean("enableWindow");
RedBusState redBusState = ((CpuAccessor)cpu).getRedBusState();
redBusState.activeDeviceId = nbt.getInt("deviceId");
redBusState.offset = nbt.getInt("offset");
redBusState.memoryWindow = nbt.getInt("memoryWindow");
redBusState.enabled = nbt.getBoolean("enabled");
redBusState.enableWindow = nbt.getBoolean("enableWindow");
//Ram write nbt.
ram.setMem(nbt.getByteArray("ramValues"));
((MemoryAccessor)ram).setMem(nbt.getByteArray("ramValues"));
}
}

@ -110,6 +110,11 @@ public class CpuEntity extends Peripheral{
return BlockEntityUpdateS2CPacket.create(this);
}
@Override
public NbtCompound toInitialChunkDataNbt() {
return createNbt();
}
@Override
protected void writeNbt(NbtCompound nbt) {
nbt.putBoolean("isRunning", this.isRunning);
@ -133,4 +138,5 @@ public class CpuEntity extends Peripheral{
core.readNbt(nbt);
super.readNbt(nbt);
}
}

@ -3,7 +3,11 @@ package net.brokenmoon.redcontrol.blockentities;
import net.brokenmoon.redcontrol.RedControl;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
public class MonitorEntity extends Peripheral {
@ -258,4 +262,15 @@ public class MonitorEntity extends Peripheral {
super.readNbt(nbt);
}
@Nullable
@Override
public Packet<ClientPlayPacketListener> toUpdatePacket() {
return BlockEntityUpdateS2CPacket.create(this);
}
@Override
public NbtCompound toInitialChunkDataNbt() {
return createNbt();
}
}

@ -3,14 +3,19 @@ package net.brokenmoon.redcontrol.blocks;
import com.mojang.serialization.MapCodec;
import com.simon816.j65el02.Cpu;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.RedControlNetworking;
import net.brokenmoon.redcontrol.blockentities.CpuEntity;
import net.brokenmoon.redcontrol.blockentities.MonitorEntity;
import net.brokenmoon.redcontrol.blockentities.Peripheral;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
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.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
@ -50,6 +55,9 @@ 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);
PacketByteBuf byteBuf = PacketByteBufs.create();
byteBuf.writeBlockPos(pos);
ServerPlayNetworking.send((ServerPlayerEntity) player, RedControlNetworking.CPUGUI_PACKET_ID,byteBuf);
}
return ActionResult.SUCCESS;

@ -1,13 +1,18 @@
package net.brokenmoon.redcontrol.blocks;
import com.mojang.serialization.MapCodec;
import net.brokenmoon.redcontrol.RedControlNetworking;
import net.brokenmoon.redcontrol.blockentities.MonitorEntity;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
@ -39,9 +44,12 @@ public class MonitorBlock extends NetworkCarrier {
MonitorEntity monitor = (MonitorEntity) world.getBlockEntity(pos);
player.sendMessage(Text.literal(String.valueOf(monitor.getBus().hashCode())), false);
String[] text = monitor.getText();
for(int i = 0; i < text.length; i++){
player.sendMessage(Text.literal(text[i]), false);
for (String s : text) {
player.sendMessage(Text.literal(s), false);
}
PacketByteBuf byteBuf = PacketByteBufs.create();
byteBuf.writeBlockPos(pos);
ServerPlayNetworking.send((ServerPlayerEntity) player, RedControlNetworking.MONITOR_PACKET_ID,byteBuf);
}
return ActionResult.SUCCESS;

@ -0,0 +1,13 @@
package net.brokenmoon.redcontrol.mixin;
import com.simon816.j65el02.device.Memory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(Memory.class)
public interface MemoryAccessor {
@Accessor("mem")
byte[] getMem();
@Accessor("mem")
void setMem(byte[] mem);
}

@ -6,6 +6,7 @@
"BusAccessor",
"CpuAccessor",
"ExampleMixin",
"MemoryAccessor",
"RedBusAccessor"
],
"injectors": {

Loading…
Cancel
Save