From 10472f0f136d17dc7194918d69363feb6637a55f Mon Sep 17 00:00:00 2001 From: Walker Fowlkes Date: Fri, 12 Apr 2024 18:48:18 -0700 Subject: [PATCH] be very afraid --- .../redcontrol/blockentities/CpuEntity.java | 3 ++ .../brokenmoon/redcontrol/blocks/Terminal.kt | 41 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java b/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java index 7a9bfc5..e2d19c5 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java +++ b/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java @@ -81,6 +81,7 @@ public class CpuEntity extends Peripheral{ isResetting = true; isReset = false; resetTimer = 5; + markDirty(); world.updateListeners(pos, this.getCachedState(), this.getCachedState(), Block.NOTIFY_LISTENERS); } @@ -88,6 +89,7 @@ public class CpuEntity extends Peripheral{ isRunning = false; isResetting = false; isReset = false; + markDirty(); world.updateListeners(pos, this.getCachedState(), this.getCachedState(), Block.NOTIFY_LISTENERS); } @@ -95,6 +97,7 @@ public class CpuEntity extends Peripheral{ isRunning = true; isResetting = false; isReset = false; + markDirty(); world.updateListeners(pos, this.getCachedState(), this.getCachedState(), Block.NOTIFY_LISTENERS); } diff --git a/src/main/java/net/brokenmoon/redcontrol/blocks/Terminal.kt b/src/main/java/net/brokenmoon/redcontrol/blocks/Terminal.kt index 63b7ec4..87d7a03 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blocks/Terminal.kt +++ b/src/main/java/net/brokenmoon/redcontrol/blocks/Terminal.kt @@ -7,11 +7,16 @@ import net.brokenmoon.redcontrol.blockentities.Peripheral import net.brokenmoon.redcontrol.util.unsigned 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.BlockState import net.minecraft.block.BlockWithEntity import net.minecraft.entity.player.PlayerEntity 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.server.network.ServerPlayerEntity +import net.minecraft.text.Text import net.minecraft.util.ActionResult import net.minecraft.util.ActionResult.FAIL import net.minecraft.util.ActionResult.SUCCESS @@ -26,8 +31,16 @@ class TerminalBlock(settings: Settings) : NetworkCarrier(settings) { @Suppress("OVERRIDE_DEPRECATION") override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hit: BlockHitResult): ActionResult { - if (world.getBlockEntity(pos) !is TerminalEntity) return FAIL + val monitor = world.getBlockEntity(pos) as? TerminalEntity?: return FAIL if (!world.isClient) { + if (player.getStackInHand(hand).item === RedControl.SQUEAKY_HAMMER) { + super.onUse(state, world, pos, player, hand, hit) + player.sendMessage(Text.literal(java.lang.String.valueOf(monitor.bus.hashCode())), false) + val text: Array = monitor.getText() + for (s in text) { + player.sendMessage(Text.literal(s), false) + } + } val bbuf = PacketByteBufs.create() bbuf.writeBlockPos(pos) ServerPlayNetworking.send(player as ServerPlayerEntity,RedControlNetworking.MONITOR_PACKET_ID,bbuf) @@ -68,6 +81,18 @@ class TerminalEntity(pos: BlockPos, state: BlockState) : Peripheral(RedControl.T var char = 0 + fun getText(): Array { + val l = Array(80) { _ -> "" } + for (y in 0 until 50) { + var temp = "" + for (x in 0 until 80) { + temp += Char(screen[y*80+x].toUShort()) + } + l[y] = temp + } + return l + } + fun pushKey(byte: Byte): Boolean { return if ((kbp + 1) % 16 != kbs) { kb[kbp] = byte @@ -100,7 +125,11 @@ class TerminalEntity(pos: BlockPos, state: BlockState) : Peripheral(RedControl.T else -> error = true } - if (data.command in 1..4) world?.updateListeners(pos, cachedState, cachedState, 3) + if (data.command in 1..4) { + RedControl.LOGGER.info("{}",data.command) + markDirty() + world?.updateListeners(pos, cachedState, cachedState, Block.NOTIFY_LISTENERS) + } data.command = if (error) -1 else 0 } @@ -152,9 +181,10 @@ class TerminalEntity(pos: BlockPos, state: BlockState) : Peripheral(RedControl.T } val needsClientUpdate = at.unsigned in setOf(0x01, 0x02, 0x03) + (0x10..0x67) - if (needsClientUpdate) - getWorld()?.updateListeners(getPos(), cachedState, cachedState, 3) - markDirty() + markDirty() + if (needsClientUpdate) { + getWorld()?.updateListeners(getPos(), cachedState, cachedState, Block.NOTIFY_LISTENERS) + } } override fun toInitialChunkDataNbt(): NbtCompound { @@ -217,4 +247,5 @@ class TerminalEntity(pos: BlockPos, state: BlockState) : Peripheral(RedControl.T } } + override fun toUpdatePacket(): Packet? = BlockEntityUpdateS2CPacket.create(this); } \ No newline at end of file