Skip to content

Commit

Permalink
made TesseractPlatformUtils a java service instead of using expect pl…
Browse files Browse the repository at this point in the history
…atform, plan to do this for all uses of expect platform
  • Loading branch information
Trinsdar committed Mar 6, 2024
1 parent cdef7d1 commit 0eec28a
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 52 deletions.
5 changes: 0 additions & 5 deletions common/src/main/java/tesseract/Tesseract.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,4 @@ public Tesseract() {
public static boolean hadFirstTick(LevelAccessor world) {
return TEST || firstTick.contains(world);
}

@ExpectPlatform
public static ConfigHandler createConfig(Config config){
throw new AssertionError();
}
}
4 changes: 2 additions & 2 deletions common/src/main/java/tesseract/TesseractConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public static void createConfig(){
ConfigSection section = config.add("general");
EU_TO_FE_RATIO = section.addDouble("eu_to_fe_ratio", 8.0, "The ratio of the eu to the fe energy converting - Default: (1.0 EU = 8.0 FE)").setMin(Double.MIN_VALUE);
EU_TO_TRE_RATIO = section.addDouble("eu_to_tre_ratio", 1.0, "The ratio of the eu to the tre energy converting - Default: (1.0 EU = 1.0 TRE)").setMin(Double.MIN_VALUE);
ENABLE_FE_OR_TRE_INPUT = section.addBool("enable_fe_or_tre_input", !TesseractPlatformUtils.isForge(), "Enables EU Machines and cables being able to input FE or TRE(Tech Reborn Energy),",
ENABLE_FE_OR_TRE_INPUT = section.addBool("enable_fe_or_tre_input", !TesseractPlatformUtils.INSTANCE.isForge(), "Enables EU Machines and cables being able to input FE or TRE(Tech Reborn Energy),",
"Please do not enable on forge unless you have balanced the fe compat to not be broken af due to power creep. - Default: false on forge, true on fabric");
ENABLE_MI_COMPAT = section.addBool("enabled_mi_compat", true, "Enables Tesseract EU having compat with MI energy. - Default: true");
CONFIG = Tesseract.createConfig(config);
CONFIG = TesseractPlatformUtils.INSTANCE.createConfig(config);
CONFIG.register();
}
}
2 changes: 1 addition & 1 deletion common/src/main/java/tesseract/TesseractGraphWrappers.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TesseractGraphWrappers {
public static final GraphWrapper<ItemTransaction, IItemPipe, IItemNode> ITEM = new GraphWrapper<>(ItemController::new, IItemNode.GETTER);

public static final GraphWrapper<RFTransaction, IRFCable, IRFNode> RF = new GraphWrapper<>(RFController::new, IRFNode.GETTER);
public static long dropletMultiplier = TesseractPlatformUtils.isForge() ? 1L : 81L;
public static long dropletMultiplier = TesseractPlatformUtils.INSTANCE.isForge() ? 1L : 81L;
//public static GraphWrapper<Integer, IRFCable, IRFNode> FE_ENERGY = new GraphWrapper<>(RFController::new);
public static GraphWrapper<GTTransaction, IGTCable, IGTNode> GT_ENERGY = new GraphWrapper<>(Energy::new, IGTNode.GT_GETTER);

Expand Down
36 changes: 15 additions & 21 deletions common/src/main/java/tesseract/TesseractPlatformUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tesseract;

import carbonconfiglib.config.Config;
import carbonconfiglib.config.ConfigHandler;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
Expand All @@ -8,30 +10,22 @@
import tesseract.api.rf.IRFNode;
import tesseract.graph.INode;

public class TesseractPlatformUtils {
@ExpectPlatform
public static IGTNode getGTNode(Level level, long pos, Direction direction, Runnable invalidate){
throw new AssertionError();
}
import java.util.ServiceLoader;

@ExpectPlatform
public static IRFNode getRFNode(Level level, long pos, Direction direction, Runnable invalidate){
throw new AssertionError();
}
public interface TesseractPlatformUtils {
TesseractPlatformUtils INSTANCE = ServiceLoader.load(TesseractPlatformUtils.class).findFirst().orElseThrow(() -> new IllegalStateException("No implementation of TesseractPlatformUtils found"));

@ExpectPlatform
public static IHeatNode getHeatNode(Level level, long pos, Direction direction, Runnable invalidate){
throw new AssertionError();
}

@ExpectPlatform
public static boolean isFeCap(Class<?> cap){
throw new AssertionError();
}
IGTNode getGTNode(Level level, long pos, Direction direction, Runnable invalidate);

IRFNode getRFNode(Level level, long pos, Direction direction, Runnable invalidate);

@ExpectPlatform
public static boolean isForge(){
throw new AssertionError();
}
IHeatNode getHeatNode(Level level, long pos, Direction direction, Runnable invalidate);

boolean isFeCap(Class<?> cap);


boolean isForge();

ConfigHandler createConfig(Config config);
}
2 changes: 1 addition & 1 deletion common/src/main/java/tesseract/api/gt/IGTNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ default void tesseractTick() {

}

GraphWrapper.ICapabilityGetter<IGTNode> GT_GETTER = TesseractPlatformUtils::getGTNode;
GraphWrapper.ICapabilityGetter<IGTNode> GT_GETTER = TesseractPlatformUtils.INSTANCE::getGTNode;
}
2 changes: 1 addition & 1 deletion common/src/main/java/tesseract/api/heat/IHeatNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ default int getTemperature() {
return getHeat() / 100;
}

GraphWrapper.ICapabilityGetter<IHeatNode> GETTER = TesseractPlatformUtils::getHeatNode;
GraphWrapper.ICapabilityGetter<IHeatNode> GETTER = TesseractPlatformUtils.INSTANCE::getHeatNode;
}
2 changes: 1 addition & 1 deletion common/src/main/java/tesseract/api/rf/IRFNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ default void update(BlockEntity object) {

}

GraphWrapper.ICapabilityGetter<IRFNode> GETTER = TesseractPlatformUtils::getRFNode;
GraphWrapper.ICapabilityGetter<IRFNode> GETTER = TesseractPlatformUtils.INSTANCE::getRFNode;
}
4 changes: 0 additions & 4 deletions fabric/src/main/java/tesseract/fabric/TesseractImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,4 @@ public static <T extends BlockEntity> void registerTRETile(BiFunction<T, Directi
public static void registerTREItem(BiFunction<ItemStack, ContainerItemContext, IEnergyHandler> function, Item type){
EnergyStorage.ITEM.registerForItems((stack, context) -> (EnergyStorage) function.apply(stack, context), type);
}

public static ConfigHandler createConfig(Config config){
return CarbonConfig.createConfig(Tesseract.API_ID, config);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package tesseract.fabric;


import carbonconfiglib.CarbonConfig;
import carbonconfiglib.config.Config;
import carbonconfiglib.config.ConfigHandler;
import earth.terrarium.botarium.common.energy.base.EnergyAttachment;
import earth.terrarium.botarium.common.energy.base.EnergyContainer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import team.reborn.energy.api.EnergyStorage;
import tesseract.Tesseract;
import tesseract.TesseractCapUtils;
import tesseract.TesseractPlatformUtils;
import tesseract.api.fabric.TileListeners;
import tesseract.api.fabric.wrapper.RFWrapper;
import tesseract.api.gt.IEnergyHandler;
Expand All @@ -21,8 +26,8 @@
import java.util.Optional;

@SuppressWarnings("UnstableApiUsage")
public class TesseractPlatformUtilsImpl {
public static IGTNode getGTNode(Level level, long pos, Direction direction, Runnable invalidate){
public class TesseractPlatformUtilsImpl implements TesseractPlatformUtils {
public IGTNode getGTNode(Level level, long pos, Direction direction, Runnable invalidate){
BlockEntity tile = level.getBlockEntity(BlockPos.of(pos));
Optional<IEnergyHandler> capability = TesseractCapUtilsImpl.getEnergyHandler(tile, direction);
if (capability.isPresent()) {
Expand All @@ -32,7 +37,7 @@ public static IGTNode getGTNode(Level level, long pos, Direction direction, Runn
return null;
}

public static IRFNode getRFNode(Level level, long pos, Direction capSide, Runnable capCallback){
public IRFNode getRFNode(Level level, long pos, Direction capSide, Runnable capCallback){
BlockEntity tile = level.getBlockEntity(BlockPos.of(pos));
if (tile == null) {
return null;
Expand All @@ -55,7 +60,7 @@ public static IRFNode getRFNode(Level level, long pos, Direction capSide, Runnab
return null;
}

public static IHeatNode getHeatNode(Level level, long pos, Direction direction, Runnable invalidate){
public IHeatNode getHeatNode(Level level, long pos, Direction direction, Runnable invalidate){
BlockEntity tile = level.getBlockEntity(BlockPos.of(pos));
if (tile == null) return null;
Optional<IHeatHandler> capability = TesseractCapUtils.getHeatHandler(tile, direction);
Expand All @@ -66,11 +71,15 @@ public static IHeatNode getHeatNode(Level level, long pos, Direction direction,
return null;
}

public static boolean isFeCap(Class<?> cap){
public boolean isFeCap(Class<?> cap){
return false;
}

public static boolean isForge(){
public boolean isForge(){
return false;
}

public ConfigHandler createConfig(Config config){
return CarbonConfig.createConfig(Tesseract.API_ID, config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tesseract.fabric.TesseractPlatformUtilsImpl
4 changes: 0 additions & 4 deletions forge/src/main/java/tesseract/forge/TesseractImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,4 @@ public void onServerTick(TickEvent.WorldTickEvent event) {
GraphWrapper.getWrappers().forEach(GraphWrapper::healthCheck);
}
}

public static ConfigHandler createConfig(Config config){
return CarbonConfig.CONFIGS.createConfig(config);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package tesseract.forge;

import carbonconfiglib.CarbonConfig;
import carbonconfiglib.config.Config;
import carbonconfiglib.config.ConfigHandler;
import earth.terrarium.botarium.common.energy.base.EnergyContainer;
import earth.terrarium.botarium.forge.energy.ForgeEnergyContainer;
import net.minecraft.core.BlockPos;
Expand All @@ -10,6 +13,7 @@
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import tesseract.TesseractCapUtils;
import tesseract.TesseractPlatformUtils;
import tesseract.api.forge.TesseractCaps;
import tesseract.api.forge.wrapper.RFWrapper;
import tesseract.api.gt.IEnergyHandler;
Expand All @@ -20,8 +24,8 @@

import java.util.Optional;

public class TesseractPlatformUtilsImpl {
public static IGTNode getGTNode(Level level, long pos, Direction direction, Runnable invalidate){
public class TesseractPlatformUtilsImpl implements TesseractPlatformUtils {
public IGTNode getGTNode(Level level, long pos, Direction direction, Runnable invalidate){
BlockEntity tile = level.getBlockEntity(BlockPos.of(pos));
LazyOptional<IEnergyHandler> capability = TesseractCapUtilsImpl.getEnergyHandler(tile, direction).map(e -> LazyOptional.of(() -> e)).orElse(LazyOptional.empty());
if (capability.isPresent()) {
Expand All @@ -31,7 +35,7 @@ public static IGTNode getGTNode(Level level, long pos, Direction direction, Runn
return null;
}

public static IRFNode getRFNode(Level level, long pos, Direction capSide, Runnable capCallback){
public IRFNode getRFNode(Level level, long pos, Direction capSide, Runnable capCallback){
BlockEntity tile = level.getBlockEntity(BlockPos.of(pos));
if (tile == null) {
return null;
Expand All @@ -50,7 +54,7 @@ public static IRFNode getRFNode(Level level, long pos, Direction capSide, Runnab
}
}

public static IHeatNode getHeatNode(Level level, long pos, Direction direction, Runnable invalidate){
public IHeatNode getHeatNode(Level level, long pos, Direction direction, Runnable invalidate){
BlockEntity tile = level.getBlockEntity(BlockPos.of(pos));
if (tile == null) return null;
LazyOptional<IHeatHandler> capability = tile.getCapability(TesseractCaps.HEAT_CAPABILITY, direction);
Expand All @@ -61,11 +65,15 @@ public static IHeatNode getHeatNode(Level level, long pos, Direction direction,
return null;
}

public static boolean isFeCap(Class<?> cap){
public boolean isFeCap(Class<?> cap){
return cap == IEnergyStorage.class;
}

public static boolean isForge(){
public boolean isForge(){
return true;
}

public ConfigHandler createConfig(Config config){
return CarbonConfig.CONFIGS.createConfig(config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tesseract.forge.TesseractPlatformUtilsImpl

0 comments on commit 0eec28a

Please sign in to comment.