Skip to content

Commit

Permalink
Improve OpMakePackagedSpell a little
Browse files Browse the repository at this point in the history
  • Loading branch information
Robotgiggle committed Jan 23, 2025
1 parent 1c4d22e commit f37f3c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.item.ItemStack
import net.minecraft.network.chat.Component
import java.util.function.Predicate;

// TODO: How to handle in circles
class OpMakePackagedSpell<T : ItemPackagedHex>(val isValid: Predicate<ItemStack>, val expectedType: T, val cost: Long) : SpellAction {
class OpMakePackagedSpell(val isValid: Predicate<ItemStack>, val expectedTypeDesc: Component, val cost: Long) : SpellAction {
constructor(itemType: ItemPackagedHex, cost: Long) : this({s -> s.`is`(itemType)}, itemType.description, cost) {}

override val argc = 2
override fun execute(
args: List<Iota>,
Expand All @@ -33,11 +36,11 @@ class OpMakePackagedSpell<T : ItemPackagedHex>(val isValid: Predicate<ItemStack>
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(it)
isValid.test(it) && hexHolder != null && !hexHolder.hasHex()
}
?: throw MishapBadOffhandItem(ItemStack.EMPTY.copy(), expectedType.description) // TODO: hack
?: throw MishapBadOffhandItem(ItemStack.EMPTY.copy(), expectedTypeDesc) // TODO: hack

val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack)
if (!isValid.test(handStack)) {
throw MishapBadOffhandItem(handStack, expectedType.description)
throw MishapBadOffhandItem(handStack, expectedTypeDesc)
} else if (hexHolder == null || hexHolder.hasHex()) {
throw MishapBadOffhandItem.of(handStack, "iota.write")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,16 @@ public class HexActions {
new ActionRegistryEntry(HexPattern.fromAngles("adaa", HexDir.WEST), OpBeep.INSTANCE));

public static final ActionRegistryEntry CRAFT$CYPHER = make("craft/cypher", new ActionRegistryEntry(
HexPattern.fromAngles("waqqqqq", HexDir.EAST), new OpMakePackagedSpell<>(s -> (s.is(HexItems.CYPHER)||s.is(HexItems.ANCIENT_CYPHER)),
HexItems.CYPHER, MediaConstants.CRYSTAL_UNIT)
HexPattern.fromAngles("waqqqqq", HexDir.EAST),
new OpMakePackagedSpell(s -> (s.is(HexItems.CYPHER)||s.is(HexItems.ANCIENT_CYPHER)), HexItems.CYPHER.getDescription(), MediaConstants.CRYSTAL_UNIT)
));
public static final ActionRegistryEntry CRAFT$TRINKET = make("craft/trinket", new ActionRegistryEntry(
HexPattern.fromAngles(
"wwaqqqqqeaqeaeqqqeaeq", HexDir.EAST), new OpMakePackagedSpell<>(s -> s.is(HexItems.TRINKET),
HexItems.TRINKET, 5 * MediaConstants.CRYSTAL_UNIT)));
HexPattern.fromAngles("wwaqqqqqeaqeaeqqqeaeq", HexDir.EAST),
new OpMakePackagedSpell(HexItems.TRINKET, 5 * MediaConstants.CRYSTAL_UNIT)
));
public static final ActionRegistryEntry CRAFT$ARTIFACT = make("craft/artifact", new ActionRegistryEntry(
HexPattern.fromAngles("wwaqqqqqeawqwqwqwqwqwwqqeadaeqqeqqeadaeqq", HexDir.EAST),
new OpMakePackagedSpell<>(s -> s.is(HexItems.ARTIFACT), HexItems.ARTIFACT, 10 * MediaConstants.CRYSTAL_UNIT)
new OpMakePackagedSpell(HexItems.ARTIFACT, 10 * MediaConstants.CRYSTAL_UNIT)
));
public static final ActionRegistryEntry CRAFT$BATTERY = make("craft/battery", new ActionRegistryEntry(
HexPattern.fromAngles("aqqqaqwwaqqqqqeqaqqqawwqwqwqwqwqw", HexDir.SOUTH_WEST), OpMakeBattery.INSTANCE));
Expand Down

0 comments on commit f37f3c7

Please sign in to comment.