Skip to content

Commit

Permalink
Merge branch 'main' into document-allay-flay-cost
Browse files Browse the repository at this point in the history
  • Loading branch information
navarchus authored Nov 25, 2024
2 parents db37c5b + ddb8174 commit 2f060c9
Show file tree
Hide file tree
Showing 118 changed files with 2,604 additions and 1,168 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ eclipse
run
.DS_Store

# Idk what prompted gradle to create this folder
Fabric/Fabric


# MacOS moment
.DS_Store

Expand Down
4 changes: 4 additions & 0 deletions Common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ repositories {
url = "https://modmaven.dev"
}

maven { url "https://maven.shedaniel.me/" }

}

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

compileOnly "com.samsthenerd.inline:inline-forge:$minecraftVersion-$inlineVersion"

compileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
testCompileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 1.20.1 2023-12-24T17:59:13.7659226 Advancements
// 1.20.1 2024-10-01T23:18:15.2302045 Advancements
4016b178322c4784c12c66c227d5b4ff2e43d32d data/hexcasting/advancements/aaa_wasteful_cast.json
6469361b24f473b4d7d900828e6bbf2bdabf916b data/hexcasting/advancements/aab_big_cast.json
b4b921ec01322795b41e88406685c3ab7c7d09cc data/hexcasting/advancements/creative_unlocker.json
e02605ac2dff5c426e1d0a58d46daefecda11946 data/hexcasting/advancements/enlightenment.json
e2679742ac4e23ba4c79c17d209f16d42d7bccd8 data/hexcasting/advancements/lore.json
6c3fc955783d450e12494b193e985a403b203f0a data/hexcasting/advancements/lore/cardamom1.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"parent": "hexcasting:root",
"criteria": {
"has_creative_unlocker": {
"conditions": {
"items": [
{
"items": [
"hexcasting:creative_unlocker"
]
}
]
},
"trigger": "minecraft:inventory_changed"
}
},
"display": {
"announce_to_chat": false,
"background": "minecraft:textures/block/calcite.png",
"description": {
"translate": "advancement.hexcasting:creative_unlocker.desc"
},
"frame": "task",
"hidden": true,
"icon": {
"item": "hexcasting:creative_unlocker"
},
"show_toast": true,
"title": {
"translate": "advancement.hexcasting:creative_unlocker"
}
},
"requirements": [
[
"has_creative_unlocker"
]
],
"sends_telemetry_event": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ fun List<Iota>.getPositiveInt(idx: Int, argc: Int = 0): Int {
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive")
}

fun List<Iota>.getPositiveLong(idx: Int, argc: Int = 0): Long {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is DoubleIota) {
val double = x.double
val rounded = double.roundToLong()
if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded >= 0) {
return rounded
}
}
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive")
}

fun List<Iota>.getPositiveIntUnder(idx: Int, max: Int, argc: Int = 0): Int {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is DoubleIota) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughMedia
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds

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

if (env.extractMedia(this.mediaCost, true) > 0)
throw MishapNotEnoughMedia(this.mediaCost)
if (this.argc > stack.size)
throw MishapNotEnoughArgs(this.argc, stack.size)
val args = stack.takeLast(this.argc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import at.petrak.hexcasting.api.casting.eval.vm.CastingImage
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughMedia
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
import net.minecraft.nbt.CompoundTag

Expand Down Expand Up @@ -44,6 +45,8 @@ interface SpellAction : Action {

val sideEffects = mutableListOf<OperatorSideEffect>()

if (env.extractMedia(result.cost, true) > 0)
throw MishapNotEnoughMedia(result.cost)
if (result.cost > 0)
sideEffects.add(OperatorSideEffect.ConsumeMedia(result.cost))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -56,11 +57,14 @@ public static void addCreateEventListener(BiConsumer<CastingEnvironment, Compoun

/**
* Add a listener that will be called whenever a new CastingEnvironment is created (legacy).
*
* @deprecated replaced by {@link #addCreateEventListener(BiConsumer)}
*/
@Deprecated(since = "0.11.0-pre-660")
public static void addCreateEventListener(Consumer<CastingEnvironment> listener) {
createEventListeners.add((env, data) -> {listener.accept(env);});
createEventListeners.add((env, data) -> {
listener.accept(env);
});
}

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

protected final ServerLevel world;

protected Map<CastingEnvironmentComponent.Key<?>, @NotNull CastingEnvironmentComponent> componentMap = new HashMap<>();
protected Map<CastingEnvironmentComponent.Key<?>, @NotNull CastingEnvironmentComponent> componentMap =
new HashMap<>();
private final List<PostExecution> postExecutions = new ArrayList<>();

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

;

/**
* Gets the caster. Can be null if {@link #getCaster()} is also null
*
* @return the entity casting
*/
@Nullable
Expand Down Expand Up @@ -237,12 +246,12 @@ public boolean isEnlightened() {
* If there was enough media found, it will return less or equal to zero; if there wasn't, it will be
* positive.
*/
public long extractMedia(long cost) {
public long extractMedia(long cost, boolean simulate) {
for (var extractMediaComponent : preMediaExtract)
cost = extractMediaComponent.onExtractMedia(cost);
cost = extractMediaEnvironment(cost);
cost = extractMediaComponent.onExtractMedia(cost, simulate);
cost = extractMediaEnvironment(cost, simulate);
for (var extractMediaComponent : postMediaExtract)
cost = extractMediaComponent.onExtractMedia(cost);
cost = extractMediaComponent.onExtractMedia(cost, simulate);
return cost;
}

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

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

public final boolean isEntityInRange(Entity e) {
return (e instanceof Player && HexConfig.server().trueNameHasAmbit()) || (this.isVecInWorld(e.position()) && this.isVecInRange(e.position()));
return isEntityInRange(e, false);
}

public final boolean isEntityInRange(Entity e, boolean ignoreTruenameAmbit) {
boolean truenameCheat = !ignoreTruenameAmbit && (e instanceof Player && HexConfig.server().trueNameHasAmbit());
return truenameCheat || (this.isVecInWorld(e.position()) && this.isVecInRange(e.position()));
}

/**
Expand Down Expand Up @@ -360,11 +374,89 @@ public InteractionHand getOtherHand() {
*/
protected abstract List<ItemStack> getUsableStacks(StackDiscoveryMode mode);

protected List<ItemStack> getUsableStacksForPlayer(StackDiscoveryMode mode, @Nullable InteractionHand castingHand
, ServerPlayer caster) {
return switch (mode) {
case QUERY -> {
var out = new ArrayList<ItemStack>();

if (castingHand == null) {
var mainhand = caster.getItemInHand(InteractionHand.MAIN_HAND);
if (!mainhand.isEmpty()) {
out.add(mainhand);
}

var offhand = caster.getItemInHand(InteractionHand.OFF_HAND);
if (!offhand.isEmpty()) {
out.add(offhand);
}
} else {
var offhand = caster.getItemInHand(HexUtils.otherHand(castingHand));
if (!offhand.isEmpty()) {
out.add(offhand);
}
}

// If we're casting from the main hand, try to pick from the slot one to the right of the selected slot
// Otherwise, scan the hotbar left to right
var anchorSlot = castingHand != InteractionHand.OFF_HAND
? (caster.getInventory().selected + 1) % 9
: 0;


for (int delta = 0; delta < 9; delta++) {
var slot = (anchorSlot + delta) % 9;
out.add(caster.getInventory().getItem(slot));
}

yield out;
}
case EXTRACTION -> {
// https://wiki.vg/Inventory is WRONG
// slots 0-8 are the hotbar
// for what purpose i cannot imagine
// http://redditpublic.com/images/b/b2/Items_slot_number.png looks right
// and offhand is 150 Inventory.java:464
var out = new ArrayList<ItemStack>();

// First, the inventory backwards
// We use inv.items here to get the main inventory, but not offhand or armor
Inventory inv = caster.getInventory();
for (int i = inv.items.size() - 1; i >= 0; i--) {
if (i != inv.selected) {
out.add(inv.items.get(i));
}
}

// then the offhand, then the selected hand
out.addAll(inv.offhand);
out.add(inv.getSelected());

yield out;
}
};
}

/**
* Get the primary/secondary item stacks this env can use (i.e. main hand and offhand for the player).
*/
protected abstract List<HeldItemInfo> getPrimaryStacks();

protected List<HeldItemInfo> getPrimaryStacksForPlayer(InteractionHand castingHand, ServerPlayer caster) {
var primaryItem = caster.getItemInHand(castingHand);

if (primaryItem.isEmpty())
primaryItem = ItemStack.EMPTY.copy();

var secondaryItem = caster.getItemInHand(HexUtils.otherHand(castingHand));

if (secondaryItem.isEmpty())
secondaryItem = ItemStack.EMPTY.copy();

return List.of(new HeldItemInfo(secondaryItem, HexUtils.otherHand(castingHand)), new HeldItemInfo(primaryItem,
castingHand));
}

/**
* Return the slot from which to take blocks and items.
*/
Expand Down Expand Up @@ -459,9 +551,44 @@ public boolean withdrawItem(Predicate<ItemStack> stackOk, int count, boolean act

/**
* Attempt to replace the first stack found which matches the predicate with the stack to replace with.
*
* @return whether it was successful.
*/
public abstract boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith, @Nullable InteractionHand hand);
public abstract boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith,
@Nullable InteractionHand hand);


public boolean replaceItemForPlayer(Predicate<ItemStack> stackOk, ItemStack replaceWith,
@Nullable InteractionHand hand, ServerPlayer caster) {
if (caster == null)
return false;

if (hand != null && stackOk.test(caster.getItemInHand(hand))) {
caster.setItemInHand(hand, replaceWith);
return true;
}

Inventory inv = caster.getInventory();
for (int i = inv.items.size() - 1; i >= 0; i--) {
if (i != inv.selected) {
if (stackOk.test(inv.items.get(i))) {
inv.setItem(i, replaceWith);
return true;
}
}
}

if (stackOk.test(caster.getItemInHand(getOtherHand()))) {
caster.setItemInHand(getOtherHand(), replaceWith);
return true;
}
if (stackOk.test(caster.getItemInHand(getCastingHand()))) {
caster.setItemInHand(getCastingHand(), replaceWith);
return true;
}

return false;
}

/**
* The order/mode stacks should be discovered in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ interface ExtractMedia extends CastingEnvironmentComponent {
* remaining cost after deducting whatever cost source this component
* is responsible for (should be &gt;= 0)
*/
long onExtractMedia(long cost);
long onExtractMedia(long cost, boolean simulate);

/**
* ExtractMedia component that extracts media BEFORE the call to {@link CastingEnvironment#extractMediaEnvironment(long)}
* ExtractMedia component that extracts media BEFORE the call to {@link CastingEnvironment#extractMediaEnvironment(long, boolean)}
*/
interface Pre extends ExtractMedia {}

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

0 comments on commit 2f060c9

Please sign in to comment.