Skip to content

Commit

Permalink
Merge branch 'qol'
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavid04 committed Feb 14, 2024
2 parents 3233c71 + a7568c0 commit 96fd9fc
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/main/java/gdavid/phi/spell/operator/HashOperator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gdavid.phi.spell.operator;

import gdavid.phi.spell.Errors;
import net.minecraft.entity.Entity;
import vazkii.psi.api.spell.Spell;
import vazkii.psi.api.spell.SpellContext;
Expand Down Expand Up @@ -30,6 +31,7 @@ public Class<?> getEvaluationType() {
@Override
public Object execute(SpellContext context) throws SpellRuntimeException {
Object val = getRawParamValue(context, value);
if (val == null) Errors.runtime(SpellRuntimeException.NULL_TARGET);
if (val instanceof Entity) return ((Entity) val).getUniqueID().hashCode();
// String, Number and Vector3 implement hashCode properly
// TODO EntityListWrapper support
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/gdavid/phi/spell/operator/number/DivModOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import gdavid.phi.spell.Param;
import gdavid.phi.spell.param.ReferenceParam;
import gdavid.phi.util.ISidedResult;
import gdavid.phi.util.ParamHelper;
import gdavid.phi.util.RenderHelper;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.RenderMaterial;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import vazkii.psi.api.ClientPsiAPI;
Expand All @@ -26,6 +31,11 @@
import vazkii.psi.api.spell.param.ParamNumber;
import vazkii.psi.api.spell.piece.PieceOperator;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class DivModOperator extends PieceOperator {

public static final ResourceLocation lineTexture = new ResourceLocation(Phi.modId, "spell/operator_div_mod_lines");
Expand All @@ -41,8 +51,14 @@ public DivModOperator(Spell spell) {
public void initParams() {
addParam(a = new ParamNumber(SpellParam.GENERIC_NAME_NUMBER1, SpellParam.RED, false, false));
addParam(b = new ParamNumber(SpellParam.GENERIC_NAME_NUMBER2, SpellParam.GREEN, false, false));
addParam(div = new ReferenceParam(Param.div.name, SpellParam.RED, true, ArrowType.NONE));
addParam(mod = new ReferenceParam(Param.mod.name, SpellParam.GREEN, true, ArrowType.NONE));
addParam(div = new ReferenceParam(Param.div.name, SpellParam.RED, true, true, ArrowType.NONE));
addParam(mod = new ReferenceParam(Param.mod.name, SpellParam.GREEN, true, true, ArrowType.NONE));
}

@Override
@OnlyIn(Dist.CLIENT)
public void addToTooltipAfterShift(List<ITextComponent> tooltip) {
ParamHelper.outputTooltip(this, super::addToTooltipAfterShift, tooltip);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gdavid.phi.spell.operator.text;

import gdavid.phi.spell.Errors;
import vazkii.psi.api.spell.Spell;
import vazkii.psi.api.spell.SpellContext;
import vazkii.psi.api.spell.SpellParam;
Expand Down Expand Up @@ -28,7 +29,9 @@ public Class<?> getEvaluationType() {

@Override
public Object execute(SpellContext context) throws SpellRuntimeException {
return getRawParamValue(context, value).toString();
Object val = getRawParamValue(context, value);
if (val == null) Errors.runtime(SpellRuntimeException.NULL_TARGET);
return val.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import gdavid.phi.spell.param.ReferenceParam;
import gdavid.phi.spell.param.TextParam;
import gdavid.phi.util.ISidedResult;
import gdavid.phi.util.ParamHelper;
import gdavid.phi.util.RenderHelper;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.RenderMaterial;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import vazkii.psi.api.ClientPsiAPI;
Expand All @@ -26,6 +31,8 @@
import vazkii.psi.api.spell.SpellRuntimeException;
import vazkii.psi.api.spell.piece.PieceOperator;

import java.util.List;

public class SplitTextAtOperator extends PieceOperator {

public static final ResourceLocation lineTexture = new ResourceLocation(Phi.modId,
Expand All @@ -42,8 +49,14 @@ public SplitTextAtOperator(Spell spell) {
public void initParams() {
addParam(text = new TextParam(Param.text.name, SpellParam.GRAY, false, false));
addParam(at = new TextParam(Param.at.name, SpellParam.BLUE, false, false));
addParam(before = new ReferenceParam(Param.before.name, SpellParam.RED, true, ArrowType.NONE));
addParam(after = new ReferenceParam(Param.after.name, SpellParam.GREEN, true, ArrowType.NONE));
addParam(before = new ReferenceParam(Param.before.name, SpellParam.RED, true, true, ArrowType.NONE));
addParam(after = new ReferenceParam(Param.after.name, SpellParam.GREEN, true, true, ArrowType.NONE));
}

@Override
@OnlyIn(Dist.CLIENT)
public void addToTooltipAfterShift(List<ITextComponent> tooltip) {
ParamHelper.outputTooltip(this, super::addToTooltipAfterShift, tooltip);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import gdavid.phi.spell.param.ReferenceParam;
import gdavid.phi.spell.param.TextParam;
import gdavid.phi.util.ISidedResult;
import gdavid.phi.util.ParamHelper;
import gdavid.phi.util.RenderHelper;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.RenderMaterial;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import vazkii.psi.api.ClientPsiAPI;
Expand All @@ -27,6 +32,8 @@
import vazkii.psi.api.spell.param.ParamNumber;
import vazkii.psi.api.spell.piece.PieceOperator;

import java.util.List;

public class SplitTextOperator extends PieceOperator {

public static final ResourceLocation lineTexture = new ResourceLocation(Phi.modId,
Expand All @@ -44,8 +51,14 @@ public SplitTextOperator(Spell spell) {
public void initParams() {
addParam(text = new TextParam(Param.text.name, SpellParam.GRAY, false, false));
addParam(position = new ParamNumber(SpellParam.GENERIC_NAME_POSITION, SpellParam.BLUE, false, false));
addParam(before = new ReferenceParam(Param.before.name, SpellParam.RED, true, ArrowType.NONE));
addParam(after = new ReferenceParam(Param.after.name, SpellParam.GREEN, true, ArrowType.NONE));
addParam(before = new ReferenceParam(Param.before.name, SpellParam.RED, true, true, ArrowType.NONE));
addParam(after = new ReferenceParam(Param.after.name, SpellParam.GREEN, true, true, ArrowType.NONE));
}

@Override
@OnlyIn(Dist.CLIENT)
public void addToTooltipAfterShift(List<ITextComponent> tooltip) {
ParamHelper.outputTooltip(this, super::addToTooltipAfterShift, tooltip);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
import gdavid.phi.spell.Errors;
import gdavid.phi.spell.param.ReferenceParam;
import gdavid.phi.util.ISidedResult;
import gdavid.phi.util.ParamHelper;
import gdavid.phi.util.RenderHelper;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.RenderMaterial;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import vazkii.psi.api.ClientPsiAPI;
Expand All @@ -28,6 +33,8 @@
import vazkii.psi.api.spell.SpellRuntimeException;
import vazkii.psi.api.spell.param.ParamVector;

import java.util.List;

public class SplitVectorOperator extends SpellPiece {

public static final ResourceLocation lineTexture = new ResourceLocation(Phi.modId,
Expand All @@ -43,9 +50,15 @@ public SplitVectorOperator(Spell spell) {
@Override
public void initParams() {
addParam(vector = new ParamVector(SpellParam.GENERIC_NAME_VECTOR, SpellParam.GRAY, false, false));
addParam(outX = new ReferenceParam(SpellParam.GENERIC_NAME_X, SpellParam.RED, true, ArrowType.NONE));
addParam(outY = new ReferenceParam(SpellParam.GENERIC_NAME_Y, SpellParam.GREEN, true, ArrowType.NONE));
addParam(outZ = new ReferenceParam(SpellParam.GENERIC_NAME_Z, SpellParam.BLUE, true, ArrowType.NONE));
addParam(outX = new ReferenceParam(SpellParam.GENERIC_NAME_X, SpellParam.RED, true, true, ArrowType.NONE));
addParam(outY = new ReferenceParam(SpellParam.GENERIC_NAME_Y, SpellParam.GREEN, true, true, ArrowType.NONE));
addParam(outZ = new ReferenceParam(SpellParam.GENERIC_NAME_Z, SpellParam.BLUE, true, true, ArrowType.NONE));
}

@Override
@OnlyIn(Dist.CLIENT)
public void addToTooltipAfterShift(List<ITextComponent> tooltip) {
ParamHelper.outputTooltip(this, super::addToTooltipAfterShift, tooltip);
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/gdavid/phi/spell/param/ReferenceParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
public class ReferenceParam extends ParamAny {

public boolean checkLoop = false;
public boolean isOutput = false;

public ReferenceParam(String name, int color, boolean canDisable) {
public ReferenceParam(String name, int color, boolean canDisable, boolean isOutput) {
super(name, color, canDisable);
this.isOutput = isOutput;
}

public ReferenceParam(String name, int color, boolean canDisable, ArrowType arrowType) {
public ReferenceParam(String name, int color, boolean canDisable, boolean isOutput, ArrowType arrowType) {
super(name, color, canDisable, arrowType);
this.isOutput = isOutput;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gdavid.phi.spell.selector;

import vazkii.psi.api.spell.EnumPieceType;
import vazkii.psi.api.spell.Spell;
import vazkii.psi.api.spell.SpellContext;
import vazkii.psi.api.spell.SpellRuntimeException;
Expand All @@ -11,6 +12,11 @@ public SpellNameSelector(Spell spell) {
super(spell);
}

@Override
public EnumPieceType getPieceType() {
return EnumPieceType.CONSTANT;
}

@Override
public Object execute(SpellContext context) throws SpellRuntimeException {
return spell.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gdavid.phi.spell.Param;
import gdavid.phi.spell.param.ReferenceParam;
import gdavid.phi.util.EvalHelper;
import gdavid.phi.util.ParamHelper;
import vazkii.psi.api.spell.EnumSpellStat;
import vazkii.psi.api.spell.Spell;
import vazkii.psi.api.spell.SpellCompilationException;
Expand All @@ -14,6 +15,14 @@
import vazkii.psi.api.spell.SpellRuntimeException;
import vazkii.psi.api.spell.param.ParamNumber;
import vazkii.psi.api.spell.piece.PieceTrick;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.List;

public class EarlyEvaluateTrick extends PieceTrick {

Expand All @@ -26,10 +35,16 @@ public EarlyEvaluateTrick(Spell spell) {

@Override
public void initParams() {
addParam(target = new ReferenceParam(SpellParam.GENERIC_NAME_TARGET, SpellParam.RED, false));
addParam(target = new ReferenceParam(SpellParam.GENERIC_NAME_TARGET, SpellParam.RED, false, false));
addParam(condition = new ParamNumber(Param.condition.name, SpellParam.BLUE, false, false));
}

@Override
@OnlyIn(Dist.CLIENT)
public void addToTooltipAfterShift(List<ITextComponent> tooltip) {
ParamHelper.outputTooltip(this, super::addToTooltipAfterShift, tooltip);
}

@Override
public void addToMetadata(SpellMetadata meta) throws SpellCompilationException {
meta.addStat(EnumSpellStat.COMPLEXITY, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gdavid.phi.spell.Param;
import gdavid.phi.spell.param.ReferenceParam;
import gdavid.phi.util.EvalHelper;
import gdavid.phi.util.ParamHelper;
import vazkii.psi.api.spell.EnumSpellStat;
import vazkii.psi.api.spell.Spell;
import vazkii.psi.api.spell.SpellCompilationException;
Expand All @@ -14,6 +15,14 @@
import vazkii.psi.api.spell.SpellRuntimeException;
import vazkii.psi.api.spell.param.ParamNumber;
import vazkii.psi.api.spell.piece.PieceTrick;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.List;

public class ReevaluateTrick extends PieceTrick {

Expand All @@ -26,10 +35,16 @@ public ReevaluateTrick(Spell spell) {

@Override
public void initParams() {
addParam(target = new ReferenceParam(SpellParam.GENERIC_NAME_TARGET, SpellParam.RED, false).preventLoop());
addParam(target = new ReferenceParam(SpellParam.GENERIC_NAME_TARGET, SpellParam.RED, false, false).preventLoop());
addParam(condition = new ParamNumber(Param.condition.name, SpellParam.BLUE, true, false));
}

@Override
@OnlyIn(Dist.CLIENT)
public void addToTooltipAfterShift(List<ITextComponent> tooltip) {
ParamHelper.outputTooltip(this, super::addToTooltipAfterShift, tooltip);
}

@Override
public void addToMetadata(SpellMetadata meta) throws SpellCompilationException {
meta.addStat(EnumSpellStat.COMPLEXITY, 1);
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/gdavid/phi/util/ParamHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package gdavid.phi.util;

import gdavid.phi.spell.Errors;
import gdavid.phi.spell.param.ReferenceParam;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import vazkii.psi.api.internal.Vector3;
Expand All @@ -12,6 +17,11 @@
import vazkii.psi.api.spell.SpellPiece;
import vazkii.psi.api.spell.SpellRuntimeException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class ParamHelper {

public static double positiveOrZero(SpellPiece piece, SpellParam<Number> param) throws SpellCompilationException {
Expand Down Expand Up @@ -51,4 +61,19 @@ public static int connectorColor(SpellPiece piece, Side side, int def) {
return def;
}

@OnlyIn(Dist.CLIENT)
public static void outputTooltip(SpellPiece piece, Consumer<List<ITextComponent>> superFn, List<ITextComponent> tooltip) {
Map<SpellParam<?>, Side> paramSidesTmp = new HashMap<>(piece.paramSides);
piece.paramSides.keySet().removeIf(e -> e instanceof ReferenceParam && ((ReferenceParam) e).isOutput);
superFn.accept(tooltip);
piece.paramSides.putAll(paramSidesTmp);
for (SpellParam<?> param : piece.paramSides.keySet()) {
if (param instanceof ReferenceParam && ((ReferenceParam) param).isOutput) {
ITextComponent name = new TranslationTextComponent(param.name).mergeStyle(TextFormatting.YELLOW);
ITextComponent type = new StringTextComponent(" [").append(param.getRequiredTypeString()).appendString("]").mergeStyle(TextFormatting.YELLOW);
tooltip.add((new StringTextComponent(param.canDisable ? "[Output] " : " Output ")).append(name).append(type));
}
}
}

}

0 comments on commit 96fd9fc

Please sign in to comment.