Don't render terminal while computer is not running.
This commit is contained in:
@@ -51,17 +51,19 @@ public final class TerminalScreen extends Screen {
|
||||
requireNonNull(minecraft).getTextureManager().bindTexture(BACKGROUND);
|
||||
blit(matrixStack, windowLeft, windowTop, 0, 0, windowWidth, windowHeight, TEXTURE_SIZE, TEXTURE_SIZE);
|
||||
|
||||
if (isMouseOverTerminal) {
|
||||
if (isMouseOverTerminal && tileEntity.isRunning()) {
|
||||
requireNonNull(minecraft).getTextureManager().bindTexture(BACKGROUND_TERMINAL_FOCUSED);
|
||||
blit(matrixStack, windowLeft, windowTop, 0, 0, windowWidth, windowHeight, TEXTURE_SIZE, TEXTURE_SIZE);
|
||||
}
|
||||
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
|
||||
final MatrixStack stack = new MatrixStack();
|
||||
stack.translate(windowLeft + TERMINAL_AREA_X, windowTop + TERMINAL_AREA_Y, this.itemRenderer.zLevel);
|
||||
stack.scale(TERMINAL_AREA_WIDTH / (float) terminal.getWidth(), TERMINAL_AREA_HEIGHT / (float) terminal.getHeight(), 1f);
|
||||
terminal.render(stack);
|
||||
if (tileEntity.isRunning()) {
|
||||
final MatrixStack stack = new MatrixStack();
|
||||
stack.translate(windowLeft + TERMINAL_AREA_X, windowTop + TERMINAL_AREA_Y, this.itemRenderer.zLevel);
|
||||
stack.scale(TERMINAL_AREA_WIDTH / (float) terminal.getWidth(), TERMINAL_AREA_HEIGHT / (float) terminal.getHeight(), 1f);
|
||||
terminal.render(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +89,7 @@ public final class TerminalScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(final int keyCode, final int scanCode, final int modifiers) {
|
||||
if (!isMouseOverTerminal && keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
if ((!isMouseOverTerminal || !tileEntity.isRunning()) && keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,41 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
|
||||
final float pixelScale = 1 / 16f;
|
||||
stack.scale(pixelScale, pixelScale, pixelScale);
|
||||
|
||||
if (tileEntity.isRunning()) {
|
||||
renderTerminal(tileEntity, stack, buffer, cameraPosition);
|
||||
}
|
||||
|
||||
stack.translate(0, 0, -0.1f);
|
||||
final Matrix4f matrix = stack.getLast().getMatrix();
|
||||
|
||||
switch (tileEntity.getBusState()) {
|
||||
case SCAN_PENDING:
|
||||
case INCOMPLETE:
|
||||
break;
|
||||
case TOO_COMPLEX:
|
||||
drawPulsingStatus(matrix, buffer, 500);
|
||||
break;
|
||||
case MULTIPLE_CONTROLLERS:
|
||||
drawPulsingStatus(matrix, buffer, 250);
|
||||
break;
|
||||
case READY:
|
||||
switch (tileEntity.getRunState()) {
|
||||
case STOPPED:
|
||||
break;
|
||||
case LOADING_DEVICES:
|
||||
drawPulsingStatus(matrix, buffer, 1000);
|
||||
break;
|
||||
case RUNNING:
|
||||
drawPower(matrix, buffer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
private void renderTerminal(final ComputerTileEntity tileEntity, final MatrixStack stack, final IRenderTypeBuffer buffer, final Vector3d cameraPosition) {
|
||||
// Render terminal content if close enough.
|
||||
if (Vector3d.copyCentered(tileEntity.getPos()).isWithinDistanceOf(cameraPosition, 6f * 6f)) {
|
||||
stack.push();
|
||||
@@ -111,35 +146,6 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
stack.translate(0, 0, -0.1f);
|
||||
final Matrix4f matrix = stack.getLast().getMatrix();
|
||||
|
||||
switch (tileEntity.getBusState()) {
|
||||
case SCAN_PENDING:
|
||||
case INCOMPLETE:
|
||||
break;
|
||||
case TOO_COMPLEX:
|
||||
drawPulsingStatus(matrix, buffer, 500);
|
||||
break;
|
||||
case MULTIPLE_CONTROLLERS:
|
||||
drawPulsingStatus(matrix, buffer, 250);
|
||||
break;
|
||||
case READY:
|
||||
switch (tileEntity.getRunState()) {
|
||||
case STOPPED:
|
||||
break;
|
||||
case LOADING_DEVICES:
|
||||
drawPulsingStatus(matrix, buffer, 1000);
|
||||
break;
|
||||
case RUNNING:
|
||||
drawQuad(matrix, TEXTURE_POWER.getBuffer(buffer, OpenComputersRenderType::getUnlitBlock));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
private void drawPulsingStatus(final Matrix4f matrix, final IRenderTypeBuffer buffer, final int frequency) {
|
||||
@@ -148,6 +154,10 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPower(final Matrix4f matrix, final IRenderTypeBuffer buffer) {
|
||||
drawQuad(matrix, TEXTURE_POWER.getBuffer(buffer, OpenComputersRenderType::getUnlitBlock));
|
||||
}
|
||||
|
||||
private static void drawQuad(final Matrix4f matrix, final IVertexBuilder buffer) {
|
||||
// NB: We may get a SpriteAwareVertexBuilder here. Sadly, its chaining is broken,
|
||||
// because methods may return the underlying vertex builder, so e.g. calling
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.*;
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
public abstract class TileEntityDeviceBusController implements DeviceBusController {
|
||||
public enum State {
|
||||
public enum BusState {
|
||||
SCAN_PENDING,
|
||||
INCOMPLETE,
|
||||
TOO_COMPLEX,
|
||||
@@ -35,7 +35,7 @@ public abstract class TileEntityDeviceBusController implements DeviceBusControll
|
||||
private final HashSet<Device> devices = new HashSet<>();
|
||||
private final HashMap<Device, Set<UUID>> deviceIds = new HashMap<>();
|
||||
|
||||
private State state = State.SCAN_PENDING;
|
||||
private BusState state = BusState.SCAN_PENDING;
|
||||
private int scanDelay;
|
||||
|
||||
protected TileEntityDeviceBusController(final TileEntity tileEntity) {
|
||||
@@ -48,7 +48,7 @@ public abstract class TileEntityDeviceBusController implements DeviceBusControll
|
||||
protected void onDevicesValid() {
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
public BusState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class TileEntityDeviceBusController implements DeviceBusControll
|
||||
deviceIds.clear();
|
||||
|
||||
scanDelay = 0; // scan as soon as possible
|
||||
state = State.SCAN_PENDING;
|
||||
state = BusState.SCAN_PENDING;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,7 +137,7 @@ public abstract class TileEntityDeviceBusController implements DeviceBusControll
|
||||
// If we have an unloaded chunk neighbor we cannot know whether our neighbor in that
|
||||
// chunk would cause a scan once it is loaded, so we'll just retry every so often.
|
||||
scanDelay = INCOMPLETE_RETRY_INTERVAL * TICKS_PER_SECOND;
|
||||
state = State.INCOMPLETE;
|
||||
state = BusState.INCOMPLETE;
|
||||
elements.clear();
|
||||
return;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ public abstract class TileEntityDeviceBusController implements DeviceBusControll
|
||||
if (busPositions.add(edge.position) && busPositions.size() > MAX_BUS_ELEMENT_COUNT) {
|
||||
elements.clear();
|
||||
scanDelay = TOO_COMPLEX_RETRY_INTERVAL * TICKS_PER_SECOND;
|
||||
state = State.TOO_COMPLEX;
|
||||
state = BusState.TOO_COMPLEX;
|
||||
return; // This return is the reason this is not in the ifPresent below.
|
||||
}
|
||||
}
|
||||
@@ -194,13 +194,13 @@ public abstract class TileEntityDeviceBusController implements DeviceBusControll
|
||||
}
|
||||
|
||||
if (hasMultipleControllers) {
|
||||
state = State.MULTIPLE_CONTROLLERS;
|
||||
state = BusState.MULTIPLE_CONTROLLERS;
|
||||
return;
|
||||
}
|
||||
|
||||
scanDevices();
|
||||
|
||||
state = State.READY;
|
||||
state = BusState.READY;
|
||||
}
|
||||
|
||||
private static final class ScanEdge {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.function.Supplier;
|
||||
|
||||
public class ComputerBusStateMessage {
|
||||
private BlockPos pos;
|
||||
private TileEntityDeviceBusController.State busState;
|
||||
private TileEntityDeviceBusController.BusState busState;
|
||||
|
||||
public ComputerBusStateMessage(final ComputerTileEntity tileEntity) {
|
||||
this.pos = tileEntity.getPos();
|
||||
@@ -30,7 +30,7 @@ public class ComputerBusStateMessage {
|
||||
|
||||
public void fromBytes(final PacketBuffer buffer) {
|
||||
pos = buffer.readBlockPos();
|
||||
busState = buffer.readEnumValue(TileEntityDeviceBusController.State.class);
|
||||
busState = buffer.readEnumValue(TileEntityDeviceBusController.BusState.class);
|
||||
}
|
||||
|
||||
public static void toBytes(final ComputerBusStateMessage message, final PacketBuffer buffer) {
|
||||
|
||||
@@ -73,7 +73,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
|
||||
private Chunk chunk;
|
||||
private final TileEntityDeviceBusController busController;
|
||||
private TileEntityDeviceBusController.State busState;
|
||||
private TileEntityDeviceBusController.BusState busState;
|
||||
private RunState runState;
|
||||
private int loadDevicesDelay;
|
||||
@Nullable private BlobStorage.JobHandle ramJobHandle;
|
||||
@@ -94,7 +94,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
|
||||
busElement = new BusElement();
|
||||
busController = new BusController();
|
||||
busState = TileEntityDeviceBusController.State.SCAN_PENDING;
|
||||
busState = TileEntityDeviceBusController.BusState.SCAN_PENDING;
|
||||
runState = RunState.STOPPED;
|
||||
|
||||
terminal = new Terminal();
|
||||
@@ -134,7 +134,12 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
stopRunnerAndUnloadDevices();
|
||||
}
|
||||
|
||||
public TileEntityDeviceBusController.State getBusState() {
|
||||
public boolean isRunning() {
|
||||
return getBusState() == TileEntityDeviceBusController.BusState.READY &&
|
||||
getRunState() == RunState.RUNNING;
|
||||
}
|
||||
|
||||
public TileEntityDeviceBusController.BusState getBusState() {
|
||||
return busState;
|
||||
}
|
||||
|
||||
@@ -155,7 +160,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void setBusStateClient(final TileEntityDeviceBusController.State value) {
|
||||
public void setBusStateClient(final TileEntityDeviceBusController.BusState value) {
|
||||
final World world = getWorld();
|
||||
if (world != null && world.isRemote()) {
|
||||
busState = value;
|
||||
@@ -180,7 +185,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
|
||||
busController.scan();
|
||||
setBusState(busController.getState());
|
||||
if (busState != TileEntityDeviceBusController.State.READY) {
|
||||
if (busState != TileEntityDeviceBusController.BusState.READY) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -264,7 +269,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
super.handleUpdateTag(state, tag);
|
||||
|
||||
NBTSerialization.deserialize(tag.getCompound(TERMINAL_NBT_TAG_NAME), terminal);
|
||||
busState = TileEntityDeviceBusController.State.values()[tag.getInt(BUS_STATE_NBT_TAG_NAME)];
|
||||
busState = TileEntityDeviceBusController.BusState.values()[tag.getInt(BUS_STATE_NBT_TAG_NAME)];
|
||||
runState = RunState.values()[tag.getInt(RUN_STATE_NBT_TAG_NAME)];
|
||||
}
|
||||
|
||||
@@ -395,7 +400,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic
|
||||
virtualMachine.vmAdapter.unload();
|
||||
}
|
||||
|
||||
private void setBusState(final TileEntityDeviceBusController.State value) {
|
||||
private void setBusState(final TileEntityDeviceBusController.BusState value) {
|
||||
if (value == busState) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ public class DeviceBusTests {
|
||||
@Test
|
||||
public void scanPendingWhenTileEntityNotLoaded() {
|
||||
busController.scan();
|
||||
assertEquals(TileEntityDeviceBusController.State.INCOMPLETE, busController.getState());
|
||||
assertEquals(TileEntityDeviceBusController.BusState.INCOMPLETE, busController.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scanCompletesWhenNoNeighbors() {
|
||||
when(world.chunkExists(anyInt(), anyInt())).thenReturn(true);
|
||||
busController.scan();
|
||||
assertEquals(TileEntityDeviceBusController.State.READY, busController.getState());
|
||||
assertEquals(TileEntityDeviceBusController.BusState.READY, busController.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +83,7 @@ public class DeviceBusTests {
|
||||
when(busControllerBusElement.getLocalDevices()).thenReturn(singletonList(device));
|
||||
|
||||
busController.scan();
|
||||
assertEquals(TileEntityDeviceBusController.State.READY, busController.getState());
|
||||
assertEquals(TileEntityDeviceBusController.BusState.READY, busController.getState());
|
||||
|
||||
verify(busControllerBusElement).addController(busController);
|
||||
assertTrue(busController.getDevices().contains(device));
|
||||
@@ -97,7 +97,7 @@ public class DeviceBusTests {
|
||||
final DeviceBusElement busElement2 = mockBusElement(CONTROLLER_POS.west().west());
|
||||
|
||||
busController.scan();
|
||||
assertEquals(TileEntityDeviceBusController.State.READY, busController.getState());
|
||||
assertEquals(TileEntityDeviceBusController.BusState.READY, busController.getState());
|
||||
|
||||
verify(busElement1).addController(busController);
|
||||
verify(busElement2).addController(busController);
|
||||
|
||||
Reference in New Issue
Block a user