Skip to content

Commit

Permalink
Merge pull request #1191 from johalun/1.19.2-jump-sub
Browse files Browse the repository at this point in the history
Add Jump Subroutine widget
  • Loading branch information
desht committed Aug 12, 2023
2 parents 692ab9f + aa6b911 commit 359d216
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class ModProgWidgets {
= register("label", ProgWidgetLabel::new);
public static final RegistryObject<ProgWidgetType<ProgWidgetJump>> JUMP
= register("jump", ProgWidgetJump::new);
public static final RegistryObject<ProgWidgetType<ProgWidgetJumpSub>> JUMP_SUB
= register("jump_sub", ProgWidgetJumpSub::new);
public static final RegistryObject<ProgWidgetType<ProgWidgetWait>> WAIT
= register("wait", ProgWidgetWait::new);
public static final RegistryObject<ProgWidgetType<ProgWidgetRename>> RENAME
Expand Down
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;
}
}
1 change: 1 addition & 0 deletions src/main/java/me/desht/pneumaticcraft/lib/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class Textures {
public static final ResourceLocation PROG_WIDGET_TEXT = progWidgetTexture("text_piece.png");
public static final ResourceLocation PROG_WIDGET_LABEL = progWidgetTexture("label_piece.png");
public static final ResourceLocation PROG_WIDGET_JUMP = progWidgetTexture("jump_piece.png");
public static final ResourceLocation PROG_WIDGET_JUMP_SUB = progWidgetTexture("jump_sub_piece.png");
public static final ResourceLocation PROG_WIDGET_WAIT = progWidgetTexture("wait_piece.png");
public static final ResourceLocation PROG_WIDGET_DROP_ITEM = progWidgetTexture("item_drop_piece.png");
public static final ResourceLocation PROG_WIDGET_EMIT_REDSTONE = progWidgetTexture("emit_redstone_piece.png");
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/pneumaticcraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,7 @@
"programmingPuzzle.pneumaticcraft.item_assign.name" : "Item Assignment",
"programmingPuzzle.pneumaticcraft.item_filter.name" : "Item Filter",
"programmingPuzzle.pneumaticcraft.jump.name" : "Jump",
"programmingPuzzle.pneumaticcraft.jump_sub.name" : "Jump Subroutine",
"programmingPuzzle.pneumaticcraft.label.name" : "Label",
"programmingPuzzle.pneumaticcraft.liquid_export.name" : "Export Fluid",
"programmingPuzzle.pneumaticcraft.liquid_filter.name" : "Fluid Filter",
Expand Down
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/$"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 359d216

Please sign in to comment.