Skip to content

Commit 2f060c9

Browse files
authored
Merge branch 'main' into document-allay-flay-cost
2 parents db37c5b + ddb8174 commit 2f060c9

File tree

118 files changed

+2604
-1168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+2604
-1168
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ eclipse
2929
run
3030
.DS_Store
3131

32+
# Idk what prompted gradle to create this folder
33+
Fabric/Fabric
34+
35+
3236
# MacOS moment
3337
.DS_Store
3438

Common/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ repositories {
2828
url = "https://modmaven.dev"
2929
}
3030

31+
maven { url "https://maven.shedaniel.me/" }
32+
3133
}
3234

3335
dependencies {
@@ -37,6 +39,8 @@ dependencies {
3739
compileOnly "at.petra-k.paucal:paucal-common-$minecraftVersion:$paucalVersion"
3840
compileOnly "vazkii.patchouli:Patchouli-xplat:$minecraftVersion-$patchouliVersion-SNAPSHOT"
3941

42+
compileOnly "com.samsthenerd.inline:inline-forge:$minecraftVersion-$inlineVersion"
43+
4044
compileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
4145
testCompileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
4246

Common/src/generated/resources/.cache/e5c5eb35b4ba40351ecb7d9f04c3527f2f5779b0

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// 1.20.1 2023-12-24T17:59:13.7659226 Advancements
1+
// 1.20.1 2024-10-01T23:18:15.2302045 Advancements
22
4016b178322c4784c12c66c227d5b4ff2e43d32d data/hexcasting/advancements/aaa_wasteful_cast.json
33
6469361b24f473b4d7d900828e6bbf2bdabf916b data/hexcasting/advancements/aab_big_cast.json
4+
b4b921ec01322795b41e88406685c3ab7c7d09cc data/hexcasting/advancements/creative_unlocker.json
45
e02605ac2dff5c426e1d0a58d46daefecda11946 data/hexcasting/advancements/enlightenment.json
56
e2679742ac4e23ba4c79c17d209f16d42d7bccd8 data/hexcasting/advancements/lore.json
67
6c3fc955783d450e12494b193e985a403b203f0a data/hexcasting/advancements/lore/cardamom1.json
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"parent": "hexcasting:root",
3+
"criteria": {
4+
"has_creative_unlocker": {
5+
"conditions": {
6+
"items": [
7+
{
8+
"items": [
9+
"hexcasting:creative_unlocker"
10+
]
11+
}
12+
]
13+
},
14+
"trigger": "minecraft:inventory_changed"
15+
}
16+
},
17+
"display": {
18+
"announce_to_chat": false,
19+
"background": "minecraft:textures/block/calcite.png",
20+
"description": {
21+
"translate": "advancement.hexcasting:creative_unlocker.desc"
22+
},
23+
"frame": "task",
24+
"hidden": true,
25+
"icon": {
26+
"item": "hexcasting:creative_unlocker"
27+
},
28+
"show_toast": true,
29+
"title": {
30+
"translate": "advancement.hexcasting:creative_unlocker"
31+
}
32+
},
33+
"requirements": [
34+
[
35+
"has_creative_unlocker"
36+
]
37+
],
38+
"sends_telemetry_event": true
39+
}

Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ fun List<Iota>.getPositiveInt(idx: Int, argc: Int = 0): Int {
199199
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive")
200200
}
201201

202+
fun List<Iota>.getPositiveLong(idx: Int, argc: Int = 0): Long {
203+
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
204+
if (x is DoubleIota) {
205+
val double = x.double
206+
val rounded = double.roundToLong()
207+
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded >= 0) {
208+
return rounded
209+
}
210+
}
211+
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive")
212+
}
213+
202214
fun List<Iota>.getPositiveIntUnder(idx: Int, max: Int, argc: Int = 0): Int {
203215
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
204216
if (x is DoubleIota) {

Common/src/main/java/at/petrak/hexcasting/api/casting/castables/ConstMediaAction.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
77
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
88
import at.petrak.hexcasting.api.casting.iota.Iota
99
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
10+
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughMedia
1011
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
1112

1213
/**
@@ -27,6 +28,8 @@ interface ConstMediaAction : Action {
2728
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
2829
val stack = image.stack.toMutableList()
2930

31+
if (env.extractMedia(this.mediaCost, true) > 0)
32+
throw MishapNotEnoughMedia(this.mediaCost)
3033
if (this.argc > stack.size)
3134
throw MishapNotEnoughArgs(this.argc, stack.size)
3235
val args = stack.takeLast(this.argc)

Common/src/main/java/at/petrak/hexcasting/api/casting/castables/SpellAction.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
99
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
1010
import at.petrak.hexcasting.api.casting.iota.Iota
1111
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
12+
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughMedia
1213
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
1314
import net.minecraft.nbt.CompoundTag
1415

@@ -44,6 +45,8 @@ interface SpellAction : Action {
4445

4546
val sideEffects = mutableListOf<OperatorSideEffect>()
4647

48+
if (env.extractMedia(result.cost, true) > 0)
49+
throw MishapNotEnoughMedia(result.cost)
4750
if (result.cost > 0)
4851
sideEffects.add(OperatorSideEffect.ConsumeMedia(result.cost))
4952

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java

Lines changed: 138 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.minecraft.world.InteractionHand;
2020
import net.minecraft.world.entity.Entity;
2121
import net.minecraft.world.entity.LivingEntity;
22+
import net.minecraft.world.entity.player.Inventory;
2223
import net.minecraft.world.entity.player.Player;
2324
import net.minecraft.world.item.ItemStack;
2425
import net.minecraft.world.phys.Vec3;
@@ -56,11 +57,14 @@ public static void addCreateEventListener(BiConsumer<CastingEnvironment, Compoun
5657

5758
/**
5859
* Add a listener that will be called whenever a new CastingEnvironment is created (legacy).
60+
*
5961
* @deprecated replaced by {@link #addCreateEventListener(BiConsumer)}
6062
*/
6163
@Deprecated(since = "0.11.0-pre-660")
6264
public static void addCreateEventListener(Consumer<CastingEnvironment> listener) {
63-
createEventListeners.add((env, data) -> {listener.accept(env);});
65+
createEventListeners.add((env, data) -> {
66+
listener.accept(env);
67+
});
6468
}
6569

6670
private boolean createEventTriggered = false;
@@ -76,7 +80,8 @@ public final void triggerCreateEvent(CompoundTag userData) {
7680

7781
protected final ServerLevel world;
7882

79-
protected Map<CastingEnvironmentComponent.Key<?>, @NotNull CastingEnvironmentComponent> componentMap = new HashMap<>();
83+
protected Map<CastingEnvironmentComponent.Key<?>, @NotNull CastingEnvironmentComponent> componentMap =
84+
new HashMap<>();
8085
private final List<PostExecution> postExecutions = new ArrayList<>();
8186

8287
private final List<PostCast> postCasts = new ArrayList<>();
@@ -103,16 +108,20 @@ public int maxOpCount() {
103108
* <p>
104109
* Implementations should NOT rely on this in general, use the methods on this class instead.
105110
* This is mostly for spells (flight, etc)
111+
*
106112
* @deprecated as of build 0.11.1-7-pre-619 you are recommended to use {@link #getCastingEntity}
107113
*/
108-
@Deprecated(since="0.11.1-7-pre-619")
114+
@Deprecated(since = "0.11.1-7-pre-619")
109115
@Nullable
110116
public ServerPlayer getCaster() {
111117
return getCastingEntity() instanceof ServerPlayer sp ? sp : null;
112-
};
118+
}
119+
120+
;
113121

114122
/**
115123
* Gets the caster. Can be null if {@link #getCaster()} is also null
124+
*
116125
* @return the entity casting
117126
*/
118127
@Nullable
@@ -237,12 +246,12 @@ public boolean isEnlightened() {
237246
* If there was enough media found, it will return less or equal to zero; if there wasn't, it will be
238247
* positive.
239248
*/
240-
public long extractMedia(long cost) {
249+
public long extractMedia(long cost, boolean simulate) {
241250
for (var extractMediaComponent : preMediaExtract)
242-
cost = extractMediaComponent.onExtractMedia(cost);
243-
cost = extractMediaEnvironment(cost);
251+
cost = extractMediaComponent.onExtractMedia(cost, simulate);
252+
cost = extractMediaEnvironment(cost, simulate);
244253
for (var extractMediaComponent : postMediaExtract)
245-
cost = extractMediaComponent.onExtractMedia(cost);
254+
cost = extractMediaComponent.onExtractMedia(cost, simulate);
246255
return cost;
247256
}
248257

@@ -252,7 +261,7 @@ public long extractMedia(long cost) {
252261
* If there was enough media found, it will return less or equal to zero; if there wasn't, it will be
253262
* positive.
254263
*/
255-
protected abstract long extractMediaEnvironment(long cost);
264+
protected abstract long extractMediaEnvironment(long cost, boolean simulate);
256265

257266
/**
258267
* Get if the vec is close enough, to the player or sentinel ...
@@ -298,7 +307,12 @@ public final boolean isVecInAmbit(Vec3 vec) {
298307
}
299308

300309
public final boolean isEntityInRange(Entity e) {
301-
return (e instanceof Player && HexConfig.server().trueNameHasAmbit()) || (this.isVecInWorld(e.position()) && this.isVecInRange(e.position()));
310+
return isEntityInRange(e, false);
311+
}
312+
313+
public final boolean isEntityInRange(Entity e, boolean ignoreTruenameAmbit) {
314+
boolean truenameCheat = !ignoreTruenameAmbit && (e instanceof Player && HexConfig.server().trueNameHasAmbit());
315+
return truenameCheat || (this.isVecInWorld(e.position()) && this.isVecInRange(e.position()));
302316
}
303317

304318
/**
@@ -360,11 +374,89 @@ public InteractionHand getOtherHand() {
360374
*/
361375
protected abstract List<ItemStack> getUsableStacks(StackDiscoveryMode mode);
362376

377+
protected List<ItemStack> getUsableStacksForPlayer(StackDiscoveryMode mode, @Nullable InteractionHand castingHand
378+
, ServerPlayer caster) {
379+
return switch (mode) {
380+
case QUERY -> {
381+
var out = new ArrayList<ItemStack>();
382+
383+
if (castingHand == null) {
384+
var mainhand = caster.getItemInHand(InteractionHand.MAIN_HAND);
385+
if (!mainhand.isEmpty()) {
386+
out.add(mainhand);
387+
}
388+
389+
var offhand = caster.getItemInHand(InteractionHand.OFF_HAND);
390+
if (!offhand.isEmpty()) {
391+
out.add(offhand);
392+
}
393+
} else {
394+
var offhand = caster.getItemInHand(HexUtils.otherHand(castingHand));
395+
if (!offhand.isEmpty()) {
396+
out.add(offhand);
397+
}
398+
}
399+
400+
// If we're casting from the main hand, try to pick from the slot one to the right of the selected slot
401+
// Otherwise, scan the hotbar left to right
402+
var anchorSlot = castingHand != InteractionHand.OFF_HAND
403+
? (caster.getInventory().selected + 1) % 9
404+
: 0;
405+
406+
407+
for (int delta = 0; delta < 9; delta++) {
408+
var slot = (anchorSlot + delta) % 9;
409+
out.add(caster.getInventory().getItem(slot));
410+
}
411+
412+
yield out;
413+
}
414+
case EXTRACTION -> {
415+
// https://wiki.vg/Inventory is WRONG
416+
// slots 0-8 are the hotbar
417+
// for what purpose i cannot imagine
418+
// http://redditpublic.com/images/b/b2/Items_slot_number.png looks right
419+
// and offhand is 150 Inventory.java:464
420+
var out = new ArrayList<ItemStack>();
421+
422+
// First, the inventory backwards
423+
// We use inv.items here to get the main inventory, but not offhand or armor
424+
Inventory inv = caster.getInventory();
425+
for (int i = inv.items.size() - 1; i >= 0; i--) {
426+
if (i != inv.selected) {
427+
out.add(inv.items.get(i));
428+
}
429+
}
430+
431+
// then the offhand, then the selected hand
432+
out.addAll(inv.offhand);
433+
out.add(inv.getSelected());
434+
435+
yield out;
436+
}
437+
};
438+
}
439+
363440
/**
364441
* Get the primary/secondary item stacks this env can use (i.e. main hand and offhand for the player).
365442
*/
366443
protected abstract List<HeldItemInfo> getPrimaryStacks();
367444

445+
protected List<HeldItemInfo> getPrimaryStacksForPlayer(InteractionHand castingHand, ServerPlayer caster) {
446+
var primaryItem = caster.getItemInHand(castingHand);
447+
448+
if (primaryItem.isEmpty())
449+
primaryItem = ItemStack.EMPTY.copy();
450+
451+
var secondaryItem = caster.getItemInHand(HexUtils.otherHand(castingHand));
452+
453+
if (secondaryItem.isEmpty())
454+
secondaryItem = ItemStack.EMPTY.copy();
455+
456+
return List.of(new HeldItemInfo(secondaryItem, HexUtils.otherHand(castingHand)), new HeldItemInfo(primaryItem,
457+
castingHand));
458+
}
459+
368460
/**
369461
* Return the slot from which to take blocks and items.
370462
*/
@@ -459,9 +551,44 @@ public boolean withdrawItem(Predicate<ItemStack> stackOk, int count, boolean act
459551

460552
/**
461553
* Attempt to replace the first stack found which matches the predicate with the stack to replace with.
554+
*
462555
* @return whether it was successful.
463556
*/
464-
public abstract boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith, @Nullable InteractionHand hand);
557+
public abstract boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith,
558+
@Nullable InteractionHand hand);
559+
560+
561+
public boolean replaceItemForPlayer(Predicate<ItemStack> stackOk, ItemStack replaceWith,
562+
@Nullable InteractionHand hand, ServerPlayer caster) {
563+
if (caster == null)
564+
return false;
565+
566+
if (hand != null && stackOk.test(caster.getItemInHand(hand))) {
567+
caster.setItemInHand(hand, replaceWith);
568+
return true;
569+
}
570+
571+
Inventory inv = caster.getInventory();
572+
for (int i = inv.items.size() - 1; i >= 0; i--) {
573+
if (i != inv.selected) {
574+
if (stackOk.test(inv.items.get(i))) {
575+
inv.setItem(i, replaceWith);
576+
return true;
577+
}
578+
}
579+
}
580+
581+
if (stackOk.test(caster.getItemInHand(getOtherHand()))) {
582+
caster.setItemInHand(getOtherHand(), replaceWith);
583+
return true;
584+
}
585+
if (stackOk.test(caster.getItemInHand(getCastingHand()))) {
586+
caster.setItemInHand(getCastingHand(), replaceWith);
587+
return true;
588+
}
589+
590+
return false;
591+
}
465592

466593
/**
467594
* The order/mode stacks should be discovered in

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironmentComponent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ interface ExtractMedia extends CastingEnvironmentComponent {
2929
* remaining cost after deducting whatever cost source this component
3030
* is responsible for (should be &gt;= 0)
3131
*/
32-
long onExtractMedia(long cost);
32+
long onExtractMedia(long cost, boolean simulate);
3333

3434
/**
35-
* ExtractMedia component that extracts media BEFORE the call to {@link CastingEnvironment#extractMediaEnvironment(long)}
35+
* ExtractMedia component that extracts media BEFORE the call to {@link CastingEnvironment#extractMediaEnvironment(long, boolean)}
3636
*/
3737
interface Pre extends ExtractMedia {}
3838

3939
/**
40-
* ExtractMedia component that extracts media AFTER the call to {@link CastingEnvironment#extractMediaEnvironment(long)}
40+
* ExtractMedia component that extracts media AFTER the call to {@link CastingEnvironment#extractMediaEnvironment(long, boolean)}
4141
* if the input is &lt;= 0 you should also probably return 0 (since media cost was already paid off)
4242
*/
4343
interface Post extends ExtractMedia {}

0 commit comments

Comments
 (0)