Skip to content

Commit 5628146

Browse files
committed
Merge branch '1.21.11' into 1.21.11-unobf
2 parents 16acfbb + 70bf99f commit 5628146

9 files changed

Lines changed: 57 additions & 50 deletions

File tree

src/main/java/eu/ha3/presencefootsteps/sound/Isolator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public boolean load(ResourceManager manager) {
8383
return lookup.load(entries, globalBlocks()) ? lookup : null;
8484
}));
8585
hasConfigurations |= !blocks.isEmpty();
86-
hasConfigurations |= ResourceUtils.forEach(BIOME_MAP, manager, biomes()::load);
86+
hasConfigurations |= ResourceUtils.forEach(BIOME_MAP, manager, biomes().createLoader());
8787
hasConfigurations |= golems().load(ResourceUtils.load(GOLEM_MAP, manager, GolemLookup::new));
8888
hasConfigurations |= primitives().load(ResourceUtils.load(PRIMITIVE_MAP, manager, PrimitiveLookup::new));
89-
hasConfigurations |= ResourceUtils.forEach(LOCOMOTION_MAP, manager, locomotions()::load);
89+
hasConfigurations |= ResourceUtils.forEach(LOCOMOTION_MAP, manager, locomotions().createLoader());
9090
var acoustics = ResourceUtils.loadAll(ACOUSTICS, manager, Acoustic.CODEC);
9191
hasConfigurations |= !acoustics.isEmpty();
9292
acoustics.forEach((id, acoustic) -> {

src/main/java/eu/ha3/presencefootsteps/sound/acoustics/Acoustic.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface Acoustic {
2828
MapCodec<Acoustic> MAP_CODEC = Codec.STRING.dispatchMap(Acoustic::type, TYPES::get);
2929
Codec<Acoustic> CODEC = Codec.xor(Codec.lazyInitialized(() -> SimultaneousAcoustic.CODEC.xmap(i -> (Acoustic)i, i-> (SimultaneousAcoustic)i)), MAP_CODEC.codec()).xmap(
3030
either -> Either.unwrap(either),
31-
acoustic -> acoustic.type() == "simultaneous" ? Either.left(acoustic) : Either.right(acoustic)
31+
acoustic -> Acoustic.SIMULTANEOUS.contentEquals(acoustic.type()) ? Either.left(acoustic) : Either.right(acoustic)
3232
);
3333
String BASIC = register("basic", VaryingAcoustic.CODEC);
3434
String EVENTS = register("events", EventSelectorAcoustics.CODEC);
@@ -78,11 +78,11 @@ private static String getType(JsonElement unsolved, String defaultUnassigned) {
7878
}
7979

8080
if (unsolved.isJsonArray()) {
81-
return "simultaneous";
81+
return SIMULTANEOUS;
8282
}
8383

8484
if (unsolved.isJsonPrimitive() && unsolved.getAsJsonPrimitive().isString()) {
85-
return "basic";
85+
return BASIC;
8686
}
8787

8888
return "";

src/main/java/eu/ha3/presencefootsteps/util/Range.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public record Range (float min, float max) {
1717
PERCENTAGE_CODEC.fieldOf("max").forGetter(Range::max)
1818
).apply(i, Range::new));
1919
private static final Codec<Range> POINT_CODEC = PERCENTAGE_CODEC.xmap(Range::exactly, Range::min);
20-
public static final Codec<Range> CODEC = Codec.xor(POINT_CODEC, RANGE_CODEC).xmap(either -> Either.unwrap(either), i -> Mth.equal(i.min(), i.max()) ? Either.left(i) : Either.right(i));
20+
public static final Codec<Range> CODEC = Codec.xor(POINT_CODEC, RANGE_CODEC).xmap(
21+
Either::unwrap,
22+
i -> Mth.equal(i.min(), i.max()) ? Either.left(i) : Either.right(i)
23+
);
2124

2225
public static final Range DEFAULT = exactly(1);
2326

src/main/java/eu/ha3/presencefootsteps/world/BiomeVarianceLookup.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.HashMap;
55
import java.util.Map;
66

7-
import com.google.gson.JsonElement;
87
import com.mojang.datafixers.util.Pair;
98
import com.mojang.serialization.Codec;
109
import com.mojang.serialization.JsonOps;
@@ -28,10 +27,12 @@ public boolean contains(Identifier key) {
2827
}
2928

3029
@Override
31-
public void add(String key, JsonElement value) {
32-
BiomeVariance.CODEC.decode(JsonOps.INSTANCE, value).result().map(Pair::getFirst).ifPresent(i -> {
33-
entries.put(Identifier.parse(key), i);
34-
});
30+
public Loader createLoader() {
31+
return (key, value) -> {
32+
BiomeVariance.CODEC.decode(JsonOps.INSTANCE, value).result().map(Pair::getFirst).ifPresent(i -> {
33+
entries.put(Identifier.parse(key), i);
34+
});
35+
};
3536
}
3637

3738
@Override

src/main/java/eu/ha3/presencefootsteps/world/ContextualBlockState.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public record ContextualBlockState(EntityType<?> type, BlockState state) {
1212
state -> new ContextualBlockState(entityType, state)
1313
));
1414

15-
1615
public static ContextualBlockState of(EntityType<?> type, BlockState state) {
1716
return CACHE.apply(type).apply(state);
1817
}
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
package eu.ha3.presencefootsteps.world;
22

3+
import java.io.Reader;
4+
import java.util.function.Consumer;
5+
6+
import com.google.gson.Gson;
7+
import com.google.gson.JsonElement;
8+
import com.google.gson.JsonObject;
9+
310
import eu.ha3.presencefootsteps.util.BlockReport.Reportable;
411
import net.minecraft.resources.Identifier;
512

6-
public interface Index<K, V> extends Loadable, Reportable {
13+
public interface Index<K, V> extends Reportable {
14+
/**
15+
* Finds the mapped result for a given key.
16+
*/
717
V lookup(K key);
818

19+
/**
20+
* Checks whether the given key identifier contains a mapping in this index.
21+
*/
922
boolean contains(Identifier key);
23+
24+
/**
25+
* Creates a resource loader to populate this index.
26+
*/
27+
Loader createLoader();
28+
29+
interface Loader extends Consumer<Reader> {
30+
Gson GSON = new Gson();
31+
32+
@Override
33+
default void accept(Reader reader) {
34+
JsonObject json = GSON.fromJson(reader, JsonObject.class);
35+
36+
json.entrySet().forEach(entry -> {
37+
accept(entry.getKey(), entry.getValue());
38+
});
39+
}
40+
41+
void accept(String key, JsonElement json);
42+
}
1043
}

src/main/java/eu/ha3/presencefootsteps/world/Loadable.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main/java/eu/ha3/presencefootsteps/world/LocomotionLookup.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import java.io.IOException;
1919
import java.util.Map;
2020

21-
import com.google.gson.JsonElement;
22-
2321
public class LocomotionLookup implements Index<Entity, Locomotion> {
2422
private final Map<Identifier, Locomotion> values = new Object2ObjectLinkedOpenHashMap<>();
2523

@@ -38,14 +36,16 @@ public Locomotion lookup(Entity key) {
3836
}
3937

4038
@Override
41-
public void add(String key, JsonElement value) {
42-
Identifier id = Identifier.parse(key);
39+
public Loader createLoader() {
40+
return (key, value) -> {
41+
Identifier id = Identifier.parse(key);
4342

44-
if (!BuiltInRegistries.ENTITY_TYPE.containsKey(id)) {
45-
PresenceFootsteps.logger.warn("Locomotion registered for unknown entity type " + id);
46-
}
43+
if (!BuiltInRegistries.ENTITY_TYPE.containsKey(id)) {
44+
PresenceFootsteps.logger.warn("Locomotion registered for unknown entity type " + id);
45+
}
4746

48-
values.put(id, Locomotion.byName(value.getAsString().toUpperCase()));
47+
values.put(id, Locomotion.byName(value.getAsString().toUpperCase()));
48+
};
4949
}
5050

5151
@Override

src/main/resources/presencefootsteps.mixin.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"required": true,
33
"minVersion": "0.7",
44
"package": "eu.ha3.presencefootsteps.mixins",
5-
"refmap": "presencefootsteps.mixin.refmap.json",
65
"compatibilityLevel": "JAVA_17",
76
"client": [
87
"MAbstractBlock",

0 commit comments

Comments
 (0)