Merge pull request #962 from CookieNick/mc1.15/paused-sequenced-gearshift

Added the 'Paused' instruction for sequenced gearshift
This commit is contained in:
simibubi 2021-02-19 15:10:14 +01:00 committed by GitHub
commit 2ece21a3ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 1 deletions

View file

@ -851,6 +851,7 @@
"create.gui.sequenced_gearshift.instruction.turn_distance.distance": "Distance",
"create.gui.sequenced_gearshift.instruction.wait": "Wait",
"create.gui.sequenced_gearshift.instruction.wait.duration": "Duration",
"create.gui.sequenced_gearshift.instruction.paused": "Paused",
"create.gui.sequenced_gearshift.instruction.end": "End",
"create.gui.sequenced_gearshift.speed": "Speed, Direction",
"create.gui.sequenced_gearshift.speed.forward": "Input speed, Forwards",

View file

@ -41,6 +41,9 @@ public class Instruction {
case WAIT:
return (int) ((1 - initialProgress) * value + 1);
case PAUSED:
return -1;
case END:
default:
break;
@ -58,6 +61,7 @@ public class Instruction {
case END:
case WAIT:
case PAUSED:
default:
break;
@ -65,6 +69,15 @@ public class Instruction {
return 0;
}
OnIsPoweredResult onIsPowered() {
switch (instruction)
{
case PAUSED:
return OnIsPoweredResult.CONTINUE;
}
return OnIsPoweredResult.NOTHING;
}
public static ListNBT serializeAll(Vector<Instruction> instructions) {
ListNBT list = new ListNBT();
instructions.forEach(i -> list.add(i.serialize()));

View file

@ -0,0 +1,6 @@
package com.simibubi.create.content.contraptions.relays.advanced.sequencer;
public enum OnIsPoweredResult {
NOTHING,
CONTINUE
}

View file

@ -64,8 +64,11 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen
return;
boolean previouslyPowered = state.get(STATE) != 0;
if (previouslyPowered != worldIn.isBlockPowered(pos))
boolean isPowered = worldIn.isBlockPowered(pos);
if (previouslyPowered != isPowered)
withTileEntityDo(worldIn, pos, SequencedGearshiftTileEntity::onRedstoneUpdate);
else if (isPowered)
withTileEntityDo(worldIn, pos, SequencedGearshiftTileEntity::onIsPowered);
}
@Override

View file

@ -32,6 +32,8 @@ public class SequencedGearshiftTileEntity extends SplitShaftTileEntity {
return;
if (world.isRemote)
return;
if (currentInstructionDuration < 0)
return;
if (timer < currentInstructionDuration) {
timer++;
return;
@ -66,6 +68,7 @@ public class SequencedGearshiftTileEntity extends SplitShaftTileEntity {
public void onRedstoneUpdate() {
if (!isIdle())
return;
if (!world.isBlockPowered(pos)) {
world.setBlockState(pos, getBlockState().with(SequencedGearshiftBlock.STATE, 0), 3);
return;
@ -75,6 +78,19 @@ public class SequencedGearshiftTileEntity extends SplitShaftTileEntity {
run(0);
}
public void onIsPowered() {
Instruction instruction = getInstruction(currentInstruction);
if (instruction == null)
return;
switch (instruction.onIsPowered())
{
case CONTINUE:
run(currentInstruction + 1);
}
}
protected void run(int instructionIndex) {
Instruction instruction = getInstruction(instructionIndex);
if (instruction == null || instruction.instruction == SequencerInstructions.END) {

View file

@ -11,6 +11,7 @@ public enum SequencerInstructions {
TURN_ANGLE("angle", AllGuiTextures.SEQUENCER_INSTRUCTION, true, true, 360, 45, 90),
TURN_DISTANCE("distance", AllGuiTextures.SEQUENCER_INSTRUCTION, true, true, 128, 5, 5),
WAIT("duration", AllGuiTextures.SEQUENCER_WAIT, true, false, 600, 20, 10),
PAUSED("", AllGuiTextures.SEQUENCER_PAUSED),
END("", AllGuiTextures.SEQUENCER_END),
;

View file

@ -54,6 +54,7 @@ public enum AllGuiTextures {
SEQUENCER_WAIT("sequencer.png", 0, 58, 162, 22),
SEQUENCER_END("sequencer.png", 0, 80, 162, 22),
SEQUENCER_EMPTY("sequencer.png", 0, 102, 162, 22),
SEQUENCER_PAUSED("sequencer.png", 0, 160, 162, 22),
// JEI
JEI_SLOT("jei/widgets.png", 18, 18),

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 17 KiB