mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-17 22:00:08 +00:00
Reformat
This commit is contained in:
@@ -88,24 +88,57 @@ public abstract class AbstractPlatform implements Platform {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractPlatform.class);
|
||||
|
||||
private static final MutableBoolean LOADED = new MutableBoolean(false);
|
||||
private static final String moonrise = "Moonrise";
|
||||
private final EventManager eventManager = new EventManagerImpl();
|
||||
private final ConfigRegistry configRegistry = new ConfigRegistry();
|
||||
private final MetaConfigRegistry metaConfigRegistry = new MetaConfigRegistry();
|
||||
|
||||
private final CheckedRegistry<ConfigPack> checkedConfigRegistry = new CheckedRegistryImpl<>(configRegistry);
|
||||
|
||||
private final CheckedRegistry<MetaPack> checkedMetaConfigRegistry = new CheckedRegistryImpl<>(metaConfigRegistry);
|
||||
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
|
||||
private final GenericLoaders loaders = new GenericLoaders(this);
|
||||
|
||||
private final PluginConfigImpl config = new PluginConfigImpl();
|
||||
|
||||
private final CheckedRegistry<BaseAddon> addonRegistry = new CheckedRegistryImpl<>(new OpenRegistryImpl<>(TypeKey.of(BaseAddon.class)));
|
||||
|
||||
private final Registry<BaseAddon> lockedAddonRegistry = new LockedRegistryImpl<>(addonRegistry);
|
||||
|
||||
public static int getGenerationThreadsWithReflection(String className, String fieldName, String project) {
|
||||
try {
|
||||
Class aClass = Class.forName(className);
|
||||
int threads = aClass.getField(fieldName).getInt(null);
|
||||
logger.info("{} found, setting {} generation threads.", project, threads);
|
||||
return threads;
|
||||
} catch(ClassNotFoundException e) {
|
||||
logger.info("{} not found.", project);
|
||||
} catch(NoSuchFieldException e) {
|
||||
logger.warn("{} found, but {} field not found this probably means {0} has changed its code and " +
|
||||
"Terra has not updated to reflect that.", project, fieldName);
|
||||
} catch(IllegalAccessException e) {
|
||||
logger.error("Failed to access {} field in {}, assuming 1 generation thread.", fieldName, project, e);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
int threads = ((Thread[]) getCoreThreadsMethod.invoke(pool)).length;
|
||||
logger.info("{} found, setting {} generation threads.", moonrise, threads);
|
||||
return threads;
|
||||
} catch(ClassNotFoundException e) {
|
||||
logger.info("{} not found.", moonrise);
|
||||
} catch(NoSuchMethodException | NoSuchFieldException e) {
|
||||
logger.warn("{} found, but field/method not found this probably means {0} has changed its code and " +
|
||||
"Terra has not updated to reflect that.", moonrise);
|
||||
} catch(IllegalAccessException | InvocationTargetException e) {
|
||||
logger.error("Failed to access thread values in {}, assuming 1 generation thread.", moonrise, e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ConfigRegistry getRawConfigRegistry() {
|
||||
return configRegistry;
|
||||
}
|
||||
@@ -356,46 +389,6 @@ public abstract class AbstractPlatform implements Platform {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getGenerationThreadsWithReflection(String className, String fieldName, String project) {
|
||||
try {
|
||||
Class aClass = Class.forName(className);
|
||||
int threads = aClass.getField(fieldName).getInt(null);
|
||||
logger.info("{} found, setting {} generation threads.", project, threads);
|
||||
return threads;
|
||||
} catch(ClassNotFoundException e) {
|
||||
logger.info("{} not found.", project);
|
||||
} catch(NoSuchFieldException e) {
|
||||
logger.warn("{} found, but {} field not found this probably means {0} has changed its code and " +
|
||||
"Terra has not updated to reflect that.", project, fieldName);
|
||||
} catch(IllegalAccessException e) {
|
||||
logger.error("Failed to access {} field in {}, assuming 1 generation thread.", fieldName, project, e);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
private static final String moonrise = "Moonrise";
|
||||
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);
|
||||
int threads = ((Thread[]) getCoreThreadsMethod.invoke(pool)).length;
|
||||
logger.info("{} found, setting {} generation threads.", moonrise, threads);
|
||||
return threads;
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.info("{} not found.", moonrise);
|
||||
} catch (NoSuchMethodException | NoSuchFieldException e) {
|
||||
logger.warn("{} found, but field/method not found this probably means {0} has changed its code and " +
|
||||
"Terra has not updated to reflect that.", moonrise);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
logger.error("Failed to access thread values in {}, assuming 1 generation thread.", moonrise, e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
loaders.register(registry);
|
||||
|
||||
@@ -29,9 +29,9 @@ import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
import com.dfsek.terra.api.util.range.Range;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.range.Range;
|
||||
import com.dfsek.terra.config.loaders.ExpressionParserOptionsTemplate;
|
||||
import com.dfsek.terra.config.loaders.LinkedHashMapLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class ExpressionParserOptionsTemplate implements ObjectTemplate<ParseOpti
|
||||
@Value("use-let-expressions")
|
||||
@Default
|
||||
private boolean useLetExpressions = DEFAULT_PARSE_OPTIONS.useLetExpressions();
|
||||
|
||||
|
||||
@Override
|
||||
public ParseOptions get() {
|
||||
return new ParseOptions(useLetExpressions);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ProbabilityCollectionLoader implements TypeLoader<ProbabilityCollec
|
||||
AnnotatedType generic = pType.getAnnotatedActualTypeArguments()[0];
|
||||
if(o instanceof Map) {
|
||||
Map<Object, Object> map = (Map<Object, Object>) o;
|
||||
if (map.size() == 1) {
|
||||
if(map.size() == 1) {
|
||||
Object onlyKey = map.keySet().iterator().next();
|
||||
return new ProbabilityCollection.Singleton<>(configLoader.loadType(generic, onlyKey, depthTracker));
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
package profiler;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.dfsek.terra.api.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class ProfilerTest {
|
||||
private static final Profiler PROFILER = new ProfilerImpl();
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package registry;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
@@ -25,10 +27,7 @@ import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.registry.CheckedRegistryImpl;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class RegistryTest {
|
||||
|
||||
Reference in New Issue
Block a user