Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master-1.19-lts' into master-1.2…
Browse files Browse the repository at this point in the history
…0-lts
  • Loading branch information
rubensworks committed Jan 8, 2025
2 parents fe5fafd + d9ea083 commit e58874b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions resources/changelog/1.19.2-1.25.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
As always, don't forget to backup your world before updating!
Requires CyclopsCore version 1.18.2 or higher.

Additions:
* Add item tooltip operators
Original file line number Diff line number Diff line change
Expand Up @@ -1254,4 +1254,33 @@ public void testInvalidInputTypeHasNbt() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_HASNBT.evaluate(new IVariable[]{DUMMY_VARIABLE});
}

/**
* ----------------------------------- TOOLTIPLINES -----------------------------------
*/

@IntegrationTest
public void testItemStackTooltip() throws EvaluationException {
IValue res1 = Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{iPickaxe});
Asserts.check(res1 instanceof ValueTypeList.ValueList, "result is a list");
TestHelpers.assertEqual(((ValueTypeList.ValueList) res1).getRawValue().getLength(), 5, "size(tooltip(pickaxe)) = 5");

IValue res2 = Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{iApple});
TestHelpers.assertEqual(((ValueTypeList.ValueList) res2).getRawValue().getLength(), 1, "size(tooltip(apple)) = 1");
}

@IntegrationTest(expected = EvaluationException.class)
public void testInvalidInputSizeTooltipLarge() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{iPickaxe, iPickaxe});
}

@IntegrationTest(expected = EvaluationException.class)
public void testInvalidInputSizeTooltipSmall() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{});
}

@IntegrationTest(expected = EvaluationException.class)
public void testInvalidInputTypeTooltip() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{DUMMY_VARIABLE});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public class OperatorBuilders {
public static final OperatorBuilder<OperatorBase.SafeVariablesGetter> ENTITY = OperatorBuilder.forType(ValueTypes.OBJECT_ENTITY).appendKind("entity");
public static final OperatorBuilder<OperatorBase.SafeVariablesGetter> ENTITY_1_SUFFIX = ENTITY.inputTypes(1, ValueTypes.OBJECT_ENTITY).renderPattern(IConfigRenderPattern.SUFFIX_1);
public static final OperatorBuilder<OperatorBase.SafeVariablesGetter> ENTITY_1_SUFFIX_LONG = ENTITY.inputTypes(1, ValueTypes.OBJECT_ENTITY).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG);
public static final OperatorBuilder<OperatorBase.SafeVariablesGetter> ENTITY_1_ITEMSTACK_1 = ENTITY.inputTypes(new IValueType[]{ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK}).renderPattern(IConfigRenderPattern.INFIX_LONG);
public static final IterativeFunction.PrePostBuilder<Entity, IValue> FUNCTION_ENTITY = IterativeFunction.PrePostBuilder.begin()
.appendPre(input -> {
ValueObjectTypeEntity.ValueEntity a = input.getValue(0, ValueTypes.OBJECT_ENTITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
Expand Down Expand Up @@ -1963,6 +1964,37 @@ public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws Evalua
itemStack -> !itemStack.isEmpty() && itemStack.hasTag()
)).build());

/**
* Get the tooltip of an itemstack in list form.
*/
public static final IOperator OBJECT_ITEMSTACK_TOOLTIP = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
.output(ValueTypes.LIST).symbol("tooltip").operatorName("tooltip").interactName("tooltip")
.function(input -> {
ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
itemStack.getRawValue().getTooltipLines(null, TooltipFlag.Default.NORMAL).stream()
.map(c -> ValueTypeString.ValueString.of(c.getString()))
.toList());
}).build());
/**
* Get the tooltip of an itemstack in list form, using the provided player entity as the player context.
*/
public static final IOperator OBJECT_ITEMSTACK_ENTITY_TOOLTIP = REGISTRY.register(OperatorBuilders.ENTITY_1_ITEMSTACK_1
.inputTypes(ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK)
.output(ValueTypes.LIST).symbol("entity_item_tooltip").operatorName("entityitemtooltip").interactName("entityItemTooltip")
.function(variables -> {
ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
ValueObjectTypeItemStack.ValueItemStack itemStack = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof Player) {
Player entity = (Player) a.getRawValue().get();
return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
itemStack.getRawValue().getTooltipLines(entity, TooltipFlag.Default.NORMAL).stream()
.map(c -> ValueTypeString.ValueString.of(c.getString()))
.toList());
}
return ValueTypes.LIST.getDefault();
}).build());

/**
* ----------------------------------- ENTITY OBJECT OPERATORS -----------------------------------
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/integrateddynamics/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,11 @@
"operator.integrateddynamics.entity.entityenergycapacity": "Entity Energy Capacity",
"operator.integrateddynamics.entity.entityenergycapacity.info": "The energy capacity of this entity.",

"operator.integrateddynamics.entity.entityitemtooltip": "Entity Tooltip",
"operator.integrateddynamics.entity.entityitemtooltip.info": "In the context of the given Player Entity, get the tooltip of the given item as a list of strings.",
"operator.integrateddynamics.itemstack.tooltip": "Tooltip",
"operator.integrateddynamics.itemstack.tooltip.info": "Get the tooltip of the given item as a list of strings.",

"operator.integrateddynamics.itemstack.isfecontainer": "Is FE Container",
"operator.integrateddynamics.itemstack.isfecontainer.info": "If the given item can hold FE",
"operator.integrateddynamics.itemstack.storedfe": "FE Stored",
Expand Down

0 comments on commit e58874b

Please sign in to comment.