Skip to content

Commit

Permalink
Merge branch 'main' into fix-misc-docs-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object authored Aug 24, 2024
2 parents 5b1fdac + 45d519d commit 2a5683e
Show file tree
Hide file tree
Showing 96 changed files with 3,080 additions and 1,474 deletions.
55 changes: 46 additions & 9 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ name: Build pull request
on:
pull_request:
workflow_dispatch:
# trigger on pushes to the default branch (main) to keep the cache up to date
push:
branches: main

env:
JAVA_VERSION: '17.0.1'

jobs:
build:
Expand All @@ -17,26 +23,57 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17.0.1"
java-version: ${{ env.JAVA_VERSION }}
- uses: gradle/actions/setup-gradle@v3
- name: Clean

- name: Build
run: |
chmod +x gradlew
./gradlew clean
./gradlew build
- name: Build
run: ./gradlew build
- name: Prepare artifacts for upload
run: |
mkdir -p dist
cp {Common,Forge,Fabric}/build/libs/*.jar dist
- name: Run Datagen
run: ./gradlew runAllDatagen
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: mod-build
path: dist
retention-days: 30

datagen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- uses: gradle/actions/setup-gradle@v3

# ForgeGradle datagen asset download often fails (see #692)
# so just allow it to automatically retry a few times
- name: Run datagen
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: |
chmod +x gradlew
./gradlew runAllDatagen
- name: Check Datagen
- name: Check datagen
run: |
git add --intent-to-add .
git diff --name-only --exit-code -- ":!:*/src/generated/resources/.cache/*"
hexdoc:
# don't bother running the docs build when pushing to main - nothing necessary to cache here
if: github.event_name != 'push'
uses: hexdoc-dev/hexdoc/.github/workflows/hexdoc.yml@main
permissions:
contents: write
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exhaustion": 0,
"exhaustion": 0.0,
"message_id": "hexcasting.overcast",
"scaling": "when_caused_by_living_non_player"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exhaustion": 0,
"exhaustion": 0.0,
"message_id": "hexcasting.shame",
"scaling": "when_caused_by_living_non_player"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"hexcasting:overcast",
"hexcasting:shame"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"hexcasting:overcast",
"hexcasting:shame"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"hexcasting:shame"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"hexcasting:overcast",
"hexcasting:shame"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ default Iota emptyIota() {
* @return if the writing succeeded/would succeed
*/
boolean writeIota(@Nullable Iota iota, boolean simulate);

/**
* @return whether it is possible to write to this IotaHolder
*/
boolean writeable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public ItemDelegatingEntityIotaHolder(Supplier<ItemStack> stackSupplier, Consume
return delegate == null ? null : delegate.readIotaTag();
}

@Override
public boolean writeable() {
var delegate = IXplatAbstractions.INSTANCE.findDataHolder(this.stackSupplier.get());
return delegate != null && delegate.writeable();
}

@Override
public boolean writeIota(@Nullable Iota datum, boolean simulate) {
var stacc = this.stackSupplier.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package at.petrak.hexcasting.api.advancements;

import com.google.gson.JsonElement;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.BuiltInExceptionProvider;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.util.GsonHelper;

import javax.annotation.Nullable;
import java.util.Objects;
import java.util.function.Function;

public class MinMaxLongs extends MinMaxBounds<Long> {
public static final MinMaxLongs ANY = new MinMaxLongs(null, null);
@Nullable
private final Long minSq;
@Nullable
private final Long maxSq;

private static MinMaxLongs create(StringReader reader, @Nullable Long min, @Nullable Long max) throws CommandSyntaxException {
if (min != null && max != null && min > max) {
throw ERROR_SWAPPED.createWithContext(reader);
} else {
return new MinMaxLongs(min, max);
}
}

@Nullable
private static Long squareOpt(@Nullable Long l) {
return l == null ? null : l * l;
}

private MinMaxLongs(@Nullable Long min, @Nullable Long max) {
super(min, max);
this.minSq = squareOpt(min);
this.maxSq = squareOpt(max);
}

public static MinMaxLongs exactly(long l) {
return new MinMaxLongs(l, l);
}

public static MinMaxLongs between(long min, long max) {
return new MinMaxLongs(min, max);
}

public static MinMaxLongs atLeast(long min) {
return new MinMaxLongs(min, null);
}

public static MinMaxLongs atMost(long max) {
return new MinMaxLongs(null, max);
}

public boolean matches(long l) {
if (this.min != null && this.min > l) {
return false;
} else {
return this.max == null || this.max >= l;
}
}

public boolean matchesSqr(long l) {
if (this.minSq != null && this.minSq > l) {
return false;
} else {
return this.maxSq == null || this.maxSq >= l;
}
}

public static MinMaxLongs fromJson(@Nullable JsonElement json) {
return fromJson(json, ANY, GsonHelper::convertToLong, MinMaxLongs::new);
}

public static MinMaxLongs fromReader(StringReader reader) throws CommandSyntaxException {
return fromReader(reader, (l) -> l);
}

public static MinMaxLongs fromReader(StringReader reader, Function<Long, Long> map) throws CommandSyntaxException {
BuiltInExceptionProvider builtInExceptions = CommandSyntaxException.BUILT_IN_EXCEPTIONS;
Objects.requireNonNull(builtInExceptions);
return fromReader(reader, MinMaxLongs::create, Long::parseLong, builtInExceptions::readerInvalidInt, map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public ResourceLocation getId() {
protected Instance createInstance(JsonObject json, ContextAwarePredicate predicate,
DeserializationContext context) {
return new Instance(predicate,
MinMaxBounds.Ints.fromJson(json.get(TAG_MEDIA_SPENT)),
MinMaxBounds.Ints.fromJson(json.get(TAG_MEDIA_WASTED)));
MinMaxLongs.fromJson(json.get(TAG_MEDIA_SPENT)),
MinMaxLongs.fromJson(json.get(TAG_MEDIA_WASTED)));
}

public void trigger(ServerPlayer player, int mediaSpent, int mediaWasted) {
public void trigger(ServerPlayer player, long mediaSpent, long mediaWasted) {
super.trigger(player, inst -> inst.test(mediaSpent, mediaWasted));
}

public static class Instance extends AbstractCriterionTriggerInstance {
protected final MinMaxBounds.Ints mediaSpent;
protected final MinMaxBounds.Ints mediaWasted;
protected final MinMaxLongs mediaSpent;
protected final MinMaxLongs mediaWasted;

public Instance(ContextAwarePredicate predicate, MinMaxBounds.Ints mediaSpent,
MinMaxBounds.Ints mediaWasted) {
public Instance(ContextAwarePredicate predicate, MinMaxLongs mediaSpent,
MinMaxLongs mediaWasted) {
super(SpendMediaTrigger.ID, predicate);
this.mediaSpent = mediaSpent;
this.mediaWasted = mediaWasted;
Expand All @@ -56,7 +56,7 @@ public JsonObject serializeToJson(SerializationContext ctx) {
return json;
}

private boolean test(int mediaSpentIn, int mediaWastedIn) {
private boolean test(long mediaSpentIn, long mediaWastedIn) {
return this.mediaSpent.matches(mediaSpentIn) && this.mediaWasted.matches(mediaWastedIn);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class OperationAction(val pattern: HexPattern) : Action {
return try {
HexArithmetics.getEngine().run(pattern, env, image, continuation)
} catch (e: NoOperatorCandidatesException) {
throw MishapInvalidOperatorArgs(e.args, e.pattern)
throw MishapInvalidOperatorArgs(e.args)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ public boolean tick(BlockEntityAbstractImpetus impetus) {
var ctrl = executor.acceptControlFlow(this.currentImage, env, this.enteredFrom, this.currentPos,
executorBlockState, world);

if (env.getImpetus() == null)
return false; //the impetus got removed during the cast and no longer exists in the world. stop casting

if (ctrl instanceof ICircleComponent.ControlFlow.Stop) {
// acceptControlFlow should have already posted the error
halt = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import at.petrak.hexcasting.api.casting.ParticleSpray;
import at.petrak.hexcasting.api.casting.PatternShapeMatch;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.casting.mishaps.Mishap;
import at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation;
import at.petrak.hexcasting.api.casting.mishaps.MishapDisallowedSpell;
Expand All @@ -10,6 +11,7 @@
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -27,6 +29,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Predicate;

Expand All @@ -42,21 +45,30 @@ public abstract class CastingEnvironment {
/**
* Stores all listeners that should be notified whenever a CastingEnvironment is initialised.
*/
private static final List<Consumer<CastingEnvironment>> createEventListeners = new ArrayList<>();
private static final List<BiConsumer<CastingEnvironment, CompoundTag>> createEventListeners = new ArrayList<>();

/**
* Add a listener that will be called whenever a new CastingEnvironment is created.
*/
public static void addCreateEventListener(Consumer<CastingEnvironment> listener) {
public static void addCreateEventListener(BiConsumer<CastingEnvironment, CompoundTag> listener) {
createEventListeners.add(listener);
}

/**
* 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);});
}

private boolean createEventTriggered = false;

public final void triggerCreateEvent() {
public final void triggerCreateEvent(CompoundTag userData) {
if (!createEventTriggered) {
for (var listener : createEventListeners)
listener.accept(this);
listener.accept(this, userData);
createEventTriggered = true;
}
}
Expand All @@ -66,6 +78,8 @@ public final void triggerCreateEvent() {

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

private final List<PostCast> postCasts = new ArrayList<>();
private final List<ExtractMedia.Pre> preMediaExtract = new ArrayList<>();
private final List<ExtractMedia.Post> postMediaExtract = new ArrayList<>();

Expand Down Expand Up @@ -113,6 +127,8 @@ public <T extends CastingEnvironmentComponent> void addExtension(@NotNull T exte
componentMap.put(extension.getKey(), extension);
if (extension instanceof PostExecution postExecution)
postExecutions.add(postExecution);
if (extension instanceof PostCast postCast)
postCasts.add(postCast);
if (extension instanceof ExtractMedia extractMedia)
if (extension instanceof ExtractMedia.Pre pre) {
preMediaExtract.add(pre);
Expand All @@ -132,6 +148,8 @@ public void removeExtension(@NotNull CastingEnvironmentComponent.Key<?> key) {

if (extension instanceof PostExecution postExecution)
postExecutions.remove(postExecution);
if (extension instanceof PostCast postCast)
postCasts.remove(postCast);
if (extension instanceof ExtractMedia extractMedia)
if (extension instanceof ExtractMedia.Pre pre) {
preMediaExtract.remove(pre);
Expand Down Expand Up @@ -188,6 +206,14 @@ public void postExecution(CastResult result) {
postExecutionComponent.onPostExecution(result);
}

/**
* Do things after the whole cast is finished (i.e. every pattern to be executed has been executed).
*/
public void postCast(CastingImage image) {
for (var postCastComponent : postCasts)
postCastComponent.onPostCast(image);
}

public abstract Vec3 mishapSprayPos();

/**
Expand Down
Loading

0 comments on commit 2a5683e

Please sign in to comment.