|
|
|
@ -2,8 +2,7 @@ package net.brokenmoon.redcontrol.blockentities;
|
|
|
|
|
|
|
|
|
|
import com.simon816.j65el02.device.RedBus;
|
|
|
|
|
import net.brokenmoon.redcontrol.RedControl;
|
|
|
|
|
import net.brokenmoon.redcontrol.api.Emulator;
|
|
|
|
|
import net.brokenmoon.redcontrol.api.RCWorldBus;
|
|
|
|
|
import net.brokenmoon.redcontrol.api.*;
|
|
|
|
|
import net.brokenmoon.redcontrol.blocks.NetworkCarrier;
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
@ -16,7 +15,7 @@ import net.minecraft.util.math.BlockPos;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
|
|
public class CpuEntity extends Peripheral{
|
|
|
|
|
public class CpuEntity extends Peripheral implements CpuControl {
|
|
|
|
|
public int i = 0;
|
|
|
|
|
|
|
|
|
|
public boolean notTicked = true;
|
|
|
|
@ -25,10 +24,13 @@ public class CpuEntity extends Peripheral{
|
|
|
|
|
private int defaultMonitorId = 1;
|
|
|
|
|
private int defaultDriveId = 2;
|
|
|
|
|
|
|
|
|
|
public boolean isRunning = false;
|
|
|
|
|
public boolean isResetting = false;
|
|
|
|
|
public boolean isReset = false;
|
|
|
|
|
private int resetTimer = 20;
|
|
|
|
|
private CpuState state = CpuState.STOPPED;
|
|
|
|
|
@Override
|
|
|
|
|
public CpuState getCpuState() {return state;}
|
|
|
|
|
|
|
|
|
|
private int resetTimer = 40;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CpuEntity(BlockPos pos, BlockState state) {
|
|
|
|
|
super(RedControl.CPU_BLOCK_ENTITY, pos, state, 0);
|
|
|
|
@ -42,18 +44,18 @@ public class CpuEntity extends Peripheral{
|
|
|
|
|
if (be.notTicked) {
|
|
|
|
|
be.notTicked = false;
|
|
|
|
|
}
|
|
|
|
|
if(be.isRunning) {
|
|
|
|
|
if(be.state == CpuState.RUNNING) {
|
|
|
|
|
for (int i = 0; i < 1000; i++)
|
|
|
|
|
be.step();
|
|
|
|
|
} else{
|
|
|
|
|
if (be.isResetting && !be.isReset && be.resetTimer > 0){
|
|
|
|
|
if (be.state == CpuState.RESET && be.resetTimer > 0){
|
|
|
|
|
be.resetTimer--;
|
|
|
|
|
} else {
|
|
|
|
|
be.core = new Emulator(be.getBus().getRedBus());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (be.core.isWaitingOnInterrupt()) {
|
|
|
|
|
be.core.setWaitingOnInterrupt();
|
|
|
|
|
be.core.setWaitingOnInterrupt(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -78,28 +80,20 @@ public class CpuEntity extends Peripheral{
|
|
|
|
|
|
|
|
|
|
public void reset() {
|
|
|
|
|
this.core.reset(this.defaultDriveId, this.defaultMonitorId);
|
|
|
|
|
isRunning = false;
|
|
|
|
|
isResetting = true;
|
|
|
|
|
isReset = false;
|
|
|
|
|
resetTimer = 20;
|
|
|
|
|
state = CpuState.RESET;
|
|
|
|
|
resetTimer = 40;
|
|
|
|
|
markDirty();
|
|
|
|
|
world.updateListeners(pos, this.getCachedState(), this.getCachedState(), Block.NOTIFY_LISTENERS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stop() {
|
|
|
|
|
isRunning = false;
|
|
|
|
|
isResetting = false;
|
|
|
|
|
isReset = false;
|
|
|
|
|
resetTimer = 20;
|
|
|
|
|
state = CpuState.STOPPED;
|
|
|
|
|
markDirty();
|
|
|
|
|
world.updateListeners(pos, this.getCachedState(), this.getCachedState(), Block.NOTIFY_LISTENERS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void start() {
|
|
|
|
|
isRunning = true;
|
|
|
|
|
isResetting = false;
|
|
|
|
|
isReset = false;
|
|
|
|
|
resetTimer = 20;
|
|
|
|
|
state = CpuState.RUNNING;
|
|
|
|
|
markDirty();
|
|
|
|
|
world.updateListeners(pos, this.getCachedState(), this.getCachedState(), Block.NOTIFY_LISTENERS);
|
|
|
|
|
}
|
|
|
|
@ -143,9 +137,7 @@ public class CpuEntity extends Peripheral{
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void writeNbt(NbtCompound nbt) {
|
|
|
|
|
nbt.putBoolean("isRunning", this.isRunning);
|
|
|
|
|
nbt.putBoolean("isResetting", this.isResetting);
|
|
|
|
|
nbt.putBoolean("isReset", this.isReset);
|
|
|
|
|
nbt.putString("state", this.state.toString());
|
|
|
|
|
nbt.putInt("resetTimer", this.resetTimer);
|
|
|
|
|
nbt.putInt("defaultMonitorId", this.defaultMonitorId);
|
|
|
|
|
nbt.putInt("defaultDriveId", this.defaultDriveId);
|
|
|
|
@ -155,9 +147,7 @@ public class CpuEntity extends Peripheral{
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void readNbt(NbtCompound nbt) {
|
|
|
|
|
this.isRunning = nbt.getBoolean("isRunning");
|
|
|
|
|
this.isResetting = nbt.getBoolean("isResetting");
|
|
|
|
|
this.isReset = nbt.getBoolean("isReset");
|
|
|
|
|
this.state = CpuState.valueOf(nbt.getString("state"));
|
|
|
|
|
this.resetTimer = nbt.getInt("resetTimer");
|
|
|
|
|
this.defaultMonitorId = nbt.getInt("defaultMonitorId");
|
|
|
|
|
this.defaultDriveId = nbt.getInt("defaultDriveId");
|
|
|
|
|