-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1191 from johalun/1.19.2-jump-sub
Add Jump Subroutine widget
- Loading branch information
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/main/java/me/desht/pneumaticcraft/common/drone/progwidgets/ProgWidgetJumpSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* This file is part of pnc-repressurized. | ||
* | ||
* pnc-repressurized is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* pnc-repressurized is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with pnc-repressurized. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.desht.pneumaticcraft.common.drone.progwidgets; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import me.desht.pneumaticcraft.api.drone.ProgWidgetType; | ||
import me.desht.pneumaticcraft.common.core.ModProgWidgets; | ||
import me.desht.pneumaticcraft.common.drone.IDroneBase; | ||
import me.desht.pneumaticcraft.lib.Textures; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.DyeColor; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static me.desht.pneumaticcraft.common.util.PneumaticCraftUtils.xlate; | ||
|
||
public class ProgWidgetJumpSub extends ProgWidget implements IJumpBackWidget, IJump { | ||
private boolean jumpBack; | ||
|
||
public ProgWidgetJumpSub() { | ||
super(ModProgWidgets.JUMP_SUB.get()); | ||
} | ||
|
||
@Override | ||
public void addErrors(List<Component> curInfo, List<IProgWidget> widgets) { | ||
super.addErrors(curInfo, widgets); | ||
if (getConnectedParameters()[0] == null) curInfo.add(xlate("pneumaticcraft.gui.progWidget.label.error.noJumpLocation")); | ||
} | ||
|
||
@Override | ||
public boolean hasStepInput() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hasStepOutput() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public IProgWidget getOutputWidget(IDroneBase drone, List<IProgWidget> allWidgets) { | ||
List<String> locations = getPossibleJumpLocations(); | ||
if (locations.size() > 0 && !jumpBack) { | ||
jumpBack = true; | ||
return ProgWidgetJump.jumpToLabel(drone, allWidgets, locations.get(0)); | ||
} | ||
jumpBack = false; | ||
return super.getOutputWidget(drone, allWidgets); | ||
} | ||
|
||
@Override | ||
public ProgWidgetType<?> returnType() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<ProgWidgetType<?>> getParameters() { | ||
return ImmutableList.of(ModProgWidgets.TEXT.get()); | ||
} | ||
|
||
@Override | ||
protected boolean hasBlacklist() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getTexture() { | ||
return Textures.PROG_WIDGET_JUMP_SUB; | ||
} | ||
|
||
@Override | ||
public WidgetDifficulty getDifficulty() { | ||
return WidgetDifficulty.MEDIUM; | ||
} | ||
|
||
@Override | ||
public List<String> getPossibleJumpLocations() { | ||
ProgWidgetText jumpLabel = (ProgWidgetText) getConnectedParameters()[0]; | ||
if (jumpLabel != null) { | ||
return Collections.singletonList(jumpLabel.string); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public DyeColor getColor() { | ||
return DyeColor.WHITE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ources/assets/pneumaticcraft/patchouli_books/book/en_us/entries/programming/jump_sub.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "Jump Subroutine Widget", | ||
"icon": "pneumaticcraft:textures/progwidgets/jump_sub_piece.png", | ||
"category": "pneumaticcraft:widget_flow", | ||
"advancement": "pneumaticcraft:programmer", | ||
"pages": [ | ||
{ | ||
"type": "text", | ||
"text": "This widget behaves like $(thing)Jump/$ except when the subroutine has completed, execution will continue in the widget connected to the bottom of the $(thing)Jump Subroutine/$ widget. A $(thing)Jump Subroutine/$ widget is useful for reusing common code and calling subroutines with arbitrary arguments by assigning variables before jumping to the subroutine." | ||
}, | ||
{ | ||
"type": "image", | ||
"images": [ | ||
"pneumaticcraft:textures/progwidgets/jump_sub_piece.png" | ||
], | ||
"text": "$(italic)Jump Subroutine Widget/$" | ||
} | ||
] | ||
} |
Binary file added
BIN
+49.4 KB
src/main/resources/assets/pneumaticcraft/textures/progwidgets/jump_sub_piece.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.