Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Codecs to serializable classes #718

Draft
wants to merge 77 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
7c80b62
implement codecs on serializable classes
Master-Bw3 Aug 12, 2024
a70621e
switch everything to use codecs
Master-Bw3 Aug 12, 2024
2b497e8
Fixed the Hex Notebook not appearing in the creative tab
Auroali Jun 25, 2024
9cead0b
possibly fix overcast dammage
walksanatora Jun 14, 2024
3f1f5be
remove redundant file
walksanatora Jun 15, 2024
114d2f2
Implement datagen for damage type definitions and tags
object-Object Jun 23, 2024
21b6eda
ok, added `inavid_operator_args` and associated stuff
kineticneticat Jul 12, 2024
652c100
do all the things
kineticneticat Jul 12, 2024
3d0ca17
Fix minor code style issues in MishapInvalidOperatorArgs
object-Object Jul 13, 2024
6d55530
6 lines to get this working...
walksanatora Jul 13, 2024
6e301ab
remove dead import
walksanatora Jul 13, 2024
325b81c
Remove gradle clean step
object-Object Jul 13, 2024
4089403
Use nick-fields/retry action to work around intermittent ForgeGradle …
object-Object Jul 13, 2024
faf140e
Add step to upload build artifacts
object-Object Aug 21, 2024
2519a50
Fix #585, Power Distillation should mishap when taking the square roo…
Talia-12 Feb 5, 2024
dcd65dc
Fix #551, White Sun's Zeniths at level 0 gives a high regen for free.
Talia-12 Feb 5, 2024
b9ef3af
Fixed #545 (Cannot read null from empty scrolls/slates) by defaulting…
Talia-12 Feb 5, 2024
3e84e72
Fixed #541, allow MediaHolderItems to specify their consumptionPriority.
Talia-12 Feb 6, 2024
1df5a38
Fixed #515
Talia-12 Feb 6, 2024
5b68df4
Mostly implement accepted solution for #545 (no reading from things w…
Talia-12 Feb 6, 2024
f4f505f
fix OpWritable for items that only accept specific types of iotas by …
Talia-12 Feb 6, 2024
e6468ff
refactor some unnecessary slowdown points found (repeatedly sending p…
Talia-12 Feb 6, 2024
83790b8
refactor moar, increase the default max op count since it is now fast…
Talia-12 Feb 6, 2024
d47d2b3
Fix #608, advancements based on amount of media spent no longer trigg…
Talia-12 Feb 6, 2024
88442e6
update
ChuijkYahus Jul 16, 2024
52581ad
Fixed spelling mistakes, mostly replaced all occurencies of english w…
Jul 18, 2024
ff84feb
Translate Impetus, Directrix
Jul 20, 2024
f1d7ef8
Fix spelling mistake
Jul 22, 2024
054ce4c
mend
Jul 22, 2024
4f2657b
Remove ForgeMixinDatagenModLoader, as it doesn't seem to actually be …
object-Object Jul 23, 2024
c7f608d
make focus and thought knot re-use some writeable checks
SamsTheNerd Aug 2, 2024
9fb3e75
switch power_neg to exponent. translation is close enough imo?
SamsTheNerd Aug 2, 2024
9eec8cf
Add comments and refactor some code to improve clarity
object-Object Aug 12, 2024
d1b7739
crash slain (closes #661)
walksanatora Jul 28, 2024
0f2e7a3
Make Break Block check for permission
vgskye Aug 14, 2024
aa46643
Allow for playerless block raycasts
vgskye Aug 19, 2024
86e603e
Remove unnecessary MixinClipContext mixin (see comments of #719)
object-Object Aug 20, 2024
1b68227
Prevent crashes due to unbounded growth of a few items. Add configura…
navarchus Aug 20, 2024
1706ed6
Address comments in discord, scale back changes to mishaps and revert…
Aug 20, 2024
bec992e
formatting revert 2
Aug 20, 2024
69ed2ad
copy result instead of casting to mutable list
Aug 20, 2024
02ab6f1
addressed comments
Aug 20, 2024
75c2de6
Update Common/src/main/resources/assets/hexcasting/lang/en_us.flatten…
navarchus Aug 20, 2024
2dfa914
Fixes Empty Impetus not accepting pulses from the back.
vgskye Aug 15, 2024
125a71b
Don't try to getStoredPlayer on client
vgskye Aug 19, 2024
cb1f0e3
Trigger Gradle build on pushes to the default branch so the cache sta…
object-Object Aug 21, 2024
3b22ef4
Flatten build artifact structure and add artifact name
object-Object Aug 21, 2024
6874eb1
Try running build and datagen in parallel
object-Object Aug 21, 2024
83999ad
Add 30-day retention period to mod-build artifact
object-Object Aug 21, 2024
b9d047b
fix undefined translations strings in en_us, "death.attack.hexcasting…
navarchus Aug 21, 2024
e2ebfce
run datagen
navarchus Aug 21, 2024
2bd293c
ugly but valid bugfix
navarchus Aug 21, 2024
afc0017
slightly less ugly bugfux
navarchus Aug 21, 2024
c6ec200
nice bugfix
navarchus Aug 21, 2024
bd2f833
remove vestigial imports
navarchus Aug 21, 2024
d095f0a
reverse whitespace change
Aug 21, 2024
7d78fc2
reverse whitespace change - 2
Aug 21, 2024
de2e77f
run datagen & update translation strings
navarchus Aug 21, 2024
7305458
Render altiora sheaf on fabric
vgskye Aug 22, 2024
c95fa81
add a override for the old method as to not break other addons
walksanatora Aug 23, 2024
a2f8fda
Deprecate the old method
walksanatora Aug 23, 2024
bafd222
document stack size mishap
navarchus Aug 23, 2024
7f9888d
funny joke
navarchus Aug 23, 2024
8596e64
implement thanatos' reflection (placeholder name for OpThanos)
navarchus Aug 23, 2024
45ecc03
update thanatos description
navarchus Aug 23, 2024
f4a96ef
solve halting problem
navarchus Aug 23, 2024
be3a5ac
add localization entry for location_too_far
navarchus Aug 23, 2024
7555194
yep this works
navarchus Aug 23, 2024
250b9d1
china and russia can have translations too I guess
navarchus Aug 23, 2024
68c7b10
Check for Sprint bind instead of Ctrl for ShiftScrollListener
vgskye Aug 24, 2024
b2dc52b
Use Patchouli keybind formatting for abacus ctrl/sprint mode instead …
object-Object Aug 24, 2024
57af646
Remove Shame On You and have Gemini throw TMI above 1024 instead
vgskye Aug 24, 2024
66f5faf
Don't throw TMI in OpDuplicateN to remove mishap message discrepancy
vgskye Aug 24, 2024
f16a169
Make explosions at eye position deal damage again because it's confus…
gamma-delta Aug 26, 2024
417b2d2
Empty commit to test if i still have to make MRs
gamma-delta Aug 26, 2024
bfad3f7
Make Break Block super cheap on conjured blocks (including a new fanc…
gamma-delta Aug 27, 2024
0f34125
implement codecs on serializable classes
Master-Bw3 Aug 12, 2024
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
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
@@ -0,0 +1,5 @@
{
"values": [
"hexcasting:overcast"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"hexcasting:overcast"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"hexcasting:overcast"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.utils.HexUtils;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import org.jetbrains.annotations.Nullable;
Expand All @@ -14,7 +15,7 @@ public interface ADIotaHolder {
default Iota readIota(ServerLevel world) {
var tag = readIotaTag();
if (tag != null) {
return IotaType.deserialize(tag, world);
return HexUtils.deserializeWithCodec(tag, Iota.getCodec(world));
} else {
return null;
}
Expand All @@ -29,4 +30,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 @@ -4,11 +4,13 @@ package at.petrak.hexcasting.api.casting

import at.petrak.hexcasting.api.casting.iota.*
import at.petrak.hexcasting.api.casting.math.HexPattern
import at.petrak.hexcasting.api.casting.mishaps.MishapEntityNotFound
import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import com.mojang.datafixers.util.Either
import net.minecraft.core.BlockPos
import net.minecraft.server.level.ServerLevel
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.LivingEntity
Expand All @@ -32,10 +34,10 @@ fun List<Iota>.getDouble(idx: Int, argc: Int = 0): Double {
}
}

fun List<Iota>.getEntity(idx: Int, argc: Int = 0): Entity {
fun List<Iota>.getEntity(idx: Int, argc: Int = 0, world: ServerLevel): Entity {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
return x.entity
return x.getEntity(world)?: throw MishapEntityNotFound(x, if (argc == 0) idx else argc - (idx + 1))
} else {
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "entity")
}
Expand Down Expand Up @@ -79,40 +81,40 @@ fun List<Iota>.getBool(idx: Int, argc: Int = 0): Boolean {

// Helpers

fun List<Iota>.getItemEntity(idx: Int, argc: Int = 0): ItemEntity {
fun List<Iota>.getItemEntity(idx: Int, argc: Int = 0, world: ServerLevel): ItemEntity {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
val e = x.entity
val e = x.getEntity(world)?: throw MishapEntityNotFound(x, if (argc == 0) idx else argc - (idx + 1))
if (e is ItemEntity)
return e
}
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "entity.item")
}

fun List<Iota>.getPlayer(idx: Int, argc: Int = 0): ServerPlayer {
fun List<Iota>.getPlayer(idx: Int, argc: Int = 0, world: ServerLevel): ServerPlayer {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
val e = x.entity
val e = x.getEntity(world)?: throw MishapEntityNotFound(x, if (argc == 0) idx else argc - (idx + 1))
if (e is ServerPlayer)
return e
}
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "entity.player")
}

fun List<Iota>.getMob(idx: Int, argc: Int = 0): Mob {
fun List<Iota>.getMob(idx: Int, argc: Int = 0, world: ServerLevel): Mob {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
val e = x.entity
val e = x.getEntity(world)?: throw MishapEntityNotFound(x, if (argc == 0) idx else argc - (idx + 1))
if (e is Mob)
return e
}
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "entity.mob")
}

fun List<Iota>.getLivingEntityButNotArmorStand(idx: Int, argc: Int = 0): LivingEntity {
fun List<Iota>.getLivingEntityButNotArmorStand(idx: Int, argc: Int = 0, world: ServerLevel): LivingEntity {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
val e = x.entity
val e = x.getEntity(world)?: throw MishapEntityNotFound(x, if (argc == 0) idx else argc - (idx + 1))
if (e is LivingEntity && e !is ArmorStand)
return e
}
Expand Down
11 changes: 11 additions & 0 deletions Common/src/main/java/at/petrak/hexcasting/api/casting/SpellList.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package at.petrak.hexcasting.api.casting

import at.petrak.hexcasting.api.casting.iota.Iota
import com.mojang.serialization.Codec
import net.minecraft.server.level.ServerLevel
import java.util.Collections

/**
* Restricted interface for functional lists.
Expand Down Expand Up @@ -90,4 +93,12 @@ sealed class SpellList : Iterable<Iota> {
return car
}
}

companion object {
@JvmStatic
fun getCodec(): Codec<SpellList> = Iota.getCodec().listOf().xmap(SpellList::LList, SpellList::toMutableList)

@JvmStatic
fun getCodec(world: ServerLevel): Codec<SpellList> = Iota.getCodec(world).listOf().xmap(SpellList::LList, SpellList::toMutableList)
}
}
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
Loading