mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-11-28 08:54:15 +00:00
feat: build Bukkit biomes, dimensions and timelines from environment attributes
This commit is contained in:
1 parent
44408a1b72
commit
bfa126bc12
85 files changed
+3191
-1621
No files matched your search
@@ -129,11 +129,9 @@ public abstract class AbstractPlatform implements Platform {
|
||||
|
||||
public static int getMoonriseGenerationThreadsWithReflection() {
|
||||
try {
|
||||
Class<?> prioritisedThreadPoolClazz = Class.forName("ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool");
|
||||
Method getCoreThreadsMethod = prioritisedThreadPoolClazz.getDeclaredMethod("getCoreThreads");
|
||||
getCoreThreadsMethod.setAccessible(true);
|
||||
Class<?> moonriseCommonClazz = Class.forName("ca.spottedleaf.moonrise.common.util.MoonriseCommon");
|
||||
Object pool = moonriseCommonClazz.getDeclaredField("WORKER_POOL").get(null);
|
||||
Object pool = moonriseCommonClazz.getField("WORKER_POOL").get(null);
|
||||
Method getCoreThreadsMethod = pool.getClass().getMethod("getCoreThreads");
|
||||
int threads = ((Thread[]) getCoreThreadsMethod.invoke(pool)).length;
|
||||
logger.info("{} found, setting {} generation threads.", moonrise, threads);
|
||||
return threads;
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.dfsek.terra.world.attribute.platform;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
|
||||
|
||||
/**
|
||||
* Thread safe.
|
||||
*/
|
||||
public final class AttributeReport {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AttributeReport.class);
|
||||
private static final String NOT_A_MINECRAFT_TAG = "no such tag in the minecraft namespace";
|
||||
|
||||
private final String pack;
|
||||
private final Consumer<String> warn;
|
||||
private final Consumer<String> debug;
|
||||
private final Set<String> notApplied = ConcurrentHashMap.newKeySet();
|
||||
private final Set<Map.Entry<String, String>> notAppliedToWorld = ConcurrentHashMap.newKeySet();
|
||||
|
||||
public AttributeReport(String pack, Consumer<String> warn, Consumer<String> debug) {
|
||||
this.pack = Objects.requireNonNull(pack, "pack");
|
||||
this.warn = Objects.requireNonNull(warn, "warn");
|
||||
this.debug = Objects.requireNonNull(debug, "debug");
|
||||
}
|
||||
|
||||
public static AttributeReport logging(ConfigPack pack) {
|
||||
return logging(pack, LOGGER);
|
||||
}
|
||||
|
||||
public static AttributeReport logging(ConfigPack pack, Logger logger) {
|
||||
return new AttributeReport(pack.getID(), logger::warn, logger::debug);
|
||||
}
|
||||
|
||||
public void attributeSkipped(String config, String key, String reason) {
|
||||
warn.accept("Pack \"" + pack + "\", config \"" + config + "\": attribute \"" + key + "\" skipped: " + reason);
|
||||
}
|
||||
|
||||
public void scheduleSkipped(String schedule, String reason) {
|
||||
warn.accept("Pack \"" + pack + "\": schedule \"" + schedule + "\" skipped: " + reason);
|
||||
}
|
||||
|
||||
public void trackDropped(String schedule, String key, String reason) {
|
||||
warn.accept("Pack \"" + pack + "\": schedule \"" + schedule + "\" track \"" + key + "\" dropped: " + reason);
|
||||
}
|
||||
|
||||
public void timeMarkerDropped(String schedule, String marker, String clock) {
|
||||
warn.accept("Pack \"" + pack + "\": schedule \"" + schedule + "\" time marker \"" + marker + "\" dropped: already defined for "
|
||||
+ "clock \"" + clock + "\"");
|
||||
}
|
||||
|
||||
public void ignored(String config, String key, String reason) {
|
||||
warn.accept("Pack \"" + pack + "\", config \"" + config + "\": \"" + key + "\" ignored: " + reason);
|
||||
}
|
||||
|
||||
public void tagCreated(String config, String tag) {
|
||||
warn.accept("Pack \"" + pack + "\", config \"" + config + "\": tag \"" + tag + "\" created: " + NOT_A_MINECRAFT_TAG);
|
||||
}
|
||||
|
||||
public void notApplied(String key) {
|
||||
if(notApplied.add(key)) debug.accept("Pack \"" + pack + "\": attribute \"" + key + "\" is not applied on this platform");
|
||||
}
|
||||
|
||||
public void notAppliedToWorld(String key, String world) {
|
||||
if(notAppliedToWorld.add(Map.entry(key, world))) {
|
||||
debug.accept("Pack \"" + pack + "\": attribute \"" + key + "\" is not applied to world \"" + world
|
||||
+ "\": it is fixed when the world is created");
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.world.attribute.platform;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.world.attribute.Attribute;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeEntry;
|
||||
|
||||
|
||||
/**
|
||||
* An attribute built after the slots were sized reads as absent.
|
||||
*/
|
||||
public final class AttributeSlots {
|
||||
public static final AttributeSlots EMPTY = new AttributeSlots(new AttributeEntry<?>[0]);
|
||||
|
||||
private final AttributeEntry<?>[] entries;
|
||||
|
||||
private AttributeSlots(AttributeEntry<?>[] entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps {@code entries} without copying: the caller must not change the array afterwards.
|
||||
*/
|
||||
public static AttributeSlots of(AttributeEntry<?>[] entries) {
|
||||
return new AttributeSlots(Objects.requireNonNull(entries, "entries"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> @Nullable AttributeEntry<T> get(Attribute<T> attribute) {
|
||||
int index = attribute.index();
|
||||
AttributeEntry<?>[] entries = this.entries;
|
||||
return index < entries.length ? (AttributeEntry<T>) entries[index] : null;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.world.attribute.platform;
|
||||
|
||||
public interface ParentEntryHolder {
|
||||
/**
|
||||
* {@link AttributeSlots#EMPTY} until the platform sets them.
|
||||
*/
|
||||
AttributeSlots parentEntries();
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.world.attribute.platform;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.api.world.attribute.Attribute;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeEntry;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeHandle;
|
||||
|
||||
|
||||
public final class ParentFold {
|
||||
private ParentFold() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes {@code upper} over {@code lower} per attribute, or overrides with their resolved value when they don't compose.
|
||||
*/
|
||||
public static AttributeSlots fold(AttributeHandle handle, Iterable<? extends Attribute<?>> attributes, AttributeSlots lower,
|
||||
AttributeSlots upper) {
|
||||
Objects.requireNonNull(lower, "lower");
|
||||
Objects.requireNonNull(upper, "upper");
|
||||
AttributeEntry<?>[] slots = new AttributeEntry<?>[handle.attributeCount()];
|
||||
for(Attribute<?> attribute : attributes) fold(handle, attribute, lower, upper, slots);
|
||||
return AttributeSlots.of(slots);
|
||||
}
|
||||
|
||||
private static <T> void fold(AttributeHandle handle, Attribute<T> attribute, AttributeSlots lower, AttributeSlots upper,
|
||||
AttributeEntry<?>[] slots) {
|
||||
AttributeEntry<T> below = lower.get(attribute);
|
||||
AttributeEntry<T> above = upper.get(attribute);
|
||||
if(below == null && above == null) return;
|
||||
slots[attribute.index()] = handle.compose(attribute, below, above)
|
||||
.orElseGet(() -> AttributeEntry.override(handle.resolve(attribute, below, above, null)));
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.dfsek.terra.world.attribute.platform;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
class AttributeReportTest {
|
||||
private final List<String> warnings = new ArrayList<>();
|
||||
private final List<String> debugs = new ArrayList<>();
|
||||
private final AttributeReport report = new AttributeReport("test", warnings::add, debugs::add);
|
||||
|
||||
@Test
|
||||
void reportFormats() {
|
||||
report.attributeSkipped("BIOME", "minecraft:visual/fog_color", "not a colour");
|
||||
report.scheduleSkipped("mypack:seasons", "no clock");
|
||||
report.trackDropped("mypack:seasons", "minecraft:visual/fog_color", "bad keyframe");
|
||||
report.timeMarkerDropped("mypack:seasons", "minecraft:noon", "minecraft:overworld");
|
||||
report.ignored("pack.yml", "vanilla", "no such dimension type \"minecraft:nope\"");
|
||||
report.tagCreated("BIOME", "minecraft:is_custom");
|
||||
report.notApplied("test:custom");
|
||||
report.notApplied("test:custom");
|
||||
report.notApplied("test:other");
|
||||
|
||||
assertEquals(List.of(
|
||||
"Pack \"test\", config \"BIOME\": attribute \"minecraft:visual/fog_color\" skipped: not a colour",
|
||||
"Pack \"test\": schedule \"mypack:seasons\" skipped: no clock",
|
||||
"Pack \"test\": schedule \"mypack:seasons\" track \"minecraft:visual/fog_color\" dropped: bad keyframe",
|
||||
"Pack \"test\": schedule \"mypack:seasons\" time marker \"minecraft:noon\" dropped: already defined for clock "
|
||||
+ "\"minecraft:overworld\"",
|
||||
"Pack \"test\", config \"pack.yml\": \"vanilla\" ignored: no such dimension type \"minecraft:nope\"",
|
||||
"Pack \"test\", config \"BIOME\": tag \"minecraft:is_custom\" created: no such tag in the minecraft namespace"), warnings);
|
||||
assertEquals(List.of(
|
||||
"Pack \"test\": attribute \"test:custom\" is not applied on this platform",
|
||||
"Pack \"test\": attribute \"test:other\" is not applied on this platform"), debugs);
|
||||
}
|
||||
|
||||
@Test
|
||||
void notAppliedToWorldOnce() {
|
||||
report.notAppliedToWorld("terra:dimension/min_y", "world");
|
||||
report.notAppliedToWorld("terra:dimension/min_y", "world");
|
||||
|
||||
assertEquals(List.of(), warnings);
|
||||
assertEquals(List.of(
|
||||
"Pack \"test\": attribute \"terra:dimension/min_y\" is not applied to world \"world\": it is fixed when the world is created"),
|
||||
debugs);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.dfsek.terra.world.attribute.platform;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.dfsek.terra.api.world.attribute.Attribute;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeEntry;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeHandle;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeKey;
|
||||
import com.dfsek.terra.world.attribute.AttributeHandleImpl;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
|
||||
class AttributeSlotsTest {
|
||||
@Test
|
||||
void outOfRangeIsNull() {
|
||||
AttributeHandle handle = new AttributeHandleImpl();
|
||||
Attribute<Float> attribute = null;
|
||||
for(int i = 0; i <= 5; i++) {
|
||||
attribute = handle.attributeBuilder(AttributeKey.<Float>parse("test:a" + i), handle.types().floatType(), 0f).build();
|
||||
}
|
||||
assertEquals(5, attribute.index());
|
||||
|
||||
assertNull(AttributeSlots.of(new AttributeEntry<?>[1]).get(attribute));
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.dfsek.terra.world.attribute.platform;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.world.attribute.Attribute;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeEntry;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeHandle;
|
||||
import com.dfsek.terra.api.world.attribute.AttributeKey;
|
||||
import com.dfsek.terra.api.world.attribute.Operation;
|
||||
import com.dfsek.terra.world.attribute.AttributeHandleImpl;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
|
||||
class ParentFoldTest {
|
||||
private static final AttributeHandle HANDLE = new AttributeHandleImpl();
|
||||
private static final Attribute<Float> FOG_END = HANDLE.attributeBuilder(AttributeKey.<Float>parse("test:fog_end"),
|
||||
HANDLE.types().floatType(), 1024f).build();
|
||||
|
||||
private static AttributeSlots slots(AttributeEntry<Float> entry) {
|
||||
AttributeEntry<?>[] entries = new AttributeEntry<?>[HANDLE.attributeCount()];
|
||||
entries[FOG_END.index()] = entry;
|
||||
return AttributeSlots.of(entries);
|
||||
}
|
||||
|
||||
private static AttributeEntry<Float> fold(AttributeEntry<Float> lower, AttributeEntry<Float> upper) {
|
||||
return ParentFold.fold(HANDLE, List.of(FOG_END), slots(lower), slots(upper)).get(FOG_END);
|
||||
}
|
||||
|
||||
@Test
|
||||
void foldComposes() {
|
||||
assertNull(fold(null, null));
|
||||
AttributeEntry<Float> lower = AttributeEntry.override(2f);
|
||||
assertSame(lower, fold(lower, null));
|
||||
AttributeEntry<Float> upper = AttributeEntry.override(2f);
|
||||
assertSame(upper, fold(null, upper));
|
||||
assertEquals(AttributeEntry.of(Operation.ADD, 3f), fold(AttributeEntry.of(Operation.ADD, 1f), AttributeEntry.of(Operation.ADD, 2f)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void foldOverrides() {
|
||||
AttributeEntry<Float> lower = AttributeEntry.of(Operation.ADD, 1f);
|
||||
AttributeEntry<Float> upper = AttributeEntry.of(Operation.MULTIPLY, 2f);
|
||||
AttributeEntry<Float> folded = fold(lower, upper);
|
||||
assertNotNull(folded);
|
||||
assertEquals(Operation.OVERRIDE, folded.operation());
|
||||
assertEquals(HANDLE.resolve(FOG_END, lower, upper, null), folded.argument());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user