From 520c9fe3c2a852cbd8714ce018eeee0603c9af77 Mon Sep 17 00:00:00 2001 From: Astoria Date: Mon, 8 Apr 2024 14:32:42 -0500 Subject: [PATCH] Bus Progress --- .../net/brokenmoon/redcontrol/api/RCBus.java | 18 +++++++++++++++++ .../redcontrol/blocks/NetworkCarrier.java | 20 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/main/java/net/brokenmoon/redcontrol/api/RCBus.java b/src/main/java/net/brokenmoon/redcontrol/api/RCBus.java index de1d093..51a7456 100644 --- a/src/main/java/net/brokenmoon/redcontrol/api/RCBus.java +++ b/src/main/java/net/brokenmoon/redcontrol/api/RCBus.java @@ -1,10 +1,28 @@ package net.brokenmoon.redcontrol.api; import com.simon816.j65el02.Bus; +import com.simon816.j65el02.device.Device; import com.simon816.j65el02.device.RedBus; +import net.brokenmoon.redcontrol.blockentities.Peripheral; + +import java.util.Arrays; public class RCBus extends Bus { + + boolean isValid = true; + + Peripheral[] peripherals = new Peripheral[256]; public RCBus(RedBus redBus) { super(redBus); } + + public void write(int address, int data) { + Peripheral peripheral = peripherals[address]; + peripheral.getBus().write(address, data); + } + + public int read(int address, boolean cpuAccess) { + Peripheral peripheral = peripherals[address]; + return peripheral.getBus().getRedBus().read(address, cpuAccess) & 0xff; + } } diff --git a/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java b/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java index 9e88006..e17519d 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java +++ b/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java @@ -4,8 +4,12 @@ import net.brokenmoon.redcontrol.api.RCBus; import net.brokenmoon.redcontrol.blockentities.Peripheral; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; public abstract class NetworkCarrier extends Block implements BlockEntityProvider { public NetworkCarrier(Settings settings) { @@ -19,4 +23,20 @@ public abstract class NetworkCarrier extends Block implements BlockEntityProvide public void setBus(World world, BlockPos pos, RCBus bus){ ((Peripheral)world.getBlockEntity(pos)).setBus(bus); } + + @Override + public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { + + } + + @Override + public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + if (state.hasBlockEntity() && !state.isOf(newState.getBlock())) { + world.removeBlockEntity(pos); + } + } + + public void invalidateBus(World world, BlockPos pos){ + + } }