Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Added a pattern display overlay for pattern-holding items (ie scrolls or slates) while holding shift in the inventory ([#879](https://github.com/FallingColors/HexMod/pull/879)) @SamsTheNerd
- Added connected textures for Akashic Ligatures when using Continuity or Optifine ([#885](https://github.com/FallingColors/HexMod/pull/885)) @kineticneticat
- Added Similarity Distillation and Dissimilarity Distillation for comparing iota types ([#1114](https://github.com/FallingColors/HexMod/pull/1114)) @IridescentVoid
- Added Surveyor's Distillation and Inspector's Distillation ([#1224](https://github.com/FallingColors/HexMod/pull/1224)) @IridescentVoid
- Added Contemplation for escaping without the exponential growth of Consideration ([#1102](https://github.com/FallingColors/HexMod/pull/1102)) @IridescentVoid

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package at.petrak.hexcasting.common.casting.actions.types

import at.petrak.hexcasting.api.casting.asActionResult
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getBlockPos
import at.petrak.hexcasting.api.casting.iota.Iota

class OpBlockEquality(val exact: Boolean) : ConstMediaAction {
override val argc = 2

override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val posA = args.getBlockPos(0).also { env.assertPosInRange(it) }
val posB = args.getBlockPos(1).also { env.assertPosInRange(it) }

val blockA = env.world.getBlockState(posA)
val blockB = env.world.getBlockState(posB)

// a unique BlockState only has one instance
val matches = if (exact) blockA === blockB else blockA.`is`(blockB.block)

return matches.asActionResult
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package at.petrak.hexcasting.common.casting.actions.types

import at.petrak.hexcasting.api.casting.asActionResult
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getEntity
import at.petrak.hexcasting.api.casting.iota.Iota

object OpEntityEquality : ConstMediaAction {
override val argc = 2

override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val entityA = args.getEntity(0).also { env.assertEntityInRange(it) }
val entityB = args.getEntity(1).also { env.assertEntityInRange(it) }

return (entityA.type == entityB.type).asActionResult
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package at.petrak.hexcasting.common.casting.actions.types

import at.petrak.hexcasting.api.casting.asActionResult
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getEntity
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidIota
import at.petrak.hexcasting.common.lib.HexItemHolderHandlers
import net.minecraft.world.item.ItemStack

class OpItemEquality(val exact: Boolean) : ConstMediaAction {
override val argc = 2

override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val itemA = args.getEntity(0).also { env.assertEntityInRange(it) }
.let { HexItemHolderHandlers.applyHandlerFor(it) }
?: throw MishapInvalidIota.ofType(args[0], 0, "entity.item_holder")

val itemB = args.getEntity(1).also { env.assertEntityInRange(it) }
.let { HexItemHolderHandlers.applyHandlerFor(it) }
?: throw MishapInvalidIota.ofType(args[1], 1, "entity.item_holder")

val matches = if (exact) ItemStack.isSameItemSameTags(itemA, itemB)
else ItemStack.isSameItem(itemA, itemB)

return matches.asActionResult
} // TODO: move book entry again and have an extra page on 'item holder'
// and examples for type of item and identical
// types: "first iota given"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.petrak.hexcasting.common.casting.actions.math.logic
package at.petrak.hexcasting.common.casting.actions.types

import at.petrak.hexcasting.api.casting.asActionResult
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package at.petrak.hexcasting.common.lib;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public class HexItemHolderHandlers {
private static Map<EntityType<?>, Function<? extends Entity, ItemStack>> REGISTRY = new HashMap<>();

/**
* Register a handler for mapping an entity type to an item.
*
* @param type Type of entity to register the handler for.
* @param handler The handler function. May return null, in which case dependent patterns will mishap.
*/
public static <T extends Entity> void register(EntityType<T> type, Function<T, ItemStack> handler) {
REGISTRY.put(type, handler);
}

@SuppressWarnings("unchecked")
public static @Nullable ItemStack applyHandlerFor(Entity e) {
var handler = REGISTRY.getOrDefault(e.getType(), entity -> null);
ItemStack stack = ((Function<Entity, ItemStack>) handler).apply(e);

if (stack != null && stack.isEmpty()) stack = null;

return stack;
}

public static void init() {
register(EntityType.ITEM, ItemEntity::getItem);
register(EntityType.ITEM_FRAME, ItemFrame::getItem);
register(EntityType.PLAYER, player -> {
ItemStack mainHand = player.getItemInHand(InteractionHand.MAIN_HAND);
if (!mainHand.isEmpty()) return mainHand;
return player.getItemInHand(InteractionHand.OFF_HAND);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import at.petrak.hexcasting.common.casting.actions.math.logic.OpBoolIf;
import at.petrak.hexcasting.common.casting.actions.math.logic.OpCoerceToBool;
import at.petrak.hexcasting.common.casting.actions.math.logic.OpEquality;
import at.petrak.hexcasting.common.casting.actions.math.logic.OpTypeEquality;
import at.petrak.hexcasting.common.casting.actions.types.OpEntityEquality;
import at.petrak.hexcasting.common.casting.actions.types.OpItemEquality;
import at.petrak.hexcasting.common.casting.actions.types.OpTypeEquality;
import at.petrak.hexcasting.common.casting.actions.types.OpBlockEquality;
import at.petrak.hexcasting.common.casting.actions.queryentity.*;
import at.petrak.hexcasting.common.casting.actions.raycast.OpBlockAxisRaycast;
import at.petrak.hexcasting.common.casting.actions.raycast.OpBlockRaycast;
Expand Down Expand Up @@ -543,6 +546,23 @@ public class HexActions {
true)
));

// == Types ==
public static final ActionRegistryEntry COMPARE_BLOCK = make("compare_block/lenient", new ActionRegistryEntry(
HexPattern.fromAngles("qqqqqeqeeeee", HexDir.NORTH_WEST), new OpBlockEquality(false)
));
public static final ActionRegistryEntry COMPARE_BLOCK_STRICT = make("compare_block/strict", new ActionRegistryEntry(
HexPattern.fromAngles("qwawqwadadwewdwe", HexDir.NORTH_WEST), new OpBlockEquality(true)
));
public static final ActionRegistryEntry COMPARE_ENTITY = make("compare_entity", new ActionRegistryEntry(
HexPattern.fromAngles("aqaeqded", HexDir.NORTH_WEST), OpEntityEquality.INSTANCE
));
public static final ActionRegistryEntry COMPARE_ITEM = make("compare_item/lenient", new ActionRegistryEntry(
HexPattern.fromAngles("qaeaqeqedqde", HexDir.NORTH_WEST), new OpItemEquality(false)
));
public static final ActionRegistryEntry COMPARE_ITEM_STRICT = make("compare_item/strict", new ActionRegistryEntry(
HexPattern.fromAngles("qaeaqewqedqde", HexDir.NORTH_WEST), new OpItemEquality(true)
));

// == Lists ==

public static final ActionRegistryEntry APPEND = make("append",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,18 @@
not_player: "Zone Distillation: Non-Player",
not_living: "Zone Distillation: Non-Living",
},

type_equals: "Similarity Distillation",
type_not_equals: "Dissimilarity Distillation",
"compare_block/": {
"lenient": "Surveyor's Distillation",
"strict": "Inspector's Distillation",
},
compare_entity: "Taxonomer's Distillation",
"compare_item/": {
"lenient": "Sorter's Distillation",
"strict": "Stacking Distillation",
},

swap: "Jester's Gambit",
rotate: "Rotation Gambit",
Expand All @@ -814,8 +826,6 @@
less_eq: "Minimus Distillation II",
equals: "Equality Distillation",
not_equals: "Inequality Distillation",
type_equals: "Similarity Distillation",
type_not_equals: "Dissimilarity Distillation",
not: "Negation Purification",
bool_coerce: "Augur's Purification",
if: "Augur's Exaltation",
Expand Down Expand Up @@ -1106,6 +1116,7 @@
"": "an entity",
mob: "a mob",
item: "an item entity",
item_holder: "an item-holding entity",
player: "a player",
living: "a living entity",
},
Expand Down Expand Up @@ -1311,6 +1322,7 @@
stackmanip: "Stack Manipulation",
logic: "Logical Operators",
entities: "Entities",
types: "Types",
lists: "List Manipulation",
patterns_as_iotas: "Escaping Patterns",
readwrite: "Reading and Writing",
Expand Down Expand Up @@ -1909,8 +1921,6 @@
if: "If the first argument is True, keeps the second and discards the third; otherwise discards the second and keeps the third.",
equals: "If the first argument equals the second (within a small tolerance), return True. Otherwise, return False.",
not_equals: "If the first argument does not equal the second (outside a small tolerance), return True. Otherwise, return False.",
type_equals: "If the type of the first argument matches the type of the second, return True. Otherwise, return False.",
type_not_equals: "If the type of the first argument does not match the type of the second, return True. Otherwise, return False.",
greater: "If the first argument is greater than the second, return True. Otherwise, return False.",
less: "If the first argument is less than the second, return True. Otherwise, return False.",
greater_eq: "If the first argument is greater than or equal to the second, return True. Otherwise, return False.",
Expand Down Expand Up @@ -1941,6 +1951,20 @@
not_living: "Take a position and maximum distance on the stack, and combine them into a list of non-living entities near the position.",
},
},

types: {
type_equals: "Compare the given iotas and push whether they are of the same type.",
type_not_equals: "Compare the given iotas and push whether they are of different types.",
"compare_block/": {
lenient: "Compare the blocks specified by the given vectors and push whether they are of the same type, in Nature's eye.",
strict: "Compare the blocks specified by the given vectors and push whether they appear to be identical.",
},
compare_entity: "Compare the given entities and push whether they are of the same type.",
"compare_item/": {
lenient: "Compare the items within or held by the given entities and push whether they are the same type of item. Two $(l:items/focus)$(item)Foci/$ will always compare as equal.",
strict: "Like $(l:patterns/types#hexcasting:compare_item/lenient)$(action)Sorter's Distillation/$, but push whether they are identical items. Two $(l:items/focus)$(item)Foci/$ only compare as identical if they hold the same iota.",
},
},

lists: {
index: "Remove the number at the top of the stack, then replace the list at the top with the nth element of that list (where n is the number you removed). Replaces the list with $(l:casting/influences)$(thing)Null/$ if the number is out of bounds.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexcasting.entry.akashic_patterns",
"category": "hexcasting:patterns",
"icon": "hexcasting:akashic_bookshelf",
"sortnum": 14,
"sortnum": 15,
"advancement": "hexcasting:enlightenment",
"entry_color": "54398a",
"pages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexcasting.entry.circle_patterns",
"category": "hexcasting:patterns",
"icon": "hexcasting:impetus/empty",
"sortnum": 13,
"sortnum": 14,
"advancement": "hexcasting:enlightenment",
"entry_color": "54398a",
"pages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexcasting.entry.entities",
"category": "hexcasting:patterns",
"icon": "minecraft:pig_spawn_egg",
"sortnum": 6,
"sortnum": 7,
"advancement": "hexcasting:root",
"read_by_default": true,
"pages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexcasting.entry.lists",
"category": "hexcasting:patterns",
"icon": "minecraft:oak_sign",
"sortnum": 7,
"sortnum": 8,
"advancement": "hexcasting:root",
"read_by_default": true,
"pages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,6 @@
"output": "bool",
"text": "hexcasting.page.logic.not_equals"
},
{
"type": "hexcasting:pattern",
"op_id": "hexcasting:type_equals",
"anchor": "hexcasting:type_equals",
"input": "any, any",
"output": "bool",
"text": "hexcasting.page.logic.type_equals"
},
{
"type": "hexcasting:pattern",
"op_id": "hexcasting:type_not_equals",
"anchor": "hexcasting:type_not_equals",
"input": "any, any",
"output": "bool",
"text": "hexcasting.page.logic.type_not_equals"
},
{
"type": "hexcasting:pattern",
"op_id": "hexcasting:greater",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexcasting.entry.meta",
"category": "hexcasting:patterns",
"icon": "minecraft:shulker_box",
"sortnum": 12,
"sortnum": 13,
"advancement": "hexcasting:root",
"read_by_default": true,
"pages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexcasting.entry.patterns_as_iotas",
"category": "hexcasting:patterns",
"icon": "minecraft:emerald",
"sortnum": 8,
"sortnum": 9,
"advancement": "hexcasting:root",
"read_by_default": true,
"pages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexcasting.entry.readwrite",
"category": "hexcasting:patterns",
"icon": "minecraft:writable_book",
"sortnum": 9,
"sortnum": 10,
"advancement": "hexcasting:root",
"read_by_default": true,
"pages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexcasting.entry.sets",
"category": "hexcasting:patterns",
"icon": "minecraft:bundle",
"sortnum": 11,
"sortnum": 12,
"advancement": "hexcasting:root",
"read_by_default": true,
"pages": [
Expand Down
Loading
Loading