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