be very afraid

main
Walker Fowlkes 7 months ago
parent 0e21b721bf
commit 10472f0f13

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

@ -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<String> = 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<String> {
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()
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<ClientPlayPacketListener>? = BlockEntityUpdateS2CPacket.create(this);
}
Loading…
Cancel
Save