diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c2b86f..2ed7d25 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -9,7 +9,7 @@ - + diff --git a/Common/build.gradle b/Common/build.gradle index 0547852..efc9343 100644 --- a/Common/build.gradle +++ b/Common/build.gradle @@ -2,11 +2,13 @@ plugins { id 'java' id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' id 'maven-publish' + id 'com.github.johnrengelman.shadow' version '7.0.0' } archivesBaseName = "${mod_name}-common-${minecraft_version}" minecraft { + accessWideners(project.file("src/main/resources/craterlib.aw")) version(minecraft_version) runs { if (project.hasProperty('common_runs_enabled') ? project.findProperty('common_runs_enabled').toBoolean() : true) { @@ -22,7 +24,7 @@ minecraft { } dependencies { - compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5' + compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5' } processResources { @@ -32,6 +34,20 @@ processResources { expand buildProps } } + +shadowJar { + dependencies { + include(dependency('me.hypherionmc.night-config:toml:3.6.5_custom')) + include(dependency('me.hypherionmc.night-config:core:3.6.5_custom')) + + //relocate 'me.hypherionmc.nightconfig', 'shadow.hypherionmc.nightconfig' + } + classifier '' +} + +build.dependsOn shadowJar +reg.configureJarTask(shadowJar) + publishing { publications { mavenJava(MavenPublication) { @@ -39,12 +55,26 @@ publishing { artifactId project.archivesBaseName version project.version from components.java + pom.withXml { + Node pomNode = asNode() + pomNode.dependencies.'*'.findAll() { + it.artifactId.text() == 'regutils-joined-fabric' || + it.artifactId.text() == 'core' || + it.artifactId.text() == 'toml' + }.each() { + it.parent().remove(it) + } + } } } repositories { maven { - url "file://" + System.getenv("local_maven") + url "https://maven.firstdarkdev.xyz/" + (project.isSnapshot ? "snapshots" : "releases") + credentials { + username System.getenv("MAVEN_USER") + password System.getenv("MAVEN_PASS") + } } } } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/Constants.java b/Common/src/main/java/me/hypherionmc/craterlib/Constants.java index 6a7543d..8232c1d 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/Constants.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/Constants.java @@ -4,7 +4,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class Constants { - public static final String MOD_ID = "craterlib"; - public static final String MOD_NAME = "CraterLib"; - public static final Logger LOG = LogManager.getLogger(MOD_NAME); + public static final String MOD_ID = "craterlib"; + public static final String MOD_NAME = "CraterLib"; + public static final Logger LOG = LogManager.getLogger(MOD_NAME); } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/api/blockentities/ISidedTickable.java b/Common/src/main/java/me/hypherionmc/craterlib/api/blockentities/ISidedTickable.java index 4f18bbf..2e73b91 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/api/blockentities/ISidedTickable.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/api/blockentities/ISidedTickable.java @@ -5,9 +5,29 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +/** + * Helper Interface for BlockEntities that tick both Client and Server Side + */ public interface ISidedTickable { + /** + * Server Tick Event + * + * @param level + * @param pos + * @param state + * @param blockEntity + */ public void serverTick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity); + + /** + * Client Tick Event + * + * @param level + * @param pos + * @param state + * @param blockEntity + */ public void clientTick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity); } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/api/blockentities/ITickable.java b/Common/src/main/java/me/hypherionmc/craterlib/api/blockentities/ITickable.java index ffa3c86..600f899 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/api/blockentities/ITickable.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/api/blockentities/ITickable.java @@ -5,8 +5,19 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +/** + * Helper Interface for BlockEntities that only tick on a single side + */ public interface ITickable { + /** + * The Tick Event. Can be either Server or Client Sided + * + * @param level + * @param pos + * @param state + * @param blockEntity + */ public void tick(Level level, BlockPos pos, BlockState state, BlockEntity blockEntity); } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/CustomRenderType.java b/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/CustomRenderType.java index 5a09023..9067131 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/CustomRenderType.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/CustomRenderType.java @@ -1,9 +1,17 @@ package me.hypherionmc.craterlib.api.rendering; -import net.minecraft.client.renderer.entity.layers.RenderLayer; +import net.minecraft.client.renderer.RenderType; +/** + * Helper Interface for defining Block render types + */ public interface CustomRenderType { - RenderLayer getCustomRenderType(); + /** + * Get the render type of the block + * + * @return + */ + RenderType getCustomRenderType(); } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/DyableBlock.java b/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/DyableBlock.java index 81bb77d..9d115ae 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/DyableBlock.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/DyableBlock.java @@ -1,12 +1,25 @@ package me.hypherionmc.craterlib.api.rendering; -import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.color.block.BlockColor; import net.minecraft.world.item.DyeColor; +/** + * Helper Interface for Dyable Blocks + */ public interface DyableBlock { - BlockColors dyeHandler(); + /** + * Get the BlockColor handler for the block + * + * @return + */ + BlockColor dyeHandler(); + /** + * Get the default Dye Color for Un-dyed states + * + * @return + */ DyeColor defaultDyeColor(); } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/ItemDyable.java b/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/ItemDyable.java index 9ed2e2c..3f86328 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/ItemDyable.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/api/rendering/ItemDyable.java @@ -2,8 +2,16 @@ package me.hypherionmc.craterlib.api.rendering; import net.minecraft.world.item.DyeColor; +/** + * Helper Interface for Dyable Items + */ public interface ItemDyable { + /** + * Get the DyeColor of the Item + * + * @return + */ public DyeColor getColor(); } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/client/gui/widgets/TimeSliderWidget.java b/Common/src/main/java/me/hypherionmc/craterlib/client/gui/widgets/TimeSliderWidget.java index 10ff84f..d934701 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/client/gui/widgets/TimeSliderWidget.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/client/gui/widgets/TimeSliderWidget.java @@ -4,6 +4,9 @@ import net.minecraft.client.gui.components.AbstractSliderButton; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; +/** + * A custom slider widget used for Time. Mostly used by the Hyper Lighting Smoke Machine + */ public class TimeSliderWidget extends AbstractSliderButton { private final double maxValue; diff --git a/Common/src/main/java/me/hypherionmc/craterlib/client/registry/ClientRegistry.java b/Common/src/main/java/me/hypherionmc/craterlib/client/registry/ClientRegistry.java new file mode 100644 index 0000000..d84281f --- /dev/null +++ b/Common/src/main/java/me/hypherionmc/craterlib/client/registry/ClientRegistry.java @@ -0,0 +1,45 @@ +package me.hypherionmc.craterlib.client.registry; + +import me.hypherionmc.craterlib.api.rendering.DyableBlock; +import me.hypherionmc.craterlib.api.rendering.ItemDyable; +import me.hypherionmc.craterlib.client.rendering.ItemColorHandler; +import me.hypherionmc.craterlib.systems.reg.RegistrationProvider; +import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.color.item.ItemColors; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; + +/** + * Helper for registering Block and Item color handlers + */ +public class ClientRegistry { + + /** + * Register Block Color Handlers + * + * @param colors + * @param blocks + */ + public static void registerBlockColors(BlockColors colors, RegistrationProvider blocks) { + blocks.getEntries().forEach(blockRegistryObject -> { + if (blockRegistryObject.get() instanceof DyableBlock dyableBlock) { + colors.register(dyableBlock.dyeHandler(), (Block) dyableBlock); + } + }); + } + + /** + * Register Item Color Handlers + * + * @param colors + * @param items + */ + public static void registerItemColors(ItemColors colors, RegistrationProvider items) { + items.getEntries().forEach(itemRegistryObject -> { + if (itemRegistryObject.get() instanceof ItemDyable itemDyable) { + colors.register(new ItemColorHandler(), (Item) itemDyable); + } + }); + } + +} diff --git a/Common/src/main/java/me/hypherionmc/craterlib/client/rendering/ItemColorHandler.java b/Common/src/main/java/me/hypherionmc/craterlib/client/rendering/ItemColorHandler.java index cd2cebf..1204388 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/client/rendering/ItemColorHandler.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/client/rendering/ItemColorHandler.java @@ -1,18 +1,31 @@ package me.hypherionmc.craterlib.client.rendering; -import me.hypherionmc.craterlib.api.rendering.DyableBlock; import me.hypherionmc.craterlib.api.rendering.ItemDyable; -import me.hypherionmc.craterlib.common.item.BlockItemDyable; -import net.minecraft.client.color.item.ItemColors; +import net.minecraft.client.color.item.ItemColor; import net.minecraft.world.item.ItemStack; -public class ItemColorHandler extends ItemColors { +/** + * Helper Class for Dyable Items implementing a simple color handler + */ +public class ItemColorHandler implements ItemColor { + /*** + * Get the color for the Item/ItemStack + * @param stack + * @param tintIndex + * @return + */ @Override public int getColor(ItemStack stack, int tintIndex) { return this.getColorFromStack(stack); } + /** + * Get the color for the specific items stack, or return BLACK (0) + * + * @param stack + * @return + */ private int getColorFromStack(ItemStack stack) { if (stack.getItem() instanceof ItemDyable itemDyable) { return itemDyable.getColor().getMaterialColor().col; diff --git a/Common/src/main/java/me/hypherionmc/craterlib/common/config/ConfigController.java b/Common/src/main/java/me/hypherionmc/craterlib/common/config/ConfigController.java new file mode 100644 index 0000000..7bdaa9c --- /dev/null +++ b/Common/src/main/java/me/hypherionmc/craterlib/common/config/ConfigController.java @@ -0,0 +1,42 @@ +package me.hypherionmc.craterlib.common.config; + +import me.hypherionmc.craterlib.Constants; +import me.hypherionmc.nightconfig.core.file.FileWatcher; + +import java.io.Serializable; +import java.util.HashMap; + +/** + * Controls Config File Reloads and Events + */ +public class ConfigController implements Serializable { + + /** + * Cache of registered configs + */ + private static final HashMap monitoredConfigs = new HashMap<>(); + + /** + * INTERNAL METHOD - Register and watch the config + * + * @param config - The config class to register and watch + */ + static void register_config(ModuleConfig config) { + if (monitoredConfigs.containsKey(config)) { + Constants.LOG.error("Failed to register " + config.getConfigPath().getName() + ". Config already registered"); + } else { + FileWatcher configWatcher = new FileWatcher(); + try { + configWatcher.setWatch(config.getConfigPath(), () -> { + Constants.LOG.info("Sending Reload Event for: " + config.getConfigPath().getName()); + config.configReloaded(); + }); + } catch (Exception e) { + Constants.LOG.error("Failed to register " + config.getConfigPath().getName() + " for auto reloading. " + e.getMessage()); + } + monitoredConfigs.put(config, configWatcher); + Constants.LOG.info("Registered " + config.getConfigPath().getName() + " successfully!"); + } + } + +} diff --git a/Common/src/main/java/me/hypherionmc/craterlib/common/config/ModuleConfig.java b/Common/src/main/java/me/hypherionmc/craterlib/common/config/ModuleConfig.java new file mode 100644 index 0000000..a5f3ef6 --- /dev/null +++ b/Common/src/main/java/me/hypherionmc/craterlib/common/config/ModuleConfig.java @@ -0,0 +1,147 @@ +package me.hypherionmc.craterlib.common.config; + +import me.hypherionmc.nightconfig.core.CommentedConfig; +import me.hypherionmc.nightconfig.core.Config; +import me.hypherionmc.nightconfig.core.conversion.ObjectConverter; +import me.hypherionmc.nightconfig.core.file.CommentedFileConfig; + +import java.io.File; + +/** + * Base Config class containing the save, upgrading and loading logic. All config classes must extend this class + */ +public class ModuleConfig { + + /* Final Variables */ + private final transient File configPath; + private final transient String networkID; + + /** + * Set up the config + * + * @param modId - The ID of the Mod/Module the config belongs to + * @param configName - The name of the config file, excluding extension + */ + public ModuleConfig(String modId, String configName) { + this(modId, "", configName); + } + + public ModuleConfig(String modId, String subFolder, String configName) { + /* Preserve the order of the config values */ + Config.setInsertionOrderPreserved(true); + + /* Configure Paths and Network SYNC ID */ + File configDir = new File("config" + (subFolder.isEmpty() ? "" : File.separator + subFolder)); + configPath = new File(configDir + File.separator + configName + ".toml"); + networkID = modId + ":conf_" + configName.replace("-", "_"); + + /* Check if the required directories exists, otherwise we create them */ + if (!configDir.exists()) { + configDir.mkdirs(); + } + + /* Register the Config for Watching and events */ + ConfigController.register_config(this); + } + + /** + * This method has to be called in the config constructor. This creates or upgrades the config file as needed + * + * @param config - The config class to use + */ + public void registerAndSetup(ModuleConfig config) { + if (!configPath.exists() || configPath.length() < 10) { + saveConfig(config); + } else { + migrateConfig(config); + } + } + + /** + * Save the config to the disk + * + * @param conf - The config class to serialize and save + */ + public void saveConfig(ModuleConfig conf) { + /* Set up the Serializer and Config Object */ + ObjectConverter converter = new ObjectConverter(); + CommentedFileConfig config = CommentedFileConfig.builder(configPath).build(); + + /* Save the config and fire the reload event */ + converter.toConfig(conf, config); + config.save(); + } + + /** + * Load the config from the file into a Class + * + * @param conf - The config Class to load + * @return - Returns the loaded version of the class + */ + public T loadConfig(Object conf) { + /* Set up the Serializer and Config Object */ + ObjectConverter converter = new ObjectConverter(); + CommentedFileConfig config = CommentedFileConfig.builder(configPath).build(); + config.load(); + + /* Load the config and return the loaded config */ + converter.toObject(config, conf); + return (T) conf; + } + + /** + * INTERNAL METHOD - Upgrades the config files in the event the config structure changes + * + * @param conf - The config class to load + */ + private void migrateConfig(ModuleConfig conf) { + /* Set up the Serializer and Config Objects */ + CommentedFileConfig config = CommentedFileConfig.builder(configPath).build(); + CommentedFileConfig newConfig = CommentedFileConfig.builder(configPath).build(); + config.load(); + + /* Upgrade the config */ + new ObjectConverter().toConfig(conf, newConfig); + updateConfigValues(config, newConfig, CommentedConfig.copy(newConfig), ""); + newConfig.save(); + } + + private void updateConfigValues(CommentedConfig oldConfig, CommentedConfig newConfig, CommentedConfig outputConfig, String subKey) { + /* Loop over the config keys and check what has changed */ + newConfig.valueMap().forEach((key, value) -> { + String finalKey = subKey + (subKey.isEmpty() ? "" : ".") + key; + if (value instanceof CommentedConfig commentedConfig) { + updateConfigValues(oldConfig, commentedConfig, outputConfig, finalKey); + } else { + outputConfig.set(finalKey, + oldConfig.contains(finalKey) ? oldConfig.get(finalKey) : value); + } + }); + } + + /** + * Get the location of the config file + * + * @return - The FILE object containing the config file + */ + public File getConfigPath() { + return configPath; + } + + /** + * Get the NETWORK SYNC ID + * + * @return - Returns the Sync ID in format modid:config_name + */ + public String getNetworkID() { + return networkID; + } + + /** + * Fired whenever changes to the config are detected + */ + public void configReloaded() { + + } + +} diff --git a/Common/src/main/java/me/hypherionmc/craterlib/common/config/annotations/Syncable.java b/Common/src/main/java/me/hypherionmc/craterlib/common/config/annotations/Syncable.java new file mode 100644 index 0000000..fb9daaf --- /dev/null +++ b/Common/src/main/java/me/hypherionmc/craterlib/common/config/annotations/Syncable.java @@ -0,0 +1,11 @@ +package me.hypherionmc.craterlib.common.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Syncable { +} diff --git a/Common/src/main/java/me/hypherionmc/craterlib/common/item/BlockItemDyable.java b/Common/src/main/java/me/hypherionmc/craterlib/common/item/BlockItemDyable.java index b5f850a..93cd0af 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/common/item/BlockItemDyable.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/common/item/BlockItemDyable.java @@ -6,12 +6,20 @@ import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.block.Block; +/** + * Base Item for Blocks that implement @link {DyableBlock}. + */ public class BlockItemDyable extends BlockItem implements ItemDyable { public BlockItemDyable(Block block, Properties properties) { super(block, properties); } + /** + * Get the Item Color from the block + * + * @return + */ @Override public DyeColor getColor() { if (this.getBlock() instanceof DyableBlock dyableBlock) { diff --git a/Common/src/main/java/me/hypherionmc/craterlib/common/item/DyableWaterBottle.java b/Common/src/main/java/me/hypherionmc/craterlib/common/item/DyableWaterBottle.java index 256f302..7ef1335 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/common/item/DyableWaterBottle.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/common/item/DyableWaterBottle.java @@ -17,6 +17,9 @@ import net.minecraft.world.level.gameevent.GameEvent; import java.util.List; +/** + * Custom Water Bottle item that supports Dye and can be used as Dye + */ public class DyableWaterBottle extends DyeItem implements ItemDyable { private final DyeColor color; @@ -28,16 +31,35 @@ public class DyableWaterBottle extends DyeItem implements ItemDyable { this.isGlowing = isGlowing; } + /** + * Normally this is used for enchanted items, in this case, it's used to check if the fluid is a glowing fluid + * + * @param stack + * @return + */ @Override public boolean isFoil(ItemStack stack) { return this.isGlowing; } + /** + * Return the color of the item for the Color Handler + * + * @return + */ @Override public DyeColor getColor() { return this.color; } + /** + * This is basically the same as the vanilla method for water bottles + * + * @param stack + * @param level + * @param user + * @return + */ @Override public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity user) { Player playerEntity; diff --git a/Common/src/main/java/me/hypherionmc/craterlib/common/item/DyableWaterBucket.java b/Common/src/main/java/me/hypherionmc/craterlib/common/item/DyableWaterBucket.java index 9dee392..d684f9b 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/common/item/DyableWaterBucket.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/common/item/DyableWaterBucket.java @@ -6,6 +6,9 @@ import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; +/** + * A custom water bucket that supports Dye Colors + */ public class DyableWaterBucket extends BucketItem implements ItemDyable { private final DyeColor color; @@ -17,6 +20,12 @@ public class DyableWaterBucket extends BucketItem implements ItemDyable { this.isGlowing = isGlowing; } + /** + * Normally this is used for enchanted items, in this case, it's used to check if the fluid is a glowing fluid + * + * @param stack + * @return + */ @Override public boolean isFoil(ItemStack stack) { return this.isGlowing; diff --git a/Common/src/main/java/me/hypherionmc/craterlib/common/network/BaseNetworkPacket.java b/Common/src/main/java/me/hypherionmc/craterlib/common/network/BaseNetworkPacket.java new file mode 100644 index 0000000..e9813b6 --- /dev/null +++ b/Common/src/main/java/me/hypherionmc/craterlib/common/network/BaseNetworkPacket.java @@ -0,0 +1,28 @@ +package me.hypherionmc.craterlib.common.network; + +import me.hypherionmc.craterlib.Constants; +import net.minecraft.Util; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.Level; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +// TODO: FINISH NETWORK IMPLEMENTATION +public interface BaseNetworkPacket { + + Map> PACKETS = Util.make(new HashMap<>(), map -> { + Constants.LOG.info("Registering Config Packets"); + }); + + void write(FriendlyByteBuf buf); + + void handle(Level level); + + record Handler(Class clazz, BiConsumer write, + Function read, + BiConsumer handle) { + } +} diff --git a/Common/src/main/java/me/hypherionmc/craterlib/common/particles/WrappedSimpleParticleType.java b/Common/src/main/java/me/hypherionmc/craterlib/common/particles/WrappedSimpleParticleType.java new file mode 100644 index 0000000..70d4fd4 --- /dev/null +++ b/Common/src/main/java/me/hypherionmc/craterlib/common/particles/WrappedSimpleParticleType.java @@ -0,0 +1,13 @@ +package me.hypherionmc.craterlib.common.particles; + +import net.minecraft.core.particles.SimpleParticleType; + +/** + * Helper Class for exposing a hidden constructor in the vanilla particle type + */ +public class WrappedSimpleParticleType extends SimpleParticleType { + + public WrappedSimpleParticleType(boolean alwaysShow) { + super(alwaysShow); + } +} diff --git a/Common/src/main/java/me/hypherionmc/craterlib/platform/services/IPlatformHelper.java b/Common/src/main/java/me/hypherionmc/craterlib/platform/services/IPlatformHelper.java index 58c4a21..bda69a3 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/platform/services/IPlatformHelper.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/platform/services/IPlatformHelper.java @@ -7,4 +7,5 @@ public interface IPlatformHelper { boolean isModLoaded(String modId); boolean isDevelopmentEnvironment(); + } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/systems/reg/package-info.java b/Common/src/main/java/me/hypherionmc/craterlib/systems/reg/package-info.java new file mode 100644 index 0000000..7943c47 --- /dev/null +++ b/Common/src/main/java/me/hypherionmc/craterlib/systems/reg/package-info.java @@ -0,0 +1,6 @@ +/** + * So, if you got here, most probably you want to see the registration system of this mod. + * Well, you are in the wrong place. This mod uses RegistrationUtils for + * all its registration needs. + */ +package me.hypherionmc.craterlib.systems.reg; diff --git a/Common/src/main/java/me/hypherionmc/craterlib/util/MathUtils.java b/Common/src/main/java/me/hypherionmc/craterlib/util/MathUtils.java index 94d8fc1..83bcfa5 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/util/MathUtils.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/util/MathUtils.java @@ -9,11 +9,11 @@ import net.minecraft.world.phys.shapes.VoxelShape; public class MathUtils { public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) { - VoxelShape[] buffer = new VoxelShape[]{ shape, Shapes.empty() }; + VoxelShape[] buffer = new VoxelShape[]{shape, Shapes.empty()}; int times = (to.ordinal() - from.ordinal() + 4) % 4; for (int i = 0; i < times; i++) { - buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.box(1-maxZ, minY, minX, 1-minZ, maxY, maxX))); + buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.box(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX))); buffer[0] = buffer[1]; buffer[1] = Shapes.empty(); } diff --git a/Common/src/main/java/me/hypherionmc/craterlib/util/OptifineUtils.java b/Common/src/main/java/me/hypherionmc/craterlib/util/OptifineUtils.java index ad1fe6e..b733855 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/util/OptifineUtils.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/util/OptifineUtils.java @@ -25,7 +25,8 @@ public class OptifineUtils { Class ofConfigClass = Class.forName("net.optifine.Config"); Method rrField = ofConfigClass.getMethod("isRenderRegions"); return (boolean) rrField.invoke(null); - } catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) { + } catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException | + IllegalAccessException e) { // Optifine is probably not present. Ignore the error return false; } catch (Exception e) { diff --git a/Common/src/main/java/me/hypherionmc/craterlib/util/RenderUtils.java b/Common/src/main/java/me/hypherionmc/craterlib/util/RenderUtils.java index ee17f5d..ab5639b 100644 --- a/Common/src/main/java/me/hypherionmc/craterlib/util/RenderUtils.java +++ b/Common/src/main/java/me/hypherionmc/craterlib/util/RenderUtils.java @@ -39,12 +39,15 @@ public class RenderUtils { public static int alpha(int pPackedColor) { return pPackedColor >>> 24; } + public static int red(int pPackedColor) { return pPackedColor >> 16 & 255; } + public static int green(int pPackedColor) { return pPackedColor >> 8 & 255; } + public static int blue(int pPackedColor) { return pPackedColor & 255; } diff --git a/Common/src/main/resources/craterlib.aw b/Common/src/main/resources/craterlib.aw new file mode 100644 index 0000000..9155d3a --- /dev/null +++ b/Common/src/main/resources/craterlib.aw @@ -0,0 +1,3 @@ +accessWidener v1 named + +accessible class net/minecraft/client/renderer/LevelRenderer$RenderChunkInfo diff --git a/Common/src/main/resources/pack.mcmeta b/Common/src/main/resources/pack.mcmeta index 52854ec..41b63a1 100644 --- a/Common/src/main/resources/pack.mcmeta +++ b/Common/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { - "pack": { - "description": "${mod_name}", - "pack_format": 8 - } -} \ No newline at end of file + "pack": { + "description": "${mod_name}", + "pack_format": 8 + } +} diff --git a/Fabric/build.gradle b/Fabric/build.gradle index c569b4c..8c0509c 100644 --- a/Fabric/build.gradle +++ b/Fabric/build.gradle @@ -11,10 +11,13 @@ dependencies { mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" + include 'me.hypherionmc.night-config:toml:3.6.5_custom' + include 'me.hypherionmc.night-config:core:3.6.5_custom' implementation project(":Common") } loom { + accessWidenerPath = project(":Common").file("src/main/resources/craterlib.aw") runs { client { client() @@ -62,12 +65,26 @@ publishing { artifactId project.archivesBaseName version project.version from components.java + pom.withXml { + Node pomNode = asNode() + pomNode.dependencies.'*'.findAll() { + it.artifactId.text() == 'regutils-joined-fabric' || + it.artifactId.text() == 'core' || + it.artifactId.text() == 'toml' + }.each() { + it.parent().remove(it) + } + } } } repositories { maven { - url "file://" + System.getenv("local_maven") + url "https://maven.firstdarkdev.xyz/" + (project.isSnapshot ? "snapshots" : "releases") + credentials { + username System.getenv("MAVEN_USER") + password System.getenv("MAVEN_PASS") + } } } } diff --git a/Fabric/src/main/java/me/hypherionmc/craterlib/CraterLibInitializer.java b/Fabric/src/main/java/me/hypherionmc/craterlib/CraterLibInitializer.java index 1a92617..c603cf8 100644 --- a/Fabric/src/main/java/me/hypherionmc/craterlib/CraterLibInitializer.java +++ b/Fabric/src/main/java/me/hypherionmc/craterlib/CraterLibInitializer.java @@ -1,11 +1,14 @@ package me.hypherionmc.craterlib; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.resource.ResourceManagerHelper; +import net.minecraft.server.packs.PackType; public class CraterLibInitializer implements ModInitializer { @Override public void onInitialize() { + var resources = ResourceManagerHelper.get(PackType.CLIENT_RESOURCES); } } diff --git a/Fabric/src/main/resources/fabric.mod.json b/Fabric/src/main/resources/fabric.mod.json index 72206b9..ac7372b 100644 --- a/Fabric/src/main/resources/fabric.mod.json +++ b/Fabric/src/main/resources/fabric.mod.json @@ -1,42 +1,39 @@ { - "schemaVersion": 1, - "id": "craterlib", - "version": "${version}", - - "name": "CraterLib", - "description": "A library mod used by HypherionSA's Mods", - "authors": [ - "Me!" + "schemaVersion": 1, + "id": "craterlib", + "version": "${version}", + "name": "CraterLib", + "description": "A library mod used by HypherionSA's Mods", + "authors": [ + "Me!" + ], + "contact": { + "homepage": "https://fabricmc.net/", + "sources": "https://github.com/FabricMC/fabric-example-mod" + }, + "license": "MIT", + "icon": "assets/modid/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "me.hypherionmc.craterlib.CraterLibInitializer" ], - "contact": { - "homepage": "https://fabricmc.net/", - "sources": "https://github.com/FabricMC/fabric-example-mod" - }, - - "license": "MIT", - "icon": "assets/modid/icon.png", - - "environment": "*", - "entrypoints": { - "main": [ - "me.hypherionmc.craterlib.CraterLibInitializer" - ], - "client": [ - "me.hypherionmc.craterlib.client.CraterLibClientInitializer" - ] - }, - "mixins": [ - "craterlib.mixins.json", - "craterlib.fabric.mixins.json" - ], - - "depends": { - "fabricloader": ">=0.12", - "fabric": "*", - "minecraft": "1.18.x", - "java": ">=17" - }, - "suggests": { - "another-mod": "*" - } + "client": [ + "me.hypherionmc.craterlib.client.CraterLibClientInitializer" + ] + }, + "mixins": [ + "craterlib.mixins.json", + "craterlib.fabric.mixins.json" + ], + "accessWidener": "craterlib.aw", + "depends": { + "fabricloader": ">=0.12", + "fabric": "*", + "minecraft": "1.18.x", + "java": ">=17" + }, + "suggests": { + "another-mod": "*" } +} diff --git a/Forge/build.gradle b/Forge/build.gradle index 921bca4..be36257 100644 --- a/Forge/build.gradle +++ b/Forge/build.gradle @@ -9,6 +9,9 @@ buildscript { classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' } } +plugins { + id 'com.github.johnrengelman.shadow' version '7.0.0' +} apply plugin: 'java' apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' @@ -97,7 +100,22 @@ processResources { } } +shadowJar { + dependencies { + include(dependency('me.hypherionmc.night-config:toml:3.6.5_custom')) + include(dependency('me.hypherionmc.night-config:core:3.6.5_custom')) + //relocate 'me.hypherionmc.nightconfig', 'shadow.hypherionmc.nightconfig' + } + classifier '' +} + +reobf { + shadowJar {} +} + +build.dependsOn reobfShadowJar +reg.configureJarTask(shadowJar) jar.finalizedBy('reobfJar') publishing { @@ -106,12 +124,26 @@ publishing { groupId project.group artifactId project.archivesBaseName version project.version - artifact jar + artifact shadowJar + pom.withXml { + Node pomNode = asNode() + pomNode.dependencies.'*'.findAll() { + it.artifactId.text() == 'regutils-joined-fabric' || + it.artifactId.text() == 'core' || + it.artifactId.text() == 'toml' + }.each() { + it.parent().remove(it) + } + } } } repositories { maven { - url "file://" + System.getenv("local_maven") + url "https://maven.firstdarkdev.xyz/" + (project.isSnapshot ? "snapshots" : "releases") + credentials { + username System.getenv("MAVEN_USER") + password System.getenv("MAVEN_PASS") + } } } } @@ -122,4 +154,4 @@ task copyAllArtifacts(type: Copy) { include("*.jar") } -build.finalizedBy(copyAllArtifacts); +build.finalizedBy(copyAllArtifacts) diff --git a/Forge/src/main/resources/META-INF/accesstransformer.cfg b/Forge/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 0000000..bf1848b --- /dev/null +++ b/Forge/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1 @@ +public net.minecraft.client.renderer.LevelRenderer$RenderChunkInfo diff --git a/Forge/src/main/resources/META-INF/mods.toml b/Forge/src/main/resources/META-INF/mods.toml index e6ea5ee..5c66957 100644 --- a/Forge/src/main/resources/META-INF/mods.toml +++ b/Forge/src/main/resources/META-INF/mods.toml @@ -1,31 +1,31 @@ -modLoader="javafml" -loaderVersion="[40,)" -license="MIT" +modLoader = "javafml" +loaderVersion = "[40,)" +license = "MIT" #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" [[mods]] -modId="craterlib" -version="${file.jarVersion}" -displayName="CraterLib" +modId = "craterlib" +version = "${file.jarVersion}" +displayName = "CraterLib" #updateJSONURL="https://change.me.example.invalid/updates.json" #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" -logoFile="multiloader.png" +logoFile = "multiloader.png" #credits="Thanks for this example mod goes to Java" -authors="HypherionSA, Misha" -description=''' +authors = "HypherionSA, Misha" +description = ''' A library mod used by HypherionSA's Mods ''' [[dependencies.craterlib]] - modId="forge" - mandatory=true - versionRange="[40,)" - ordering="NONE" - side="BOTH" +modId = "forge" +mandatory = true +versionRange = "[40,)" +ordering = "NONE" +side = "BOTH" [[dependencies.craterlib]] - modId="minecraft" - mandatory=true - versionRange="[1.18.2,1.19)" - ordering="NONE" - side="BOTH" +modId = "minecraft" +mandatory = true +versionRange = "[1.18.2,1.19)" +ordering = "NONE" +side = "BOTH" diff --git a/README.md b/README.md index c67c0ff..7c44eff 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,24 @@ A library mod used by HypherionSA's mods. Mostly used by Hyper Lighting 2. +*** + +## Library Features + +* Universal Config System (TOML Based) +* Easy Cross Mod-Loader registration System +* Built in Helper Classes for Various minecraft features +* Built in FluidTank and Energy systems for Forge/Fabric (Forge versions are just wrappers). +* Built in Optifine-Compat utilities +* Various utilities for Blockstates, LANG, Math and Rendering +* TODO: Built in Cross Mod-Loader Network system +* TODO: Various GUI widgets and Utilities +* TODO: Cross Mod-Loader Dynamic Lighting +* TODO: Texture Utils +* TODO: Sync Config From Server to Client + +*** + ## Setup Instructions *Coming Soon* diff --git a/build.gradle b/build.gradle index e52d38b..3ecfc78 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,31 @@ +plugins { + id 'java' + id 'com.matyrobbrt.mc.registrationutils' version '0.2.6' +} + +registrationUtils { + group 'me.hypherionmc.craterlib.systems.reg' + projects { + Common { type 'common'; project ':Common' } + Fabric { type 'fabric'; project ':Fabric' } + Forge { type 'forge'; project ':Forge' } + } +} + subprojects { + ext { + isSnapshot: false + } + def version_base = "${project.version_major}.${project.version_minor}" version = "${version_base}.${project.version_patch}" + group = project.group + // Jenkins if (System.getenv('BUILD_NUMBER') != null) { + project.isSnapshot = true version = version_base + "." + System.getenv('BUILD_NUMBER') + "d" } @@ -17,16 +38,16 @@ subprojects { jar { manifest { attributes([ - 'Specification-Title' : mod_name, - 'Specification-Vendor' : mod_author, - 'Specification-Version' : project.jar.archiveVersion, - 'Implementation-Title' : project.name, - 'Implementation-Version' : project.jar.archiveVersion, - 'Implementation-Vendor' : mod_author, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Timestampe' : System.currentTimeMillis(), - 'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", - 'Build-On-Minecraft' : minecraft_version + 'Specification-Title' : mod_name, + 'Specification-Vendor' : mod_author, + 'Specification-Version' : project.jar.archiveVersion, + 'Implementation-Title' : project.name, + 'Implementation-Version' : project.jar.archiveVersion, + 'Implementation-Vendor' : mod_author, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Timestampe' : System.currentTimeMillis(), + 'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", + 'Build-On-Minecraft' : minecraft_version ]) } } @@ -37,6 +58,15 @@ subprojects { name = 'Sponge / Mixin' url = 'https://repo.spongepowered.org/repository/maven-public/' } + maven { + name = 'Hypherion Maven' + url = 'https://maven.firstdarkdev.xyz/releases/' + } + } + + dependencies { + implementation 'me.hypherionmc.night-config:toml:3.6.5_custom' + implementation 'me.hypherionmc.night-config:core:3.6.5_custom' } tasks.withType(JavaCompile).configureEach { diff --git a/gradle.properties b/gradle.properties index 663d90d..fb0e617 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Project version_major=1 version_minor=0 -version_patch=0 +version_patch=5 group=me.hypherionmc.craterlib # Common @@ -10,10 +10,9 @@ common_runs_enabled=false common_client_run_name=Common Client common_server_run_name=Common Server - # Forge forge_version=40.1.0 -//forge_ats_enabled=true +forge_ats_enabled=true # Fabric fabric_version=0.51.1+1.18.2