Almost good, world is null
parent
520c9fe3c2
commit
30d9aaeffb
@ -1,28 +1,63 @@
|
||||
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 net.brokenmoon.redcontrol.blocks.NetworkCarrier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
public class RCBus {
|
||||
|
||||
public class RCBus extends Bus {
|
||||
boolean isValid = false;
|
||||
|
||||
boolean isValid = true;
|
||||
private RedBus redBus;
|
||||
|
||||
Peripheral[] peripherals = new Peripheral[256];
|
||||
public RCBus(RedBus redBus) {
|
||||
super(redBus);
|
||||
this.redBus = redBus;
|
||||
}
|
||||
|
||||
public void write(int address, int data) {
|
||||
public void write(int address, int data, World world, BlockPos pos) {
|
||||
if(isValid) {
|
||||
Peripheral peripheral = peripherals[address];
|
||||
peripheral.getBus().write(address, data);
|
||||
peripheral.getBus().getRedBus().write(address, data);
|
||||
} else {
|
||||
generateBus(world, pos);
|
||||
write(address, data, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public int read(int address, boolean cpuAccess) {
|
||||
public int read(int address, boolean cpuAccess, World world, BlockPos pos) {
|
||||
if(isValid) {
|
||||
Peripheral peripheral = peripherals[address];
|
||||
return peripheral.getBus().getRedBus().read(address, cpuAccess) & 0xff;
|
||||
} else {
|
||||
generateBus(world, pos);
|
||||
return read(address, cpuAccess, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void generateBus(World world, BlockPos pos){
|
||||
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBus(world, pos);
|
||||
}
|
||||
|
||||
public RedBus getRedBus() {
|
||||
return redBus;
|
||||
}
|
||||
|
||||
public void setRedBus(RedBus redBus) {
|
||||
this.redBus = redBus;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
this.redBus.updatePeripheral();
|
||||
}
|
||||
|
||||
public Peripheral[] getPeripherals(){
|
||||
return peripherals;
|
||||
}
|
||||
|
||||
public void setPeripherals(Peripheral[] peripherals){
|
||||
this.peripherals = peripherals;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package net.brokenmoon.redcontrol.api;
|
||||
|
||||
import com.simon816.j65el02.Cpu;
|
||||
|
||||
public class RCCpu extends Cpu {
|
||||
|
||||
private RCBus rcbus;
|
||||
|
||||
public RCCpu() {
|
||||
}
|
||||
|
||||
public RCBus getRCBus() {
|
||||
return rcbus;
|
||||
}
|
||||
|
||||
|
||||
public void setRCBus(RCBus rcbus) {
|
||||
this.rcbus = rcbus;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue