diff --git a/1.19.2/build.gradle b/1.19.2/build.gradle index 9047fb2..f3ac02f 100644 --- a/1.19.2/build.gradle +++ b/1.19.2/build.gradle @@ -10,7 +10,7 @@ architectury { allprojects { group = rootProject.maven_group - version = "$project.name-$rootProject.mod_version" + version = "$project.name-$rootProject.loader_safe_version-mc$rootProject.minecraft_version" } diff --git a/1.19.2/common/build.gradle b/1.19.2/common/build.gradle index 816616f..be4a2ab 100644 --- a/1.19.2/common/build.gradle +++ b/1.19.2/common/build.gradle @@ -10,4 +10,6 @@ dependencies { // Architectury API. This is optional, and you can comment it out if you don't need it. modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version" + + } diff --git a/1.19.2/common/src/main/java/org/TestSystem/TestMod.java b/1.19.2/common/src/main/java/org/TestSystem/TestMod.java new file mode 100644 index 0000000..b87b5c5 --- /dev/null +++ b/1.19.2/common/src/main/java/org/TestSystem/TestMod.java @@ -0,0 +1,21 @@ +package org.TestSystem; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import org.TestSystem.world.Blocks.TestBlocks; +import org.TestSystem.world.Items.CreativeModeTabs; +import org.TestSystem.world.Items.TestItems; + +public class TestMod { + public static final String MODID = "vrglabslib"; + + public static void init(){ + CreativeModeTabs.init(); + TestItems.init(); + TestBlocks.init(); + } + + public static Item.Settings basicItemSettings() { + return new Item.Settings().group(ItemGroup.DECORATIONS); + } +} diff --git a/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestBlockEntity.java b/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestBlockEntity.java new file mode 100644 index 0000000..7b4cc29 --- /dev/null +++ b/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestBlockEntity.java @@ -0,0 +1,15 @@ +package org.TestSystem.world.Blocks; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.math.BlockPos; +import org.Vrglab.Utils.Utils; + +public class TestBlockEntity extends BlockEntity { + public TestBlockEntity(BlockPos pos, BlockState state) { + super(Utils.convertToMcSafeType(TestBlocks.TEST_ENTITY_BLOCK_TYPE), pos, state); + } + + +} diff --git a/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestBlocks.java b/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestBlocks.java new file mode 100644 index 0000000..67bc832 --- /dev/null +++ b/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestBlocks.java @@ -0,0 +1,22 @@ +package org.TestSystem.world.Blocks; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.Material; +import org.TestSystem.TestMod; +import org.Vrglab.Modloader.Registration.Registry; + +public class TestBlocks { + + public static Object TEST_BLOCK = Registry.RegisterBlock("test_block", TestMod.MODID, ()->new Block(AbstractBlock.Settings.of(Material.METAL)), TestMod.basicItemSettings()); + public static Object TEST_ITEMLESS_BLOCK = Registry.RegisterItemlessBlock("test_itemless_block", TestMod.MODID, ()->new Block(AbstractBlock.Settings.of(Material.METAL))); + + public static Object TEST_POI_BLOCK = Registry.RegisterBlock("test_poi_block", TestMod.MODID, ()->new Block(AbstractBlock.Settings.of(Material.METAL)), TestMod.basicItemSettings()); + public static Object TEST_ENTITY_BLOCK = Registry.RegisterBlock("test_entity_block", TestMod.MODID, ()->new TestEntityBlockHolder(AbstractBlock.Settings.of(Material.METAL)), TestMod.basicItemSettings()); + + public static Object TEST_ENTITY_BLOCK_TYPE = Registry.RegisterBlockEntityType("test_entity_block_type", TestMod.MODID, TestBlockEntity::new, TEST_ENTITY_BLOCK); + + public static void init() { + + } +} diff --git a/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestEntityBlockHolder.java b/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestEntityBlockHolder.java new file mode 100644 index 0000000..5652f49 --- /dev/null +++ b/1.19.2/common/src/main/java/org/TestSystem/world/Blocks/TestEntityBlockHolder.java @@ -0,0 +1,27 @@ +package org.TestSystem.world.Blocks; + +import net.minecraft.block.BlockEntityProvider; +import net.minecraft.block.BlockRenderType; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; + +public class TestEntityBlockHolder extends BlockWithEntity implements BlockEntityProvider { + + protected TestEntityBlockHolder(Settings settings) { + super(settings); + } + + @Nullable + @Override + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new TestBlockEntity(pos, state); + } + + @Override + public BlockRenderType getRenderType(BlockState state) { + return BlockRenderType.MODEL; + } +} diff --git a/1.19.2/common/src/main/java/org/TestSystem/world/Items/CreativeModeTabs.java b/1.19.2/common/src/main/java/org/TestSystem/world/Items/CreativeModeTabs.java new file mode 100644 index 0000000..d632598 --- /dev/null +++ b/1.19.2/common/src/main/java/org/TestSystem/world/Items/CreativeModeTabs.java @@ -0,0 +1,8 @@ +package org.TestSystem.world.Items; + +public class CreativeModeTabs { + + public static void init(){ + + } +} diff --git a/1.19.2/common/src/main/java/org/TestSystem/world/Items/TestItems.java b/1.19.2/common/src/main/java/org/TestSystem/world/Items/TestItems.java new file mode 100644 index 0000000..6832c7d --- /dev/null +++ b/1.19.2/common/src/main/java/org/TestSystem/world/Items/TestItems.java @@ -0,0 +1,15 @@ +package org.TestSystem.world.Items; + +import net.minecraft.item.Item; +import org.TestSystem.TestMod; +import org.Vrglab.Modloader.Registration.Registry; + +public class TestItems { + + public static Object TEST_ITEM = Registry.RegisterItem("test_item", TestMod.MODID, ()->new Item(TestMod.basicItemSettings())); + + + public static void init(){ + + } +} diff --git a/1.19.2/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/TypeTransformer.java b/1.19.2/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/TypeTransformer.java index fd0c1d4..9b43e3e 100644 --- a/1.19.2/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/TypeTransformer.java +++ b/1.19.2/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/TypeTransformer.java @@ -1,8 +1,9 @@ package org.Vrglab.Modloader.CreationHelpers; -import net.minecraft.block.entity.BlockEntityType; import org.Vrglab.Modloader.Types.ICallBack; +import org.jetbrains.annotations.ApiStatus; +@ApiStatus.Internal public class TypeTransformer { public static ICallBack ObjectToType; diff --git a/1.19.2/common/src/main/java/org/Vrglab/Modloader/Registration/Registry.java b/1.19.2/common/src/main/java/org/Vrglab/Modloader/Registration/Registry.java index 337b748..5a8f3f0 100644 --- a/1.19.2/common/src/main/java/org/Vrglab/Modloader/Registration/Registry.java +++ b/1.19.2/common/src/main/java/org/Vrglab/Modloader/Registration/Registry.java @@ -6,7 +6,6 @@ import net.minecraft.item.Item; import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeType; -import net.minecraft.screen.ScreenHandlerType; import net.minecraft.sound.SoundEvent; import net.minecraft.village.TradeOffer; import net.minecraft.world.gen.GenerationStep; @@ -16,6 +15,7 @@ import org.Vrglab.Modloader.Types.ICallBack; import org.Vrglab.Modloader.Types.IScreenHandledCreationFunction; import org.Vrglab.Modloader.Types.IScreenHandlerTypeCreationFunction; +import org.Vrglab.Modloader.enumTypes.IRegistryType; import org.Vrglab.Modloader.enumTypes.RegistryTypes; import org.Vrglab.Modloader.enumTypes.VinillaBiomeTypes; import org.Vrglab.Screen.ScreenHandler; @@ -32,7 +32,7 @@ */ public class Registry { private static class UnregisteredData{ - public UnregisteredData(int registry_type, Object... args) { + public UnregisteredData(UUID registry_type, Object... args) { this.registry_type = registry_type; this.args = new ArrayList<>(); for (Object argdata: args) { @@ -41,18 +41,18 @@ public UnregisteredData(int registry_type, Object... args) { } public List args; - public int registry_type; + public UUID registry_type; public boolean resolved; public Object Obj = null; } - private static Map> open_registeries = new HashMap<>(); + private static Map> open_registeries = new HashMap<>(); private static Map> ready_to_load_registeries = new HashMap<>(); /** * Initializes a Modloader's Registry to be used for loading of objects - *
(Using this function is extremely not recommended, unless you trully know what you are really doing, instead use {@link #initRegistry(ICallBack, RegistryTypes, String)})
+ *
(Using this function is extremely not recommended, unless you trully know what you are really doing, instead use {@link #initRegistry(ICallBack, IRegistryType, String)})
* @param _registery The registry code * @param _currentRegistryTypes the type of registry * @param modid the Mod ID @@ -60,7 +60,7 @@ public UnregisteredData(int registry_type, Object... args) { * @author Arad Bozorgmehr * @since 1.1.0 */ - public static void initRegistry(ICallBack _registery, int _currentRegistryTypes, String modid){ + public static void initRegistry(ICallBack _registery, UUID _currentRegistryTypes, String modid){ if(open_registeries.containsKey(modid)){ open_registeries.get(modid).put(_currentRegistryTypes, _registery); } else{ @@ -86,21 +86,8 @@ public static void initRegistry(ICallBack _registery, int _currentRegistryTypes, * @author Arad Bozorgmehr * @since 1.0.0 */ - public static void initRegistry(ICallBack _registery, RegistryTypes _currentRegistryTypes, String modid){ - if(open_registeries.containsKey(modid)){ - open_registeries.get(modid).put(_currentRegistryTypes.getTypeId(), _registery); - } else{ - open_registeries.put(modid, new HashMap()); - open_registeries.get(modid).put(_currentRegistryTypes.getTypeId(), _registery); - } - if(ready_to_load_registeries.containsKey(modid) && ready_to_load_registeries.get(modid).size() > 0) { - for (UnregisteredData data: ready_to_load_registeries.get(modid)) { - if(!data.resolved && data.registry_type == _currentRegistryTypes.getTypeId()){ - data.Obj = _registery.accept(data.args.toArray()); - data.resolved = true; - } - } - } + public static void initRegistry(ICallBack _registery, IRegistryType _currentRegistryTypes, String modid){ + initRegistry(_registery, _currentRegistryTypes.getTypeId(), modid); } /** @@ -113,19 +100,13 @@ public static void initRegistry(ICallBack _registery, RegistryTypes _currentRegi * @author Arad Bozorgmehr * @since 1.0.0 */ - public static void ForgeEventResolver(Object eventData, ICallBack resolver, RegistryTypes ResolveTypeOf, String modid){ - if(ready_to_load_registeries.containsKey(modid) && ready_to_load_registeries.get(modid).size() > 0) { - for (UnregisteredData data: ready_to_load_registeries.get(modid)) { - if(!data.resolved && data.registry_type == ResolveTypeOf.getTypeId()){ - data.Obj = resolver.accept(data.args.toArray(), eventData); - } - } - } + public static void ForgeEventResolver(Object eventData, ICallBack resolver, IRegistryType ResolveTypeOf, String modid){ + ForgeEventResolver(eventData, resolver, ResolveTypeOf.getTypeId(), modid); } /** * Creates an Event resolver for forge - *
(Using this function is extremely not recommended, unless you trully know what you are really doing, instead use {@link #ForgeEventResolver(Object, ICallBack, RegistryTypes, String)})
+ *
(Using this function is extremely not recommended, unless you truly know what you are really doing, instead use {@link #ForgeEventResolver(Object, ICallBack, IRegistryType, String)})
* @param eventData The event data * @param resolver The resolver code * @param ResolveTypeOf The type of Object this event resolves @@ -134,7 +115,7 @@ public static void ForgeEventResolver(Object eventData, ICallBack resolver, Regi * @author Arad Bozorgmehr * @since 1.1.0 */ - public static void ForgeEventResolver(Object eventData, ICallBack resolver, int ResolveTypeOf, String modid){ + public static void ForgeEventResolver(Object eventData, ICallBack resolver, UUID ResolveTypeOf, String modid){ if(ready_to_load_registeries.containsKey(modid) && ready_to_load_registeries.get(modid).size() > 0) { for (UnregisteredData data: ready_to_load_registeries.get(modid)) { if(!data.resolved && data.registry_type == ResolveTypeOf){ @@ -147,7 +128,7 @@ public static void ForgeEventResolver(Object eventData, ICallBack resolver, int /** * Register's a new Item for MC. Based on what Mod loader we are on, We either receive the Object itself or a * RegistryObject of the Object, to safely use the Object in other pieces of - * code use {@link org.Vrglab.Modloader.CreationHelpers.TypeTransformer#ObjectToType} + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} * @param name The Item name (aka ID) * @param Modid The Mod Id of the Registerar * @param aNew The supplier which gives us the Item Instance @@ -163,7 +144,7 @@ public static Object RegisterItem(String name, String Modid, Supplier aNew) { /** * Register's a new Block for MC. Based on what Mod loader we are on, We either receive the Object itself or a * RegistryObject of the Object, to safely use the Object in other pieces of - * code use {@link org.Vrglab.Modloader.CreationHelpers.TypeTransformer#ObjectToType} + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} * @param name The Block name (aka ID) * @param Modid The Mod Id of the Registerar * @param aNew The supplier which gives us the Block Instance @@ -180,11 +161,11 @@ public static Object RegisterBlock(String name, String Modid, Supplier aNew, Ite /** * Register's a new Block Entity for MC. Based on what Mod loader we are on, We either receive the Object itself or a * RegistryObject of the Object, to safely use the Object in other pieces of - * code use {@link org.Vrglab.Modloader.CreationHelpers.TypeTransformer#ObjectToType} + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} * @param name The Block Entity name (aka ID) * @param Modid The Mod Id of the Registerar * @param aNew The ::new which gives us the Block Entity Instance - * @param block The block to attach the entity to (NOT converted using {@link org.Vrglab.Modloader.CreationHelpers.TypeTransformer#ObjectToType}) + * @param block The block to attach the entity to (NOT converted using {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)}) * @return The registered data * * @author Arad Bozorgmehr @@ -199,7 +180,7 @@ public static Object RegisterBlockEntityType(String name, String Modid, IBlockEn * @param name The Screen Handler name (aka ID) * @param Modid The Mod Id of the Registerar * @param aNew The ::new which gives us the Screen Handler Instance - * @return The registered data (The return value of this Function CAN NOT be converted using {@link org.Vrglab.Modloader.CreationHelpers.TypeTransformer#ObjectToType}) + * @return The registered data (The return value of this Function CAN NOT be converted using {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)}) * * @author Arad Bozorgmehr * @since 1.0.0 @@ -225,7 +206,7 @@ public static ()); - ready_to_load_registeries.get(Modid).add(data); - } - else - ready_to_load_registeries.get(Modid).add(data); - return data.Obj; - } + public static Object SimpleRegister(IRegistryType type, String Modid, Object... args){ + return SimpleRegister(type.getTypeId(), Modid, args); } /** * Sends data to the modloader for something to be registered for MC - *
(Using this function is extremely not recommended, unless you trully know what you are really doing, instead use {@link #SimpleRegister(RegistryTypes, String, Object...)})
+ *
(Using this function is extremely not recommended, unless you trully know what you are really doing, instead use {@link #SimpleRegister(IRegistryType, String, Object...)})
* @param type The type to use for registeration * @param Modid The Mod Id of the Registerar * @param args All the arguments needed to register the Object (On the callback end of this interaction the arguments are fed in the EXACT same order) @@ -360,8 +329,8 @@ public static Object SimpleRegister(RegistryTypes type, String Modid, Object... * @author Arad Bozorgmehr * @since 1.1.0 */ - public static Object SimpleRegister(int type, String Modid, Object... args){ - VLModInfo.LOGGER.info("Registering "+String.valueOf(type).toLowerCase() +" " + args[0] + " for " + Modid); + public static Object SimpleRegister(UUID type, String Modid, Object... args){ + VLModInfo.LOGGER.info("Registry "+String.valueOf(type).toLowerCase() +" Registering " + args[0] + " for " + Modid); if(open_registeries.containsKey(Modid) && open_registeries.get(Modid).containsKey(type)) return open_registeries.get(Modid).get(type).accept(args); else { diff --git a/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/IRegistryType.java b/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/IRegistryType.java new file mode 100644 index 0000000..7aa1498 --- /dev/null +++ b/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/IRegistryType.java @@ -0,0 +1,7 @@ +package org.Vrglab.Modloader.enumTypes; + +import java.util.UUID; + +public interface IRegistryType { + UUID getTypeId(); +} diff --git a/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryType.java b/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryType.java new file mode 100644 index 0000000..442b4d7 --- /dev/null +++ b/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryType.java @@ -0,0 +1,6 @@ +package org.Vrglab.Modloader.enumTypes; + +public interface RegistryType { + public int getTypeId(); + +} diff --git a/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryTypes.java b/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryTypes.java index 56b8307..c26ec1f 100644 --- a/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryTypes.java +++ b/1.19.2/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryTypes.java @@ -1,45 +1,38 @@ package org.Vrglab.Modloader.enumTypes; -public enum RegistryTypes { - ITEM(0), - BLOCK(1), - ITEMLESS_BLOCK(2), - ENTITY_BLOCK(3), - MENU(4), - RECIPE(5), - ENTITY(6), - TAG(7), - BIOM(8), - STRUCTURE(9), - POI(10), - PROFESSION(11), - TRADE(12), - CONFIGURED_FEAT_ORE(13), - PLACED_FEAT(14), - BIOME_MODIFICATIONS(15), - BLOCK_ENTITY_TYPE(16), - SCREEN_HANDLER_TYPE(17), - HANDLED_SCREEN(18), - RECIPE_SERIALIZER(19), - RECIPE_TYPE(20) +import java.util.UUID; + +public enum RegistryTypes implements IRegistryType { + ITEM(UUID.randomUUID()), + BLOCK(UUID.randomUUID()), + ITEMLESS_BLOCK(UUID.randomUUID()), + ENTITY_BLOCK(UUID.randomUUID()), + MENU(UUID.randomUUID()), + RECIPE(UUID.randomUUID()), + ENTITY(UUID.randomUUID()), + TAG(UUID.randomUUID()), + BIOM(UUID.randomUUID()), + STRUCTURE(UUID.randomUUID()), + POI(UUID.randomUUID()), + PROFESSION(UUID.randomUUID()), + TRADE(UUID.randomUUID()), + CONFIGURED_FEAT_ORE(UUID.randomUUID()), + PLACED_FEAT(UUID.randomUUID()), + BIOME_MODIFICATIONS(UUID.randomUUID()), + BLOCK_ENTITY_TYPE(UUID.randomUUID()), + SCREEN_HANDLER_TYPE(UUID.randomUUID()), + HANDLED_SCREEN(UUID.randomUUID()), + RECIPE_SERIALIZER(UUID.randomUUID()), + RECIPE_TYPE(UUID.randomUUID()) ; - private final int getTypeId; - RegistryTypes(int type) { + private final UUID getTypeId; + RegistryTypes(UUID type) { getTypeId = type; } - public int getTypeId() { + public UUID getTypeId() { return getTypeId; } - - public static RegistryTypes fromTypeId(int typeId) { - for (RegistryTypes type : values()) { - if (type.getTypeId() == typeId) { - return type; - } - } - throw new IllegalArgumentException("No enum constant with typeId " + typeId); - } } diff --git a/1.19.2/common/src/main/java/org/Vrglab/Utils/Utils.java b/1.19.2/common/src/main/java/org/Vrglab/Utils/Utils.java new file mode 100644 index 0000000..0559738 --- /dev/null +++ b/1.19.2/common/src/main/java/org/Vrglab/Utils/Utils.java @@ -0,0 +1,10 @@ +package org.Vrglab.Utils; + +import org.Vrglab.Modloader.CreationHelpers.TypeTransformer; + +public class Utils { + + public static T convertToMcSafeType(Object registry_result){ + return (T)TypeTransformer.ObjectToType.accept(registry_result); + } +} diff --git a/1.19.2/common/src/main/java/org/Vrglab/VrglabsLib.java b/1.19.2/common/src/main/java/org/Vrglab/VrglabsLib.java index 03b82bb..1bf596d 100644 --- a/1.19.2/common/src/main/java/org/Vrglab/VrglabsLib.java +++ b/1.19.2/common/src/main/java/org/Vrglab/VrglabsLib.java @@ -1,5 +1,8 @@ package org.Vrglab; + +import org.TestSystem.TestMod; + public final class VrglabsLib { public static void init() { diff --git a/1.19.2/fabric-like/build.gradle b/1.19.2/fabric-like/build.gradle index ec5aaf0..003311f 100644 --- a/1.19.2/fabric-like/build.gradle +++ b/1.19.2/fabric-like/build.gradle @@ -9,6 +9,7 @@ dependencies { // Architectury API. This is optional, and you can comment it out if you don't need it. modImplementation "dev.architectury:architectury-fabric:$rootProject.architectury_api_version" + compileOnly(project(path: ':common', configuration: 'namedElements')) { transitive false } } diff --git a/1.19.2/fabric-like/src/main/java/org/Vrglab/fabriclike/Utils/FabricLikeRegisteryCreator.java b/1.19.2/fabric-like/src/main/java/org/Vrglab/fabriclike/Utils/FabricLikeRegisteryCreator.java index 6485abf..c7d17d6 100644 --- a/1.19.2/fabric-like/src/main/java/org/Vrglab/fabriclike/Utils/FabricLikeRegisteryCreator.java +++ b/1.19.2/fabric-like/src/main/java/org/Vrglab/fabriclike/Utils/FabricLikeRegisteryCreator.java @@ -9,11 +9,9 @@ import net.fabricmc.fabric.api.object.builder.v1.villager.VillagerProfessionBuilder; import net.fabricmc.fabric.api.object.builder.v1.world.poi.PointOfInterestHelper; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; -import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.entity.player.PlayerInventory; @@ -41,7 +39,6 @@ import net.minecraft.world.gen.placementmodifier.PlacementModifier; import org.Vrglab.EnergySystem.EnergyStorage; import org.Vrglab.EnergySystem.EnergyStorageUtils; -import org.Vrglab.EnergySystem.IEnergySupplier; import org.Vrglab.Modloader.CreationHelpers.OreGenFeatCreationHelper; import org.Vrglab.Modloader.CreationHelpers.PlacementModifierCreationHelper; import org.Vrglab.Modloader.CreationHelpers.TypeTransformer; @@ -60,21 +57,8 @@ public class FabricLikeRegisteryCreator { public static void Create(String modid) { setEnergyStorageStatics(modid); - - OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() { - @Override - public Object accept(Object... args) { - return ((Block)args[0]).getDefaultState(); - } - }; - - PlacementModifierCreationHelper.getHeightModifications = new ICallBack() { - @Override - public Object accept(Object... args) { - return HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom((Integer) args[0]), YOffset.aboveBottom((Integer) args[1])); - } - }; - + setOreGenHelperStatics(); + setNetworkStatics(); TypeTransformer.ObjectToType = new ICallBack() { @Override @@ -83,19 +67,7 @@ public Object accept(Object... args) { } }; - Network.registerGlobalReceiver = new ICallbackVoid() { - @Override - public void accept(Object... args) { - ServerPlayNetworking.registerGlobalReceiver((Identifier) args[0], (a,b,c,d,e)->((ICallBack)args[1]).accept(a,b,c,d,e)); - } - }; - Network.clientSendPacket = new ICallbackVoid() { - @Override - public void accept(Object... args) { - ClientPlayNetworking.send((Identifier) args[0], (PacketByteBuf) args[1]); - } - }; ICallBack ItemRegistryCallBack = new ICallBack() { @Override @@ -249,7 +221,6 @@ public Screen create(ScreenHandler handler, PlayerInventory playerInventory, Tex Registry.initRegistry(HandledScreensRegistryCallBack, RegistryTypes.HANDLED_SCREEN, modid); } - private static void setEnergyStorageStatics(String modid) { EnergyStorageUtils.createStorageInstance = new ICallBack() { @Override @@ -314,4 +285,36 @@ public Object accept(Object... args) { } }; } + + private static void setOreGenHelperStatics() { + OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() { + @Override + public Object accept(Object... args) { + return ((Block)args[0]).getDefaultState(); + } + }; + + PlacementModifierCreationHelper.getHeightModifications = new ICallBack() { + @Override + public Object accept(Object... args) { + return HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom((Integer) args[0]), YOffset.aboveBottom((Integer) args[1])); + } + }; + } + + private static void setNetworkStatics() { + Network.registerGlobalReceiver = new ICallbackVoid() { + @Override + public void accept(Object... args) { + ServerPlayNetworking.registerGlobalReceiver((Identifier) args[0], (a,b,c,d,e)->((ICallBack)args[1]).accept(a,b,c,d,e)); + } + }; + + Network.clientSendPacket = new ICallbackVoid() { + @Override + public void accept(Object... args) { + ClientPlayNetworking.send((Identifier) args[0], (PacketByteBuf) args[1]); + } + }; + } } diff --git a/1.19.2/fabric/build.gradle b/1.19.2/fabric/build.gradle index 160c5f2..763bb52 100644 --- a/1.19.2/fabric/build.gradle +++ b/1.19.2/fabric/build.gradle @@ -32,6 +32,8 @@ dependencies { // Architectury API. This is optional, and you can comment it out if you don't need it. modImplementation "dev.architectury:architectury-fabric:$rootProject.architectury_api_version" + + common(project(path: ':common', configuration: 'namedElements')) { transitive false } shadowBundle project(path: ':common', configuration: 'transformProductionFabric') diff --git a/1.19.2/forge/build.gradle b/1.19.2/forge/build.gradle index dafe20d..336f9bc 100644 --- a/1.19.2/forge/build.gradle +++ b/1.19.2/forge/build.gradle @@ -36,6 +36,8 @@ dependencies { // Architectury API. This is optional, and you can comment it out if you don't need it. modImplementation "dev.architectury:architectury-forge:$rootProject.architectury_api_version" + + common(project(path: ':common', configuration: 'namedElements')) { transitive false } shadowBundle project(path: ':common', configuration: 'transformProductionForge') } diff --git a/1.19.2/forge/src/main/java/org/Vrglab/forge/Utils/ForgeRegistryCreator.java b/1.19.2/forge/src/main/java/org/Vrglab/forge/Utils/ForgeRegistryCreator.java index ae17da2..612cc87 100644 --- a/1.19.2/forge/src/main/java/org/Vrglab/forge/Utils/ForgeRegistryCreator.java +++ b/1.19.2/forge/src/main/java/org/Vrglab/forge/Utils/ForgeRegistryCreator.java @@ -57,7 +57,7 @@ public class ForgeRegistryCreator { - public static ICallBack TradeRegistryEventCallback = new ICallBack() { + private static ICallBack TradeRegistryEventCallback = new ICallBack() { @Override public Object accept(Object... args) { Object[] arg = (Object[]) args[0]; @@ -73,21 +73,9 @@ public Object accept(Object... args) { public static void Create(IEventBus eventBus, String modid) { - createEnergyyCallBacks(); - - OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() { - @Override - public Object accept(Object... args) { - return ((RegistryObject)args[0]).get().getDefaultState(); - } - }; - - PlacementModifierCreationHelper.getHeightModifications = new ICallBack() { - @Override - public Object accept(Object... args) { - return HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom((int) args[0]), YOffset.aboveBottom((int) args[1])); - } - }; + createEnergyCallBacks(); + createOreGenStatics(); + createNetworkStatics(); TypeTransformer.ObjectToType = new ICallBack() { @Override @@ -100,20 +88,6 @@ public Object accept(Object... args) { } }; - Network.registerGlobalReceiver = new ICallbackVoid() { - @Override - public void accept(Object... args) { - - } - }; - - Network.clientSendPacket = new ICallbackVoid() { - @Override - public void accept(Object... args) { - - } - }; - DeferredRegister ITEM_REGISTRY = DeferredRegister.create(ForgeRegistries.ITEMS, modid); ITEM_REGISTRY.register(eventBus); @@ -244,7 +218,29 @@ public Object accept(Object... args) { Registry.initRegistry(RecipeTypeRegistryCallBack, RegistryTypes.RECIPE_TYPE, modid); } - private static void createEnergyyCallBacks() { + public static void CreateClient(String modid){ + ICallBack HandledScreensRegistryCallBack = new ICallBack() { + @Override + public Object accept(Object... args) { + + HandledScreens.Provider provider = new HandledScreens.Provider() { + @Override + public Screen create(ScreenHandler handler, PlayerInventory playerInventory, Text title) { + return ((IScreenHandledCreationFunction)args[2]).create((org.Vrglab.Screen.ScreenHandler) handler, playerInventory, title); + } + }; + HandledScreens.register((ScreenHandlerType)args[1], provider); + return null; + } + }; + Registry.initRegistry(HandledScreensRegistryCallBack, RegistryTypes.HANDLED_SCREEN, modid); + } + + public static void villagerTradeEventResolver(VillagerTradesEvent e, String modid) { + Registry.ForgeEventResolver(e, TradeRegistryEventCallback, RegistryTypes.TRADE, modid); + } + + private static void createEnergyCallBacks() { EnergyStorageUtils.createStorageInstance = new ICallBack() { @Override public Object accept(Object... args) { @@ -306,7 +302,7 @@ public Object accept(Object... args) { int maxReceive = 0; maxReceiveField.setAccessible(true); try { - maxReceive = (int) maxReceiveField.get(storage); + maxReceive = (int) maxReceiveField.get(storage); } catch (IllegalAccessException e) { } @@ -341,7 +337,7 @@ public Object accept(Object... args) { energyField = storage.getClass().getDeclaredField("energy"); } catch (NoSuchFieldException e) { } - energyField.setAccessible(true); + energyField.setAccessible(true); int energy = 0; try { energy = (int) energyField.get(storage); @@ -353,27 +349,36 @@ public Object accept(Object... args) { }; } - public static void CreateClient(String modid){ - ICallBack HandledScreensRegistryCallBack = new ICallBack() { + private static void createOreGenStatics() { + + OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() { @Override public Object accept(Object... args) { + return ((RegistryObject)args[0]).get().getDefaultState(); + } + }; - HandledScreens.Provider provider = new HandledScreens.Provider() { - @Override - public Screen create(ScreenHandler handler, PlayerInventory playerInventory, Text title) { - return ((IScreenHandledCreationFunction)args[2]).create((org.Vrglab.Screen.ScreenHandler) handler, playerInventory, title); - } - }; - HandledScreens.register((ScreenHandlerType)args[1], provider); - return null; + PlacementModifierCreationHelper.getHeightModifications = new ICallBack() { + @Override + public Object accept(Object... args) { + return HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom((int) args[0]), YOffset.aboveBottom((int) args[1])); } }; - Registry.initRegistry(HandledScreensRegistryCallBack, RegistryTypes.HANDLED_SCREEN, modid); } + private static void createNetworkStatics() { + Network.registerGlobalReceiver = new ICallbackVoid() { + @Override + public void accept(Object... args) { - public static void villagerTradeEventResolver(VillagerTradesEvent e, String modid) { - Registry.ForgeEventResolver(e, TradeRegistryEventCallback, RegistryTypes.TRADE, modid); - } + } + }; + + Network.clientSendPacket = new ICallbackVoid() { + @Override + public void accept(Object... args) { + } + }; + } } diff --git a/1.19.2/gradle.properties b/1.19.2/gradle.properties index 259f6cf..a677378 100644 --- a/1.19.2/gradle.properties +++ b/1.19.2/gradle.properties @@ -3,8 +3,7 @@ org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true # Mod properties -mod_version = 1.1.0-mc1.19.2 -loader_safe_version = 1.1.0 +loader_safe_version=1.2.0 maven_group = org.Vrglab archives_name = vrglabslib enabled_platforms = fabric,forge,quilt @@ -19,4 +18,4 @@ fabric_loader_version = 0.15.11 fabric_api_version = 0.77.0+1.19.2 forge_version = 1.19.2-43.3.13 quilt_loader_version = 0.26.0-beta.4 -quilted_fabric_api_version = 4.0.0-beta.30+0.76.0-1.19.2 +quilted_fabric_api_version = 4.0.0-beta.30+0.76.0-1.19.2 \ No newline at end of file diff --git a/1.19.2/quilt/build.gradle b/1.19.2/quilt/build.gradle index 8a86876..19369e0 100644 --- a/1.19.2/quilt/build.gradle +++ b/1.19.2/quilt/build.gradle @@ -34,6 +34,9 @@ dependencies { // Quilt Standard Libraries and QSL. modImplementation "org.quiltmc.quilted-fabric-api:quilted-fabric-api:$rootProject.quilted_fabric_api_version" + + + // Architectury API. This is optional, and you can comment it out if you don't need it. modImplementation("dev.architectury:architectury-fabric:$rootProject.architectury_api_version") { // We must not pull Fabric Loader and Fabric API from Architectury Fabric. diff --git a/1.20.4/build.gradle b/1.20.4/build.gradle index ad22503..3becfc1 100644 --- a/1.20.4/build.gradle +++ b/1.20.4/build.gradle @@ -10,7 +10,7 @@ architectury { allprojects { group = rootProject.maven_group - version = "$project.name-$rootProject.mod_version" + version = "$project.name-$rootProject.loader_safe_version-mc$rootProject.minecraft_version" } subprojects { diff --git a/1.20.4/common/src/main/java/org/TestSystem/TestMod.java b/1.20.4/common/src/main/java/org/TestSystem/TestMod.java new file mode 100644 index 0000000..44d5644 --- /dev/null +++ b/1.20.4/common/src/main/java/org/TestSystem/TestMod.java @@ -0,0 +1,24 @@ +package org.TestSystem; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import org.TestSystem.world.Blocks.TestBlocks; +import org.TestSystem.world.Items.CreativeModeTabs; +import org.TestSystem.world.Items.TestItems; +import org.Vrglab.Utils.Utils; + +import java.util.function.Supplier; + +public class TestMod { + public static final String MODID = "vrglabslib"; + + public static void init(){ + CreativeModeTabs.init(); + TestItems.init(); + TestBlocks.init(); + } + + public static Item.Settings basicItemSettings() { + return new Item.Settings(); + } +} diff --git a/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestBlockEntity.java b/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestBlockEntity.java new file mode 100644 index 0000000..7b4cc29 --- /dev/null +++ b/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestBlockEntity.java @@ -0,0 +1,15 @@ +package org.TestSystem.world.Blocks; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.math.BlockPos; +import org.Vrglab.Utils.Utils; + +public class TestBlockEntity extends BlockEntity { + public TestBlockEntity(BlockPos pos, BlockState state) { + super(Utils.convertToMcSafeType(TestBlocks.TEST_ENTITY_BLOCK_TYPE), pos, state); + } + + +} diff --git a/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestBlocks.java b/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestBlocks.java new file mode 100644 index 0000000..4e1a81d --- /dev/null +++ b/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestBlocks.java @@ -0,0 +1,32 @@ +package org.TestSystem.world.Blocks; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import org.TestSystem.TestMod; +import org.Vrglab.Modloader.Registration.Registry; + +import java.util.ArrayList; +import java.util.List; + +public class TestBlocks { + + public static Object TEST_BLOCK = Registry.RegisterBlock("test_block", TestMod.MODID, ()->new Block(AbstractBlock.Settings.create()), ()->TestMod.basicItemSettings()); + public static Object TEST_ITEMLESS_BLOCK = Registry.RegisterItemlessBlock("test_itemless_block", TestMod.MODID, ()->new Block(AbstractBlock.Settings.create())); + + public static Object TEST_POI_BLOCK = Registry.RegisterBlock("test_poi_block", TestMod.MODID, ()->new Block(AbstractBlock.Settings.create()), ()->TestMod.basicItemSettings()); + public static Object TEST_ENTITY_BLOCK = Registry.RegisterBlock("test_entity_block", TestMod.MODID, ()->new TestEntityBlockHolder(AbstractBlock.Settings.create()), ()->TestMod.basicItemSettings()); + + public static Object TEST_ENTITY_BLOCK_TYPE = Registry.RegisterBlockEntityType("test_entity_block_type", TestMod.MODID, TestBlockEntity::new, TEST_ENTITY_BLOCK); + + public static Object[] getAll(){ + List objectList = new ArrayList<>(); + objectList.add(TEST_BLOCK); + objectList.add(TEST_POI_BLOCK); + objectList.add(TEST_ENTITY_BLOCK); + return objectList.toArray(); + } + + public static void init() { + + } +} diff --git a/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestEntityBlockHolder.java b/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestEntityBlockHolder.java new file mode 100644 index 0000000..4cedf61 --- /dev/null +++ b/1.20.4/common/src/main/java/org/TestSystem/world/Blocks/TestEntityBlockHolder.java @@ -0,0 +1,33 @@ +package org.TestSystem.world.Blocks; + +import com.mojang.serialization.MapCodec; +import net.minecraft.block.BlockEntityProvider; +import net.minecraft.block.BlockRenderType; +import net.minecraft.block.BlockState; +import net.minecraft.block.BlockWithEntity; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; + +public class TestEntityBlockHolder extends BlockWithEntity implements BlockEntityProvider { + + protected TestEntityBlockHolder(Settings settings) { + super(settings); + } + + @Override + protected MapCodec getCodec() { + return null; + } + + @Nullable + @Override + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new TestBlockEntity(pos, state); + } + + @Override + public BlockRenderType getRenderType(BlockState state) { + return BlockRenderType.MODEL; + } +} diff --git a/1.20.4/common/src/main/java/org/TestSystem/world/Items/CreativeModeTabs.java b/1.20.4/common/src/main/java/org/TestSystem/world/Items/CreativeModeTabs.java new file mode 100644 index 0000000..39a4f9f --- /dev/null +++ b/1.20.4/common/src/main/java/org/TestSystem/world/Items/CreativeModeTabs.java @@ -0,0 +1,22 @@ +package org.TestSystem.world.Items; + +import org.TestSystem.TestMod; +import org.TestSystem.world.Blocks.TestBlocks; +import org.Vrglab.Helpers.CreativeModeTabBuilder; +import org.Vrglab.Modloader.Registration.Registry; + +import java.util.ArrayList; + +public class CreativeModeTabs { + + public static Object TEST_GROUP = Registry.RegisterCreativeModeTab("test_tab", TestMod.MODID, + CreativeModeTabBuilder.create() + .setDisplayText("test_tab") + .setIcon(TestItems.TEST_ITEM) + .setEntries(TestItems.getAll(), TestBlocks.getAll()) + .build() + ); + + public static void init(){ + } +} diff --git a/1.20.4/common/src/main/java/org/TestSystem/world/Items/TestItems.java b/1.20.4/common/src/main/java/org/TestSystem/world/Items/TestItems.java new file mode 100644 index 0000000..ac2427d --- /dev/null +++ b/1.20.4/common/src/main/java/org/TestSystem/world/Items/TestItems.java @@ -0,0 +1,25 @@ +package org.TestSystem.world.Items; + +import net.minecraft.item.Item; +import org.TestSystem.TestMod; +import org.Vrglab.Modloader.Registration.Registry; + +import java.util.ArrayList; +import java.util.List; + +public class TestItems { + + public static Object TEST_ITEM = Registry.RegisterItem("test_item", TestMod.MODID, ()->new Item(TestMod.basicItemSettings())); + + + public static Object[] getAll(){ + List objectList = new ArrayList<>(); + objectList.add(TEST_ITEM); + return objectList.toArray(); + } + + + public static void init(){ + + } +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/EnergyStorage.java b/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/EnergyStorage.java new file mode 100644 index 0000000..30d1321 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/EnergyStorage.java @@ -0,0 +1,221 @@ +package org.Vrglab.EnergySystem; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import org.Vrglab.Modloader.CreationHelpers.TypeTransformer; +import org.Vrglab.Modloader.Types.ICallBack; +import org.Vrglab.Modloader.Types.ICallBackVoidNoArg; +import org.Vrglab.Utils.VLModInfo; + +import static org.Vrglab.EnergySystem.EnergyStorageUtils.hasExternalStorage; + +public class EnergyStorage implements IEnergyContainer{ + + public static T createStorage(Class clazz, long capacity) { + try { + return clazz.getConstructor(long.class).newInstance(capacity); + } catch (Exception e) { + throw new RuntimeException("Failed to create EnergyStorage instance", e); + } + } + + public static T createStorage(Class clazz, long capacity, long maxTransfer) { + try { + return clazz.getConstructor(long.class, long.class).newInstance(capacity, maxTransfer); + } catch (Exception e) { + throw new RuntimeException("Failed to create EnergyStorage instance", e); + } + } + + public static T createStorage(Class clazz, long capacity, long maxTransfer, long maxExtract) { + try { + return clazz.getConstructor(long.class, long.class, long.class).newInstance(capacity, maxTransfer, maxExtract); + } catch (Exception e) { + throw new RuntimeException("Failed to create EnergyStorage instance", e); + } + } + + public static T createStorage(Class clazz, long capacity, long maxTransfer, long maxExtract, long energy) { + try { + return clazz.getConstructor(long.class, long.class, long.class, long.class).newInstance(capacity, maxTransfer, maxExtract, energy); + } catch (Exception e) { + throw new RuntimeException("Failed to create EnergyStorage instance", e); + } + } + + public static EnergyStorage createStorage(long capacity){ + return createStorage(EnergyStorage.class, capacity); + } + public static EnergyStorage createStorage(long capacity, long maxTransfer){ + return createStorage(EnergyStorage.class, capacity, maxTransfer); + } + + public static EnergyStorage createStorage(long capacity, long maxTransfer, long maxExtract) { + return createStorage(EnergyStorage.class, capacity, maxTransfer, maxExtract); + } + + public static EnergyStorage createStorage(long capacity, long maxTransfer, long maxExtract, long energy){ + return createStorage(EnergyStorage.class, capacity, maxTransfer, maxExtract, energy); + } + + public static IEnergyContainer getStorageInWorld(World world, BlockPos blockPos, Direction facing){ + IEnergyContainer storage = null; + BlockEntity entity = world.getBlockEntity(blockPos.offset(facing)); + if(containEnergyStorage(entity)) { + try { + if(entity != null && entity instanceof IEnergySupplier) { + storage = ((IEnergySupplier)entity).getEnergyStorage(); + } else if((boolean)hasExternalStorage.accept(entity)){ + if (EnergyStorageUtils.getCachedContainer(blockPos.offset(facing)) != null) { + try{ + storage = EnergyStorageUtils.getCachedContainer(blockPos.offset(facing)); + if(((BlockEntity)((EnergyStorage)storage).blockEntity).isRemoved()) { + EnergyStorageUtils.removeFromCache(blockPos.offset(facing)); + throw new RuntimeException("Accessed Storage is removed"); + } + } catch (Throwable t) { + storage = (EnergyStorage)EnergyStorageUtils.wrapExternalStorage.accept(world, blockPos, facing, entity); + EnergyStorageUtils.cacheEnergyContainer(blockPos.offset(facing), storage); + } + } else { + storage = (EnergyStorage)EnergyStorageUtils.wrapExternalStorage.accept(world, blockPos, facing, entity); + EnergyStorageUtils.cacheEnergyContainer(blockPos.offset(facing), storage); + } + } + + } catch (Throwable t) { + + } + } + return storage; + } + + public static boolean containEnergyStorage(World world, BlockPos blockPos){ + BlockEntity entity = world.getBlockEntity(blockPos); + return containEnergyStorage(entity); + } + + public static boolean containEnergyStorage(BlockEntity entity){ + if(entity != null && entity instanceof IEnergySupplier || (boolean)hasExternalStorage.accept(entity)) { + try { + return true; + } catch (Throwable t) { + + } + } + return false; + } + + + protected long energy; + protected long capacity; + protected long maxReceive; + protected long maxExtract; + public ICallBackVoidNoArg makeDirty; + protected Object actualEnergyInstance, blockEntity; + + public EnergyStorage(long capacity) { + this(capacity, capacity, capacity, 0); + } + + public EnergyStorage(long capacity, long maxTransfer) { + this(capacity, maxTransfer, maxTransfer, 0); + } + + public EnergyStorage(long capacity, long maxReceive, long maxExtract) { + this(capacity, maxReceive, maxExtract, 0); + } + + public EnergyStorage(long capacity, long maxReceive, long maxExtract, long energy) { + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + this.energy = Math.max(0 , Math.min(capacity, energy)); + this.actualEnergyInstance = EnergyStorageUtils.createStorageInstance.accept(capacity, maxReceive, maxExtract, energy, this, blockEntity); + } + + public EnergyStorage(Object instance, long capacity, long maxReceive, long maxExtract, long energy) { + this(capacity, maxReceive, maxExtract, energy); + this.actualEnergyInstance = instance; + } + + @Override + public long receiveEnergy(long maxReceive, boolean simulate) { + energy += Long.valueOf(EnergyStorageUtils.receiveEnergyInstance.accept(actualEnergyInstance, maxReceive, simulate).toString()); + return energy; + } + + @Override + public long extractEnergy(long maxExtract, boolean simulate) { + energy -= Long.valueOf(EnergyStorageUtils.extractEnergyInstance.accept(actualEnergyInstance, maxExtract, simulate).toString()); + return energy; + } + + /** + * Adds energy to the storage. Returns quantity of energy that was accepted. + * + * @param maxReceive Maximum amount of energy to be inserted. + * @return Amount of energy that was accepted by the storage. + */ + @Override + public long receiveEnergy(long maxReceive) { + return receiveEnergy(maxReceive, false); + } + + /** + * Removes energy from the storage. Returns quantity of energy that was removed. + * + * @param maxExtract Maximum amount of energy to be extracted. + * @return Amount of energy that was (or would have been) extracted from the storage. + */ + @Override + public long extractEnergy(long maxExtract) { + return extractEnergy(maxExtract, false); + } + + /** + * Set's the energy Storages block entity type + *

DO NOT USE {@link TypeTransformer#ObjectToType} ON THE GIVEN OBJECT

+ * @param blockEntity the un-transformed object of the block entity + * @return The Energy storage reference + */ + public EnergyStorage setBlockEntityType(Object blockEntity) { + this.blockEntity = TypeTransformer.ObjectToType.accept(blockEntity); + return this; + } + + public EnergyStorage setMakeDirtyFunction(ICallBackVoidNoArg makeDirty) { + this.makeDirty = makeDirty; + return this; + } + + @Override + public long getEnergyStored() { + return energy; + } + + @Override + public long getMaxEnergyStored() { + return capacity; + } + + @Override + public boolean canExtract() { + return this.maxExtract > 0; + } + + @Override + public boolean canReceive() { + return this.maxReceive > 0; + } + + public boolean isEmpty() { + return (energy == 0); + } + + public boolean atMaxCapacity(){ + return (energy == capacity); + } +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/EnergyStorageUtils.java b/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/EnergyStorageUtils.java new file mode 100644 index 0000000..271f06c --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/EnergyStorageUtils.java @@ -0,0 +1,56 @@ +package org.Vrglab.EnergySystem; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import org.Vrglab.Modloader.Types.ICallBack; +import org.Vrglab.Utils.VLModInfo; + +import java.util.HashMap; +import java.util.Map; + +public class EnergyStorageUtils { + public static ICallBack createStorageInstance, extractEnergyInstance, receiveEnergyInstance, wrapExternalStorage, hasExternalStorage; + private static Map CACHED_CONTAINER = new HashMap<>(); + + public static T getCachedContainer(BlockPos pos){ + return (T) CACHED_CONTAINER.get(pos); + } + + public static void cacheEnergyContainer(BlockPos pos, T container){ + CACHED_CONTAINER.put(pos, container); + } + + public static void removeFromCache(BlockPos pos) { + CACHED_CONTAINER.remove(pos); + } + + + public static boolean pushEnergyTo(BlockEntity self, World world, BlockPos blockPos, Direction dir, long amnt) { + if(EnergyStorage.containEnergyStorage(world, blockPos.offset(dir))) { + EnergyStorage storage = (EnergyStorage)EnergyStorage.getStorageInWorld(world, blockPos, dir); + EnergyStorage self_storage = ((IEnergySupplier)self).getEnergyStorage(); + if(storage != null && (!self_storage.isEmpty() && !storage.atMaxCapacity())) { + storage.receiveEnergy(amnt); + self_storage.extractEnergy(amnt); + return true; + } + } + return false; + } + + public static boolean pullEnergyFrom(BlockEntity self, World world, BlockPos blockPos, Direction dir, long amnt) { + if(EnergyStorage.containEnergyStorage(world, blockPos.offset(dir))) { + EnergyStorage storage = (EnergyStorage)EnergyStorage.getStorageInWorld(world, blockPos, dir); + EnergyStorage self_storage = ((IEnergySupplier)self).getEnergyStorage(); + if(storage != null && (!self_storage.atMaxCapacity() && !storage.isEmpty())) { + storage.extractEnergy(amnt); + self_storage.receiveEnergy(amnt); + return true; + } + } + return false; + } + +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/IEnergyContainer.java b/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/IEnergyContainer.java new file mode 100644 index 0000000..4cb6cd0 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/IEnergyContainer.java @@ -0,0 +1,67 @@ +package org.Vrglab.EnergySystem; + +import net.minecraft.nbt.NbtType; + +public interface IEnergyContainer { + /** + * Adds energy to the storage. Returns quantity of energy that was accepted. + * + * @param maxReceive + * Maximum amount of energy to be inserted. + * @param simulate + * If TRUE, the insertion will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) accepted by the storage. + */ + long receiveEnergy(long maxReceive, boolean simulate); + + /** + * Removes energy from the storage. Returns quantity of energy that was removed. + * + * @param maxExtract + * Maximum amount of energy to be extracted. + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) extracted from the storage. + */ + long extractEnergy(long maxExtract, boolean simulate); + + /** + * Adds energy to the storage. Returns quantity of energy that was accepted. + * + * @param maxReceive + * Maximum amount of energy to be inserted. + * @return Amount of energy that was accepted by the storage. + */ + long receiveEnergy(long maxReceive); + + /** + * Removes energy from the storage. Returns quantity of energy that was removed. + * + * @param maxExtract + * Maximum amount of energy to be extracted. + * @return Amount of energy that was (or would have been) extracted from the storage. + */ + long extractEnergy(long maxExtract); + + /** + * Returns the amount of energy currently stored. + */ + long getEnergyStored(); + + /** + * Returns the maximum amount of energy that can be stored. + */ + long getMaxEnergyStored(); + + /** + * Returns if this storage can have energy extracted. + * If this is false, then any calls to extractEnergy will return 0. + */ + boolean canExtract(); + + /** + * Used to determine if this storage can receive energy. + * If this is false, then any calls to receiveEnergy will return 0. + */ + boolean canReceive(); +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/IEnergySupplier.java b/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/IEnergySupplier.java new file mode 100644 index 0000000..ec3bca2 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/EnergySystem/IEnergySupplier.java @@ -0,0 +1,5 @@ +package org.Vrglab.EnergySystem; + +public interface IEnergySupplier { + T getEnergyStorage(); +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Helpers/CreativeModeTabBuilder.java b/1.20.4/common/src/main/java/org/Vrglab/Helpers/CreativeModeTabBuilder.java new file mode 100644 index 0000000..8db6234 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Helpers/CreativeModeTabBuilder.java @@ -0,0 +1,44 @@ +package org.Vrglab.Helpers; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import org.Vrglab.Utils.Utils; + +public class CreativeModeTabBuilder { + private ItemGroup.Builder builder; + + public static CreativeModeTabBuilder create(){ + var instance = new CreativeModeTabBuilder(); + instance.builder = ItemGroup.create(null, -1); + return instance; + } + + public CreativeModeTabBuilder setDisplayText(String txt) { + builder.displayName(Text.translatable(txt)); + return this; + } + + public CreativeModeTabBuilder setIcon(Object item) { + builder.icon(()->new ItemStack((Item)Utils.convertToMcSafeType(item))); + return this; + } + + public CreativeModeTabBuilder setEntries(Object[] itementeries, Object[] blockenteries) { + builder.entries(((displayContext, entries1) -> { + for (var data: itementeries) { + entries1.add((Item)Utils.convertToMcSafeType(data)); + } + for (var data: blockenteries) { + entries1.add((Block)Utils.convertToMcSafeType(data)); + } + })); + return this; + } + + public ItemGroup build(){ + return this.builder.build(); + } +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Helpers/ImplementedInventory.java b/1.20.4/common/src/main/java/org/Vrglab/Helpers/ImplementedInventory.java new file mode 100644 index 0000000..bdd12a6 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Helpers/ImplementedInventory.java @@ -0,0 +1,209 @@ +package org.Vrglab.Helpers; + + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.Inventories; +import net.minecraft.inventory.SidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.math.Direction; +import org.jetbrains.annotations.Nullable; + +/** + * A simple {@code SidedInventory} implementation with only default methods + an item list getter. + * + *

Reading and writing to tags

+ * Use {@link Inventories#writeNbt(net.minecraft.nbt.NbtCompound, DefaultedList)} and {@link Inventories#readNbt(net.minecraft.nbt.NbtCompound, DefaultedList)} + * on {@linkplain #getItems() the item list}. + * + * License: CC0 + * @author Juuz + */ +@FunctionalInterface +public interface ImplementedInventory extends SidedInventory { + /** + * Gets the item list of this inventory. + * Must return the same instance every time it's called. + * + * @return the item list + */ + DefaultedList getItems(); + + /** + * Creates an inventory from the item list. + * + * @param items the item list + * @return a new inventory + */ + static ImplementedInventory of(DefaultedList items) { + return () -> items; + } + + /** + * Creates a new inventory with the size. + * + * @param size the inventory size + * @return a new inventory + */ + static ImplementedInventory ofSize(int size) { + return of(DefaultedList.ofSize(size, ItemStack.EMPTY)); + } + + // SidedInventory + + /** + * Gets the available slots to automation on the side. + * + *

The default implementation returns an array of all slots. + * + * @param side the side + * @return the available slots + */ + @Override + default int[] getAvailableSlots(Direction side) { + int[] result = new int[getItems().size()]; + for (int i = 0; i < result.length; i++) { + result[i] = i; + } + + return result; + } + + /** + * Returns true if the stack can be inserted in the slot at the side. + * + *

The default implementation returns true. + * + * @param slot the slot + * @param stack the stack + * @param side the side + * @return true if the stack can be inserted + */ + @Override + default boolean canInsert(int slot, ItemStack stack, @Nullable Direction side) { + return true; + } + + /** + * Returns true if the stack can be extracted from the slot at the side. + * + *

The default implementation returns true. + * + * @param slot the slot + * @param stack the stack + * @param side the side + * @return true if the stack can be extracted + */ + @Override + default boolean canExtract(int slot, ItemStack stack, Direction side) { + return true; + } + + // Inventory + + /** + * Returns the inventory size. + * + *

The default implementation returns the size of {@link #getItems()}. + * + * @return the inventory size + */ + @Override + default int size() { + return getItems().size(); + } + + /** + * @return true if this inventory has only empty stacks, false otherwise + */ + @Override + default boolean isEmpty() { + for (int i = 0; i < size(); i++) { + ItemStack stack = getStack(i); + if (!stack.isEmpty()) { + return false; + } + } + + return true; + } + + /** + * Gets the item in the slot. + * + * @param slot the slot + * @return the item in the slot + */ + @Override + default ItemStack getStack(int slot) { + return getItems().get(slot); + } + + /** + * Takes a stack of the size from the slot. + * + *

(default implementation) If there are less items in the slot than what are requested, + * takes all items in that slot. + * + * @param slot the slot + * @param count the item count + * @return a stack + */ + @Override + default ItemStack removeStack(int slot, int count) { + ItemStack result = Inventories.splitStack(getItems(), slot, count); + if (!result.isEmpty()) { + markDirty(); + } + + return result; + } + + /** + * Removes the current stack in the {@code slot} and returns it. + * + *

The default implementation uses {@link Inventories#removeStack(java.util.List, int)} + * + * @param slot the slot + * @return the removed stack + */ + @Override + default ItemStack removeStack(int slot) { + return Inventories.removeStack(getItems(), slot); + } + + /** + * Replaces the current stack in the {@code slot} with the provided stack. + * + *

If the stack is too big for this inventory ({@link net.minecraft.inventory.Inventory#getMaxCountPerStack()}), + * it gets resized to this inventory's maximum amount. + * + * @param slot the slot + * @param stack the stack + */ + @Override + default void setStack(int slot, ItemStack stack) { + getItems().set(slot, stack); + if (stack.getCount() > getMaxCountPerStack()) { + stack.setCount(getMaxCountPerStack()); + } + } + + /** + * Clears {@linkplain #getItems() the item list}}. + */ + @Override + default void clear() { + getItems().clear(); + } + + @Override + default void markDirty() { + // Override if you want behavior. + } + + @Override + default boolean canPlayerUse(PlayerEntity player) { + return true; + } +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/OreGenFeatCreationHelper.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/OreGenFeatCreationHelper.java index b3446d8..5fd2977 100644 --- a/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/OreGenFeatCreationHelper.java +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/OreGenFeatCreationHelper.java @@ -1,8 +1,7 @@ package org.Vrglab.Modloader.CreationHelpers; import net.minecraft.block.BlockState; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.structure.rule.RuleTest; +import net.minecraft.block.RedstoneBlock; import net.minecraft.structure.rule.TagMatchRuleTest; import net.minecraft.world.gen.feature.OreFeatureConfig; import org.Vrglab.Modloader.Types.ICallBack; diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/PlacementModifierCreationHelper.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/PlacementModifierCreationHelper.java index be48523..1b44a10 100644 --- a/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/PlacementModifierCreationHelper.java +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/PlacementModifierCreationHelper.java @@ -2,7 +2,7 @@ import net.minecraft.world.gen.placementmodifier.*; import org.Vrglab.Modloader.Types.ICallBack; -import org.Vrglab.Utils.Modinfo; +import org.Vrglab.Utils.VLModInfo; import java.util.ArrayList; import java.util.List; @@ -31,7 +31,7 @@ public PlacementModifierCreationHelper HeightRangePlacement(int lowest, int high public PlacementModifierCreationHelper CountModifier(int count) { if(targets.get(0)!= null && targets.get(0).getClass() == RarityFilterPlacementModifier.class) { - Modinfo.LOGGER.error("Cant add Count modifier when Rarity modifier is already added"); + VLModInfo.LOGGER.error("Cant add Count modifier when Rarity modifier is already added"); return this; } @@ -41,7 +41,7 @@ public PlacementModifierCreationHelper CountModifier(int count) { public PlacementModifierCreationHelper RarityModifier(int chance) { if(targets.get(0)!= null && targets.get(0).getClass() == CountPlacementModifier.class) { - Modinfo.LOGGER.error("Cant add Rarity modifier when Count modifier is already added"); + VLModInfo.LOGGER.error("Cant add Rarity modifier when Count modifier is already added"); return this; } diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/TypeTransformer.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/TypeTransformer.java new file mode 100644 index 0000000..9b43e3e --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/CreationHelpers/TypeTransformer.java @@ -0,0 +1,10 @@ +package org.Vrglab.Modloader.CreationHelpers; + +import org.Vrglab.Modloader.Types.ICallBack; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public class TypeTransformer { + public static ICallBack ObjectToType; + +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/Registration/Registry.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/Registration/Registry.java index a8da50d..3915ed2 100644 --- a/1.20.4/common/src/main/java/org/Vrglab/Modloader/Registration/Registry.java +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/Registration/Registry.java @@ -1,23 +1,39 @@ package org.Vrglab.Modloader.Registration; import net.minecraft.block.Block; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.RecipeType; import net.minecraft.sound.SoundEvent; import net.minecraft.village.TradeOffer; import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.OreFeatureConfig; +import org.Vrglab.Modloader.Types.IBlockEntityLoaderFunction; import org.Vrglab.Modloader.Types.ICallBack; +import org.Vrglab.Modloader.Types.IScreenHandledCreationFunction; +import org.Vrglab.Modloader.Types.IScreenHandlerTypeCreationFunction; +import org.Vrglab.Modloader.enumTypes.IRegistryType; import org.Vrglab.Modloader.enumTypes.RegistryTypes; import org.Vrglab.Modloader.enumTypes.VinillaBiomeTypes; -import org.Vrglab.Utils.Modinfo; +import org.Vrglab.Screen.ScreenHandler; +import org.Vrglab.Utils.VLModInfo; import java.util.*; import java.util.function.Supplier; +/** + * Class to handle Data registration Across Modloaders and various MC version + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ public class Registry { private static class UnregisteredData{ - public UnregisteredData( RegistryTypes registry_type, Object... args) { + public UnregisteredData(UUID registry_type, Object... args) { this.registry_type = registry_type; this.args = new ArrayList<>(); for (Object argdata: args) { @@ -26,29 +42,30 @@ public UnregisteredData( RegistryTypes registry_type, Object... args) { } public List args; - public RegistryTypes registry_type; + public UUID registry_type; public boolean resolved; public Object Obj = null; } - private static Map> open_registeries = new HashMap<>(); + private static Map> open_registeries = new HashMap<>(); private static Map> ready_to_load_registeries = new HashMap<>(); /** * Initializes a Modloader's Registry to be used for loading of objects + *
(Using this function is extremely not recommended, unless you trully know what you are really doing, instead use {@link #initRegistry(ICallBack, IRegistryType, String)})
* @param _registery The registry code * @param _currentRegistryTypes the type of registry * @param modid the Mod ID * * @author Arad Bozorgmehr - * @since 1.0.0 + * @since 1.1.0 */ - public static void initRegistry(ICallBack _registery, RegistryTypes _currentRegistryTypes, String modid){ + public static void initRegistry(ICallBack _registery, UUID _currentRegistryTypes, String modid){ if(open_registeries.containsKey(modid)){ open_registeries.get(modid).put(_currentRegistryTypes, _registery); } else{ - open_registeries.put(modid, new HashMap<>()); + open_registeries.put(modid, new HashMap()); open_registeries.get(modid).put(_currentRegistryTypes, _registery); } if(ready_to_load_registeries.containsKey(modid) && ready_to_load_registeries.get(modid).size() > 0) { @@ -61,7 +78,45 @@ public static void initRegistry(ICallBack _registery, RegistryTypes _currentRegi } } - public static void ForgeLikeEventResolver(Object eventData, ICallBack resolver, RegistryTypes ResolveTypeOf, String modid){ + /** + * Initializes a Modloader's Registry to be used for loading of objects + * @param _registery The registry code + * @param _currentRegistryTypes the type of registry + * @param modid the Mod ID + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ + public static void initRegistry(ICallBack _registery, IRegistryType _currentRegistryTypes, String modid){ + initRegistry(_registery, _currentRegistryTypes.getTypeId(), modid); + } + + /** + * Creates an Event resolver for forge + * @param eventData The event data + * @param resolver The resolver code + * @param ResolveTypeOf The type of Object this event resolves + * @param modid The Mod ID + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ + public static void ForgeEventResolver(Object eventData, ICallBack resolver, IRegistryType ResolveTypeOf, String modid){ + ForgeEventResolver(eventData, resolver, ResolveTypeOf.getTypeId(), modid); + } + + /** + * Creates an Event resolver for forge + *
(Using this function is extremely not recommended, unless you truly know what you are really doing, instead use {@link #ForgeEventResolver(Object, ICallBack, IRegistryType, String)})
+ * @param eventData The event data + * @param resolver The resolver code + * @param ResolveTypeOf The type of Object this event resolves + * @param modid The Mod ID + * + * @author Arad Bozorgmehr + * @since 1.1.0 + */ + public static void ForgeEventResolver(Object eventData, ICallBack resolver, UUID ResolveTypeOf, String modid){ if(ready_to_load_registeries.containsKey(modid) && ready_to_load_registeries.get(modid).size() > 0) { for (UnregisteredData data: ready_to_load_registeries.get(modid)) { if(!data.resolved && data.registry_type == ResolveTypeOf){ @@ -71,23 +126,133 @@ public static void ForgeLikeEventResolver(Object eventData, ICallBack resolver, } } - + /** + * Register's a new Item for MC. Based on what Mod loader we are on, We either receive the Object itself or a + * RegistryObject of the Object, to safely use the Object in other pieces of + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} + * @param name The Item name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param aNew The supplier which gives us the Item Instance + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ public static Object RegisterItem(String name, String Modid, Supplier aNew) { return SimpleRegister(RegistryTypes.ITEM, Modid, name, aNew); } - public static Object RegisterBlock(String name, String Modid, Supplier aNew, Item.Settings settings) { + /** + * Register's a new Block for MC. Based on what Mod loader we are on, We either receive the Object itself or a + * RegistryObject of the Object, to safely use the Object in other pieces of + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} + * @param name The Block name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param aNew The supplier which gives us the Block Instance + * @param settings The {@link net.minecraft.item.Item.Settings} to use for the Blocks inventory Item + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ + public static Object RegisterBlock(String name, String Modid, Supplier aNew, Supplier settings) { return SimpleRegister(RegistryTypes.BLOCK, Modid, name, aNew, settings); } + /** + * Register's a new Block Entity for MC. Based on what Mod loader we are on, We either receive the Object itself or a + * RegistryObject of the Object, to safely use the Object in other pieces of + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} + * @param name The Block Entity name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param aNew The ::new which gives us the Block Entity Instance + * @param block The block to attach the entity to (NOT converted using {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)}) + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ + public static Object RegisterBlockEntityType(String name, String Modid, IBlockEntityLoaderFunction aNew, Object block) { + return SimpleRegister(RegistryTypes.BLOCK_ENTITY_TYPE, Modid, name, aNew, block); + } + + /** + * Register's a new Screen Handler for MC. + * @param name The Screen Handler name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param aNew The ::new which gives us the Screen Handler Instance + * @return The registered data (The return value of this Function CAN NOT be converted using {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)}) + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ + public static Object RegisterScreenHandlerType(String name, String Modid, IScreenHandlerTypeCreationFunction aNew) { + return SimpleRegister(RegistryTypes.SCREEN_HANDLER_TYPE, Modid, name, aNew); + } + + /** + * Register's a new Handled Screen for MC. + *
You can call this function within any init() functions
+ * @param name The name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param aNew The ::new which gives us the Handled Screen Instance + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ + public static > void RegisterHandledScreen(String name, String Modid, Object handlerType, IScreenHandledCreationFunction aNew) { + SimpleRegister(RegistryTypes.HANDLED_SCREEN, Modid, name, handlerType, aNew); + } + + /** + * Register's a new Itemless Block for MC. Based on what Mod loader we are on, We either receive the Object itself or a + * RegistryObject of the Object, to safely use the Object in other pieces of + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} + * @param name The Block name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param aNew The supplier which gives us the Block Instance + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ public static Object RegisterItemlessBlock(String name, String Modid, Supplier aNew) { return SimpleRegister(RegistryTypes.ITEMLESS_BLOCK, Modid, name, aNew); } + /** + * Register's a new POI (Point of Interest) for MC. Based on what Mod loader we are on, We either receive the Object itself or a + * RegistryObject of the Object, to safely use the Object in other pieces of + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} + * @param name The POI name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param block The block to attach the entity to (NOT converted using {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)}) + * @param tickcount The POI tick count + * @param searchdistance The Search distance for the POI + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ public static Object RegisterPOI(String name, String Modid, Object block, int tickcount, int searchdistance) { return SimpleRegister(RegistryTypes.POI, Modid, name, tickcount, searchdistance, block); } + /** + * Register's a new Villager Profession for MC. Based on what Mod loader we are on, We either receive the Object itself or a + * RegistryObject of the Object, to safely use the Object in other pieces of + * code use {@link org.Vrglab.Utils.Utils#convertToMcSafeType(Object)} + * @param name The Villager Profession name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param aNew The POI name (aka ID) + * @param itemImmutableSet Gatherable Items + * @param blockImmutableSet Secondary Job Site's + * @param sound Work Sound + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ public static Object RegisterProfession(String name, String Modid, String aNew, Item[] itemImmutableSet, Block[] blockImmutableSet, SoundEvent sound) { return SimpleRegister(RegistryTypes.PROFESSION, Modid, name, aNew, itemImmutableSet, blockImmutableSet, sound); } @@ -105,12 +270,82 @@ public static Object RegisterPlacedFeature(String name, String Modid, Object con } public static void AddBiomeModification(String name, String Modid, VinillaBiomeTypes biomeTypes, GenerationStep.Feature gen_step, Object Placed_ore) { - SimpleRegister(RegistryTypes.BIOME_MODIFICATIONS, Modid, name, biomeTypes, gen_step, Placed_ore); } - public static Object SimpleRegister(RegistryTypes type, String Modid, Object... args){ - Modinfo.LOGGER.info("Registering "+type.toString().toLowerCase() +" " + args[0] + " for " + Modid); + /** + * Register's a new Recipe Serializer + * + * @param name The Villager Profession name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param serializer_instance The instance to the Recipe Serializer class + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.1.0 + */ + public static Object RegisterRecipeSerializer(String name, String Modid, RecipeSerializer serializer_instance) { + return SimpleRegister(RegistryTypes.RECIPE_SERIALIZER, Modid, name, serializer_instance); + } + + /** + * Register's a new Recipe Type + * + * @param name The Villager Profession name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param type_instance The instance to the Recipe Type class + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.1.0 + */ + public static Object RegisterRecipeType(String name, String Modid, RecipeType type_instance) { + return SimpleRegister(RegistryTypes.RECIPE_TYPE, Modid, name, type_instance); + } + + + /** + * Register's a new Creative mode tab + * + * @param name The tab name (aka ID) + * @param Modid The Mod Id of the Registerar + * @param tab The instance to the tab + * + * @author Arad Bozorgmehr + * @since 1.0.0-mc1.20.4 + */ + public static Object RegisterCreativeModeTab(String name, String Modid, T tab) { + return SimpleRegister(RegistryTypes.CREATIVE_MODE_TAB, Modid, name, tab); + } + + /** + * Sends data to the modloader for something to be registered for MC + * @param type The type to use for registeration + * @param Modid The Mod Id of the Registerar + * @param args All the arguments needed to register the Object (On the callback end of this interaction the arguments are fed in the EXACT same order) + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.0.0 + */ + public static Object SimpleRegister(IRegistryType type, String Modid, Object... args){ + return SimpleRegister(type.getTypeId(), Modid, args); + } + + + /** + * Sends data to the modloader for something to be registered for MC + *
(Using this function is extremely not recommended, unless you trully know what you are really doing, instead use {@link #SimpleRegister(IRegistryType, String, Object...)})
+ * @param type The type to use for registeration + * @param Modid The Mod Id of the Registerar + * @param args All the arguments needed to register the Object (On the callback end of this interaction the arguments are fed in the EXACT same order) + * @return The registered data + * + * @author Arad Bozorgmehr + * @since 1.1.0 + */ + public static Object SimpleRegister(UUID type, String Modid, Object... args){ + VLModInfo.LOGGER.info("Registering "+String.valueOf(type).toLowerCase() +" " + args[0] + " for " + Modid); if(open_registeries.containsKey(Modid) && open_registeries.get(Modid).containsKey(type)) return open_registeries.get(Modid).get(type).accept(args); else { diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IBlockEntityLoaderFunction.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IBlockEntityLoaderFunction.java new file mode 100644 index 0000000..23d14e6 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IBlockEntityLoaderFunction.java @@ -0,0 +1,10 @@ +package org.Vrglab.Modloader.Types; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; + +@FunctionalInterface +public interface IBlockEntityLoaderFunction { + T create(BlockPos blockPos, BlockState blockState); +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IScreenHandledCreationFunction.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IScreenHandledCreationFunction.java new file mode 100644 index 0000000..a3b448d --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IScreenHandledCreationFunction.java @@ -0,0 +1,13 @@ +package org.Vrglab.Modloader.Types; + +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.text.Text; +import org.Vrglab.Screen.ScreenHandler; + +@FunctionalInterface +public interface IScreenHandledCreationFunction> { + + U create(T handler, PlayerInventory playerInventory, Text title); +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IScreenHandlerTypeCreationFunction.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IScreenHandlerTypeCreationFunction.java new file mode 100644 index 0000000..82c901b --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/Types/IScreenHandlerTypeCreationFunction.java @@ -0,0 +1,9 @@ +package org.Vrglab.Modloader.Types; + +import net.minecraft.entity.player.PlayerInventory; +import org.Vrglab.Screen.ScreenHandler; + +@FunctionalInterface +public interface IScreenHandlerTypeCreationFunction { + T create(int syncId, PlayerInventory playerInventory); +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/enumTypes/IRegistryType.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/enumTypes/IRegistryType.java new file mode 100644 index 0000000..7aa1498 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/enumTypes/IRegistryType.java @@ -0,0 +1,7 @@ +package org.Vrglab.Modloader.enumTypes; + +import java.util.UUID; + +public interface IRegistryType { + UUID getTypeId(); +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryTypes.java b/1.20.4/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryTypes.java index 0da2792..7a1a06f 100644 --- a/1.20.4/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryTypes.java +++ b/1.20.4/common/src/main/java/org/Vrglab/Modloader/enumTypes/RegistryTypes.java @@ -1,20 +1,39 @@ package org.Vrglab.Modloader.enumTypes; -public enum RegistryTypes { - ITEM, - BLOCK, - ITEMLESS_BLOCK, - ENTITY_BLOCK, - MENU, - RECIPE, - ENTITY, - TAG, - BIOM, - STRUCTURE, - POI, - PROFESSION, - TRADE, - CONFIGURED_FEAT_ORE, - PLACED_FEAT, - BIOME_MODIFICATIONS +import java.util.UUID; + +public enum RegistryTypes implements IRegistryType { + ITEM(UUID.randomUUID()), + BLOCK(UUID.randomUUID()), + ITEMLESS_BLOCK(UUID.randomUUID()), + ENTITY_BLOCK(UUID.randomUUID()), + MENU(UUID.randomUUID()), + RECIPE(UUID.randomUUID()), + ENTITY(UUID.randomUUID()), + TAG(UUID.randomUUID()), + BIOM(UUID.randomUUID()), + STRUCTURE(UUID.randomUUID()), + POI(UUID.randomUUID()), + PROFESSION(UUID.randomUUID()), + TRADE(UUID.randomUUID()), + CONFIGURED_FEAT_ORE(UUID.randomUUID()), + PLACED_FEAT(UUID.randomUUID()), + BIOME_MODIFICATIONS(UUID.randomUUID()), + BLOCK_ENTITY_TYPE(UUID.randomUUID()), + SCREEN_HANDLER_TYPE(UUID.randomUUID()), + HANDLED_SCREEN(UUID.randomUUID()), + RECIPE_SERIALIZER(UUID.randomUUID()), + RECIPE_TYPE(UUID.randomUUID()), + CREATIVE_MODE_TAB(UUID.randomUUID()) + ; + + + private final UUID getTypeId; + RegistryTypes(UUID type) { + getTypeId = type; + } + + public UUID getTypeId() { + return getTypeId; + } } diff --git a/1.20.4/common/src/main/java/org/Vrglab/Networking/Network.java b/1.20.4/common/src/main/java/org/Vrglab/Networking/Network.java new file mode 100644 index 0000000..9e9c5ae --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Networking/Network.java @@ -0,0 +1,31 @@ +package org.Vrglab.Networking; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; +import org.Vrglab.Modloader.Types.ICallbackVoid; +import org.Vrglab.Networking.Packet.BaseC2SPacket; +import org.Vrglab.Utils.VLModInfo; + + + +public class Network { + public static ICallbackVoid registerGlobalReceiver; + public static ICallbackVoid clientSendPacket; + + public static void RegisterC2SGlobal(BaseC2SPacket packet_receiver){ + VLModInfo.LOGGER.info("Registering C2S: " + packet_receiver.getKey()); + registerGlobalReceiver.accept(packet_receiver.getKey(), new ICallbackVoid() { + @Override + public void accept(Object... args) { + packet_receiver.receive((MinecraftServer)args[0], (ServerPlayerEntity)args[1], (ServerPlayNetworkHandler)args[2], (PacketByteBuf)args[3], args[4]); + } + }); + } + + public static void SendC2SPacket(Identifier id, PacketByteBuf buff) { + clientSendPacket.accept(id, buff); + } +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Networking/Packet/BaseC2SPacket.java b/1.20.4/common/src/main/java/org/Vrglab/Networking/Packet/BaseC2SPacket.java new file mode 100644 index 0000000..4265f43 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Networking/Packet/BaseC2SPacket.java @@ -0,0 +1,18 @@ +package org.Vrglab.Networking.Packet; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public abstract class BaseC2SPacket { + + public void receive(MinecraftServer server, ServerPlayerEntity player, ServerPlayNetworkHandler handler, PacketByteBuf buf, Object responseSender) { + ExecuteOnServer(server, player, handler, buf, responseSender); + } + + protected abstract void ExecuteOnServer(MinecraftServer server, ServerPlayerEntity player, ServerPlayNetworkHandler handler, PacketByteBuf buf, Object responseSender); + + public abstract Identifier getKey(); +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Screen/ScreenHandler.java b/1.20.4/common/src/main/java/org/Vrglab/Screen/ScreenHandler.java new file mode 100644 index 0000000..05444d5 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Screen/ScreenHandler.java @@ -0,0 +1,22 @@ +package org.Vrglab.Screen; + +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.slot.Slot; +import org.jetbrains.annotations.Nullable; + +public abstract class ScreenHandler extends net.minecraft.screen.ScreenHandler { + protected ScreenHandler(@Nullable ScreenHandlerType type, int syncId) { + super(type, syncId); + } + + @Override + public boolean insertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast) { + return super.insertItem(stack, startIndex, endIndex, fromLast); + } + + @Override + public Slot addSlot(Slot slot) { + return super.addSlot(slot); + } +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Screen/ScreenUtils.java b/1.20.4/common/src/main/java/org/Vrglab/Screen/ScreenUtils.java new file mode 100644 index 0000000..7cfaec8 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Screen/ScreenUtils.java @@ -0,0 +1,60 @@ +package org.Vrglab.Screen; + +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; +import net.minecraft.util.Identifier; + +public class ScreenUtils { + public static ItemStack HandleShiftClick(int invSlot, Inventory inventory, ScreenHandler handler) { + ItemStack newStack = ItemStack.EMPTY; + Slot slot = handler.slots.get(invSlot); + if (slot != null && slot.hasStack()) { + ItemStack originalStack = slot.getStack(); + newStack = originalStack.copy(); + if (invSlot < inventory.size()) { + if (!handler.insertItem(originalStack, inventory.size(), handler.slots.size(), true)) { + return ItemStack.EMPTY; + } + } else if (!handler.insertItem(originalStack, 0, inventory.size(), false)) { + return ItemStack.EMPTY; + } + + if (originalStack.isEmpty()) { + slot.setStack(ItemStack.EMPTY); + } else { + slot.markDirty(); + } + } + + return newStack; + } + + public static void drawBG(int width, int height, int backgroundWidth, int backgroundHeight, MatrixStack matrices, HandledScreen screen, Identifier Texture){ + /*RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.setShaderTexture(0, Texture); + int x = (width - backgroundWidth) / 2; + int y = (height - backgroundHeight) / 2; + screen.drawTexture(matrices, x, y+2, 0, 0, backgroundWidth, backgroundHeight);*/ + } + + public static void addPlayerInventory(PlayerInventory playerInventory, ScreenHandler handler) { + for (int i = 0; i < 3; ++i) { + for (int l = 0; l < 9; ++l) { + handler.addSlot(new Slot(playerInventory, l + i * 9 + 9, 8 + l * 18, 86 + i * 18)); + } + } + } + + public static void addPlayerHotbar(PlayerInventory playerInventory, ScreenHandler handler) { + for (int i = 0; i < 9; ++i) { + handler.addSlot(new Slot(playerInventory, i, 8 + i * 18, 144)); + } + } +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Utils/Utils.java b/1.20.4/common/src/main/java/org/Vrglab/Utils/Utils.java new file mode 100644 index 0000000..0559738 --- /dev/null +++ b/1.20.4/common/src/main/java/org/Vrglab/Utils/Utils.java @@ -0,0 +1,10 @@ +package org.Vrglab.Utils; + +import org.Vrglab.Modloader.CreationHelpers.TypeTransformer; + +public class Utils { + + public static T convertToMcSafeType(Object registry_result){ + return (T)TypeTransformer.ObjectToType.accept(registry_result); + } +} diff --git a/1.20.4/common/src/main/java/org/Vrglab/Utils/Modinfo.java b/1.20.4/common/src/main/java/org/Vrglab/Utils/VLModInfo.java similarity index 90% rename from 1.20.4/common/src/main/java/org/Vrglab/Utils/Modinfo.java rename to 1.20.4/common/src/main/java/org/Vrglab/Utils/VLModInfo.java index 91a2e3e..c42e118 100644 --- a/1.20.4/common/src/main/java/org/Vrglab/Utils/Modinfo.java +++ b/1.20.4/common/src/main/java/org/Vrglab/Utils/VLModInfo.java @@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory; -public class Modinfo { +public class VLModInfo { public static final String MOD_ID = "vrglabslib"; public static Logger LOGGER = LoggerFactory.getLogger(VrglabsLib.class); diff --git a/1.20.4/common/src/main/java/org/Vrglab/VlBlocks.java b/1.20.4/common/src/main/java/org/Vrglab/VlBlocks.java deleted file mode 100644 index 1230f88..0000000 --- a/1.20.4/common/src/main/java/org/Vrglab/VlBlocks.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.Vrglab; - -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemGroups; -import org.Vrglab.Modloader.Registration.Registry; -import org.Vrglab.Utils.Modinfo; - -public class VlBlocks { - - public static Object BLOCK = Registry.RegisterBlock("block", Modinfo.MOD_ID, ()->new Block(AbstractBlock.Settings.create()), new Item.Settings().arch$tab(ItemGroups.BUILDING_BLOCKS)); - - public static void init(){ - - } -} diff --git a/1.20.4/common/src/main/java/org/Vrglab/VlGenData.java b/1.20.4/common/src/main/java/org/Vrglab/VlGenData.java deleted file mode 100644 index e8480b6..0000000 --- a/1.20.4/common/src/main/java/org/Vrglab/VlGenData.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.Vrglab; - -import net.minecraft.registry.tag.BlockTags; -import net.minecraft.world.gen.GenerationStep; -import net.minecraft.world.gen.feature.OreConfiguredFeatures; -import org.Vrglab.Modloader.CreationHelpers.OreGenFeatCreationHelper; -import org.Vrglab.Modloader.CreationHelpers.PlacementModifierCreationHelper; -import org.Vrglab.Modloader.Registration.Registry; -import org.Vrglab.Modloader.enumTypes.*; -import org.Vrglab.Utils.Modinfo; - -public class VlGenData { - - public static Object ORE_GEN_FEAT = Registry.RegisterOreConfiguredFeature("block_ore", Modinfo.MOD_ID, ()->OreGenFeatCreationHelper.create().addMatchCase(GenReplaceables.STONE_ORE_REPLACEABLES, VlBlocks.BLOCK).addMatchCase(GenReplaceables.DEEPSLATE_ORE_REPLACEABLES, VlBlocks.BLOCK).build(), 5); - - public static Object PLACED_FEAT = Registry.RegisterPlacedFeature("block_ore_placed", Modinfo.MOD_ID, ORE_GEN_FEAT, PlacementModifierCreationHelper.create().HeightRangePlacement(-80, 80).CountModifier(10).build()); - - - public static void init(){ - Registry.AddBiomeModification("overworld_block_gen", Modinfo.MOD_ID, VinillaBiomeTypes.OVERWORLD, GenerationStep.Feature.UNDERGROUND_ORES, PLACED_FEAT); - } -} diff --git a/1.20.4/common/src/main/java/org/Vrglab/VlPoiAndProfession.java b/1.20.4/common/src/main/java/org/Vrglab/VlPoiAndProfession.java deleted file mode 100644 index 438a686..0000000 --- a/1.20.4/common/src/main/java/org/Vrglab/VlPoiAndProfession.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.Vrglab; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.village.TradeOffer; -import org.Vrglab.Modloader.Registration.Registry; -import org.Vrglab.Utils.Modinfo; - -public class VlPoiAndProfession { - public static Object POI = Registry.RegisterPOI("poi", Modinfo.MOD_ID, VlBlocks.BLOCK, 1, 1); - public static Object PROFESSION = Registry.RegisterProfession("profession", Modinfo.MOD_ID, "poi", new Item[0], new Block[0], null); - - public static void init(){ - Registry.RegisterVillagerTrade("level1_profession", Modinfo.MOD_ID, PROFESSION, 1, new TradeOffer(new ItemStack(Items.EMERALD, 1), new ItemStack(Items.DIAMOND, 2), 20, 20, 0.02f)); - } -} diff --git a/1.20.4/common/src/main/java/org/Vrglab/VrglabsLib.java b/1.20.4/common/src/main/java/org/Vrglab/VrglabsLib.java index 2b02b76..1a19836 100644 --- a/1.20.4/common/src/main/java/org/Vrglab/VrglabsLib.java +++ b/1.20.4/common/src/main/java/org/Vrglab/VrglabsLib.java @@ -1,9 +1,10 @@ package org.Vrglab; +import org.TestSystem.TestMod; + public final class VrglabsLib { public static void init() { - VlBlocks.init(); - VlGenData.init(); + } } diff --git a/1.20.4/common/src/main/resources/assets/vrglabslib/blockstates/block.json b/1.20.4/common/src/main/resources/assets/vrglabslib/blockstates/block.json deleted file mode 100644 index 1984ecd..0000000 --- a/1.20.4/common/src/main/resources/assets/vrglabslib/blockstates/block.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "variants": { - "": { - "model": "vrglabslib:block/block" - } - } -} \ No newline at end of file diff --git a/1.20.4/common/src/main/resources/assets/vrglabslib/models/block/block.json b/1.20.4/common/src/main/resources/assets/vrglabslib/models/block/block.json deleted file mode 100644 index 9f7c3b3..0000000 --- a/1.20.4/common/src/main/resources/assets/vrglabslib/models/block/block.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "minecraft:block/cube_all", - "textures": { - "all": "vrglabslib:block/block" - } -} \ No newline at end of file diff --git a/1.20.4/common/src/main/resources/assets/vrglabslib/models/item/block.json b/1.20.4/common/src/main/resources/assets/vrglabslib/models/item/block.json deleted file mode 100644 index 22030ba..0000000 --- a/1.20.4/common/src/main/resources/assets/vrglabslib/models/item/block.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "vrglabslib:block/block" -} \ No newline at end of file diff --git a/1.20.4/common/src/main/resources/data/minecraft/tags/point_of_interest_type/acquirable_job_site.json b/1.20.4/common/src/main/resources/data/minecraft/tags/point_of_interest_type/acquirable_job_site.json deleted file mode 100644 index 28b3671..0000000 --- a/1.20.4/common/src/main/resources/data/minecraft/tags/point_of_interest_type/acquirable_job_site.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "values": [ - "vrglabslib:poi" - ] -} \ No newline at end of file diff --git a/1.20.4/common/src/main/resources/data/vrglabslib/neoforge/biome_modifier/add_block_ore.json b/1.20.4/common/src/main/resources/data/vrglabslib/neoforge/biome_modifier/add_block_ore.json deleted file mode 100644 index 9f485f8..0000000 --- a/1.20.4/common/src/main/resources/data/vrglabslib/neoforge/biome_modifier/add_block_ore.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "neoforge:add_features", - "biomes": "#minecraft:is_overworld", - "features": "vrglabslib:block_ore_placed", - "step": "underground_ores" -} \ No newline at end of file diff --git a/1.20.4/common/src/main/resources/data/vrglabslib/worldgen/configured_feature/block_ore.json b/1.20.4/common/src/main/resources/data/vrglabslib/worldgen/configured_feature/block_ore.json deleted file mode 100644 index 56baf72..0000000 --- a/1.20.4/common/src/main/resources/data/vrglabslib/worldgen/configured_feature/block_ore.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "type": "minecraft:ore", - "config": { - "discard_chance_on_air_exposure": 0.0, - "size": 5, - "targets": [ - { - "state": { - "Name": "vrglabslib:block" - }, - "target": { - "predicate_type": "minecraft:tag_match", - "tag": "minecraft:stone_ore_replaceables" - } - }, - { - "state": { - "Name": "vrglabslib:block" - }, - "target": { - "predicate_type": "minecraft:tag_match", - "tag": "minecraft:deepslate_ore_replaceables" - } - } - ] - } -} \ No newline at end of file diff --git a/1.20.4/common/src/main/resources/data/vrglabslib/worldgen/placed_feature/block_ore_placed.json b/1.20.4/common/src/main/resources/data/vrglabslib/worldgen/placed_feature/block_ore_placed.json deleted file mode 100644 index 6264ae7..0000000 --- a/1.20.4/common/src/main/resources/data/vrglabslib/worldgen/placed_feature/block_ore_placed.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "feature": "vrglabslib:block_ore", - "placement": [ - { - "type": "minecraft:count", - "count": 10 - }, - { - "type": "minecraft:in_square" - }, - { - "type": "minecraft:height_range", - "height": { - "type": "minecraft:trapezoid", - "max_inclusive": { - "above_bottom": 80 - }, - "min_inclusive": { - "above_bottom": -80 - } - } - }, - { - "type": "minecraft:biome" - } - ] -} \ No newline at end of file diff --git a/1.20.4/fabric-like/src/main/java/org/Vrglab/fabriclike/Utils/FabricLikeRegisteryCreator.java b/1.20.4/fabric-like/src/main/java/org/Vrglab/fabriclike/Utils/FabricLikeRegisteryCreator.java index eddcef4..d57a364 100644 --- a/1.20.4/fabric-like/src/main/java/org/Vrglab/fabriclike/Utils/FabricLikeRegisteryCreator.java +++ b/1.20.4/fabric-like/src/main/java/org/Vrglab/fabriclike/Utils/FabricLikeRegisteryCreator.java @@ -2,31 +2,47 @@ import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.fabricmc.fabric.api.biome.v1.BiomeSelectors; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; import net.fabricmc.fabric.api.object.builder.v1.villager.VillagerProfessionBuilder; import net.fabricmc.fabric.api.object.builder.v1.world.poi.PointOfInterestHelper; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.RecipeType; import net.minecraft.registry.*; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.minecraft.village.TradeOffer; import net.minecraft.village.VillagerProfession; +import net.minecraft.world.World; import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.YOffset; import net.minecraft.world.gen.feature.*; import net.minecraft.world.gen.placementmodifier.HeightRangePlacementModifier; import net.minecraft.world.gen.placementmodifier.PlacementModifier; +import org.Vrglab.EnergySystem.EnergyStorage; +import org.Vrglab.EnergySystem.EnergyStorageUtils; import org.Vrglab.Modloader.CreationHelpers.OreGenFeatCreationHelper; import org.Vrglab.Modloader.CreationHelpers.PlacementModifierCreationHelper; +import org.Vrglab.Modloader.CreationHelpers.TypeTransformer; import org.Vrglab.Modloader.Registration.Bootstrapper; import org.Vrglab.Modloader.Registration.Registry; +import org.Vrglab.Modloader.Types.ICallbackVoid; import org.Vrglab.Modloader.enumTypes.*; import org.Vrglab.Modloader.Types.ICallBack; +import org.Vrglab.Networking.Network; +import team.reborn.energy.api.base.SimpleEnergyStorage; import java.util.List; import java.util.function.Supplier; @@ -34,17 +50,14 @@ public class FabricLikeRegisteryCreator { public static void Create(String modid) { - OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() { - @Override - public Object accept(Object... args) { - return ((Block)args[0]).getDefaultState(); - } - }; + setEnergyStorageStatics(modid); + setOreGenHelperStatics(); + setNetworkStatics(); - PlacementModifierCreationHelper.getHeightModifications = new ICallBack() { + TypeTransformer.ObjectToType = new ICallBack() { @Override public Object accept(Object... args) { - return HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom((Integer) args[0]), YOffset.aboveBottom((Integer) args[1])); + return args[0]; } }; @@ -58,7 +71,7 @@ public Object accept(Object... args) { @Override public Object accept(Object... args) { Block b = net.minecraft.registry.Registry.register(Registries.BLOCK, new Identifier(modid, args[0].toString()), ((Supplier)args[1]).get()); - net.minecraft.registry.Registry.register(Registries.ITEM, new Identifier(modid, args[0].toString()), new BlockItem(b, (Item.Settings) args[2])); + net.minecraft.registry.Registry.register(Registries.ITEM, new Identifier(modid, args[0].toString()), new BlockItem(b, ((Supplier) args[2]).get())); return b; } }; @@ -130,6 +143,28 @@ public Object accept(Object... args) { } }; + ICallBack RecipeSerializerRegistryCallBack = new ICallBack() { + @Override + public Object accept(Object... args) { + return net.minecraft.registry.Registry.register(Registries.RECIPE_SERIALIZER, new Identifier(modid, args[0].toString()), (RecipeSerializer)args[1]); + } + }; + + ICallBack RecipeTypeRegistryCallBack = new ICallBack() { + @Override + public Object accept(Object... args) { + return net.minecraft.registry.Registry.register(Registries.RECIPE_TYPE, new Identifier(modid, args[0].toString()), (RecipeType) args[1]); + } + }; + + ICallBack ItemGroupRegistryCallBack = new ICallBack() { + @Override + public Object accept(Object... args) { + return net.minecraft.registry.Registry.register(Registries.ITEM_GROUP, new Identifier(modid, args[0].toString()), (ItemGroup)args[1]); + } + }; + + Registry.initRegistry(ItemGroupRegistryCallBack, RegistryTypes.CREATIVE_MODE_TAB, modid); Registry.initRegistry(ItemRegistryCallBack, RegistryTypes.ITEM, modid); Registry.initRegistry(ItemlessBlockRegistryCallBack, RegistryTypes.ITEMLESS_BLOCK, modid); Registry.initRegistry(BlockRegistryCallBack, RegistryTypes.BLOCK, modid); @@ -139,6 +174,8 @@ public Object accept(Object... args) { Registry.initRegistry(OreGenRegistryCallBack, RegistryTypes.CONFIGURED_FEAT_ORE, modid); Registry.initRegistry(PlacedFeatCallBack, RegistryTypes.PLACED_FEAT, modid); Registry.initRegistry(BiomeModCallBack, RegistryTypes.BIOME_MODIFICATIONS, modid); + Registry.initRegistry(RecipeSerializerRegistryCallBack, RegistryTypes.RECIPE_SERIALIZER, modid); + Registry.initRegistry(RecipeTypeRegistryCallBack, RegistryTypes.RECIPE_TYPE, modid); } public static void configureBootstrappables(RegistryWrapper.WrapperLookup Wrapper, FabricDynamicRegistryProvider.Entries entries) { @@ -157,4 +194,101 @@ public static void boostrap(RegistryBuilder builder, String modid) { return r.register((RegistryKey)args[0], new PlacedFeature(config_feat_lookup.getOrThrow((RegistryKey>) args[1]), (List)args[2])); }, BootstrapType.PLACED_FEAT, modid)); } + + private static void setEnergyStorageStatics(String modid) { + EnergyStorageUtils.createStorageInstance = new ICallBack() { + @Override + public Object accept(Object... args) { + return new SimpleEnergyStorage((Long) args[0],(Long) args[1],(Long) args[2]){ + @Override + protected void onFinalCommit() { + super.onFinalCommit(); + try { + ((EnergyStorage)args[4]).makeDirty.accept(); + } catch (Throwable t) { + + } + } + }; + } + }; + + EnergyStorageUtils.receiveEnergyInstance = new ICallBack() { + @Override + public Object accept(Object... args) { + try (Transaction openTrans = Transaction.openOuter()) { + long res = ((SimpleEnergyStorage)args[0]).insert((long)args[1], openTrans); + openTrans.commit(); + return res; + } + } + }; + + EnergyStorageUtils.extractEnergyInstance = new ICallBack() { + @Override + public Object accept(Object... args) { + try (Transaction openTrans = Transaction.openOuter()) { + long res = ((SimpleEnergyStorage)args[0]).extract((long)args[1], openTrans); + openTrans.commit(); + return res; + } + } + }; + + EnergyStorageUtils.hasExternalStorage = new ICallBack() { + @Override + public Object accept(Object... args) { + BlockEntity entity = (BlockEntity) args[0]; + + if(entity == null){ + return false; + } + + return (team.reborn.energy.api.EnergyStorage.SIDED.find(entity.getWorld(), entity.getPos(), Direction.NORTH) != null || + team.reborn.energy.api.EnergyStorage.SIDED.find(entity.getWorld(), entity.getPos(), Direction.EAST) != null || + team.reborn.energy.api.EnergyStorage.SIDED.find(entity.getWorld(), entity.getPos(), Direction.WEST) != null || + team.reborn.energy.api.EnergyStorage.SIDED.find(entity.getWorld(), entity.getPos(), Direction.SOUTH) != null); + } + }; + + EnergyStorageUtils.wrapExternalStorage = new ICallBack() { + @Override + public Object accept(Object... args) { + team.reborn.energy.api.EnergyStorage storage = team.reborn.energy.api.EnergyStorage.SIDED.find((World) args[0], (BlockPos) args[1], (Direction) args[2]); + return new EnergyStorage(storage, storage.getCapacity(), storage.getCapacity(), storage.getCapacity(), storage.getAmount()); + } + }; + } + + private static void setOreGenHelperStatics() { + OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() { + @Override + public Object accept(Object... args) { + return ((Block)args[0]).getDefaultState(); + } + }; + + PlacementModifierCreationHelper.getHeightModifications = new ICallBack() { + @Override + public Object accept(Object... args) { + return HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom((Integer) args[0]), YOffset.aboveBottom((Integer) args[1])); + } + }; + } + + private static void setNetworkStatics() { + Network.registerGlobalReceiver = new ICallbackVoid() { + @Override + public void accept(Object... args) { + ServerPlayNetworking.registerGlobalReceiver((Identifier) args[0], (a, b, c, d, e)->((ICallBack)args[1]).accept(a,b,c,d,e)); + } + }; + + Network.clientSendPacket = new ICallbackVoid() { + @Override + public void accept(Object... args) { + ClientPlayNetworking.send((Identifier) args[0], (PacketByteBuf) args[1]); + } + }; + } } diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/EnergyStorage.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/EnergyStorage.java new file mode 100644 index 0000000..71cc4c4 --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/EnergyStorage.java @@ -0,0 +1,125 @@ +package team.reborn.energy.api; + +import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; +import net.fabricmc.fabric.api.lookup.v1.item.ItemApiLookup; +import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.Direction; +import org.jetbrains.annotations.Nullable; +import team.reborn.energy.api.base.DelegatingEnergyStorage; +import team.reborn.energy.api.base.SimpleEnergyItem; +import team.reborn.energy.api.base.SimpleEnergyStorage; +import team.reborn.energy.api.base.SimpleSidedEnergyContainer; +import team.reborn.energy.impl.EnergyImpl; +import team.reborn.energy.impl.SimpleItemEnergyStorageImpl; + +/** + * An object that can store energy. + * + *

    + *
  • {@link #supportsInsertion} and {@link #supportsExtraction} can be used to tell if insertion and extraction + * functionality are possibly supported by this storage.
  • + *
  • {@link #insert} and {@link #extract} can be used to insert or extract resources from this storage.
  • + *
  • {@link #getAmount} and {@link #getCapacity} can be used to query the current amount and capacity of this storage. + * There is no guarantee that the current amount of energy can be extracted, + * nor that something can be inserted if capacity > amount. + * If you want to know, you can simulate the operation with {@link #insert} and {@link #extract}. + *
  • + *
+ * + * @see Transaction + */ +@SuppressWarnings({"unused", "deprecation", "UnstableApiUsage"}) +public interface EnergyStorage { + /** + * Sided block access to energy storages. + * The {@code Direction} parameter may be null, meaning that the full storage (ignoring side restrictions) should be queried. + * Refer to {@link BlockApiLookup} for documentation on how to use this field. + * + *

The system is push based. That means that power sources are responsible for pushing power to nearby machines. + * Machines and wires should NOT pull power from other sources. + * + *

{@link SimpleEnergyStorage} and {@link SimpleSidedEnergyContainer} are provided as base implementations. + * + *

When the operations supported by an energy storage change, + * that is if the return value of {@link EnergyStorage#supportsInsertion} or {@link EnergyStorage#supportsExtraction} changes, + * the storage should notify its neighbors with a block update so that they can refresh their connections if necessary. + * + *

This may be queried safely both on the logical server and on the logical client threads. + * On the server thread (i.e. with a server world), all transfer functionality is always supported. + * On the client thread (i.e. with a client world), contents of queried EnergyStorages are unreliable and should not be modified. + */ + BlockApiLookup SIDED = + BlockApiLookup.get(new Identifier("teamreborn:sided_energy"), EnergyStorage.class, Direction.class); + + /** + * Item access to energy storages. + * Querying should always happen through {@link ContainerItemContext#find}. + * + *

{@link SimpleItemEnergyStorageImpl} is provided as an implementation example. + * Instances of it can be optained through {@link SimpleEnergyItem#createStorage}. + * Custom implementations should treat the context as a wrapper around a single slot, + * and always check the current item variant and amount before any operation, like {@code SimpleItemEnergyStorageImpl} does it. + * The check can be handled by {@link DelegatingEnergyStorage}. + * + *

This may be queried both client-side and server-side. + * Returned APIs should behave the same regardless of the logical side. + */ + ItemApiLookup ITEM = + ItemApiLookup.get(new Identifier("teamreborn:energy"), EnergyStorage.class, ContainerItemContext.class); + + /** + * Always empty energy storage. + */ + EnergyStorage EMPTY = EnergyImpl.EMPTY; + + /** + * Return false if calling {@link #insert} will absolutely always return 0, or true otherwise or in doubt. + * + *

Note: This function is meant to be used by cables or other devices that can transfer energy to know if + * they should interact with this storage at all. + */ + default boolean supportsInsertion() { + return true; + } + + /** + * Try to insert up to some amount of energy into this storage. + * + * @param maxAmount The maximum amount of energy to insert. May not be negative. + * @param transaction The transaction this operation is part of. + * @return A nonnegative integer not greater than maxAmount: the amount that was inserted. + */ + long insert(long maxAmount, TransactionContext transaction); + + /** + * Return false if calling {@link #extract} will absolutely always return 0, or true otherwise or in doubt. + * + *

Note: This function is meant to be used by cables or other devices that can transfer energy to know if + * they should interact with this storage at all. + */ + default boolean supportsExtraction() { + return true; + } + + /** + * Try to extract up to some amount of energy from this storage. + * + * @param maxAmount The maximum amount of energy to extract. May not be negative. + * @param transaction The transaction this operation is part of. + * @return A nonnegative integer not greater than maxAmount: the amount that was extracted. + */ + long extract(long maxAmount, TransactionContext transaction); + + /** + * Return the current amount of energy that is stored. + */ + long getAmount(); + + /** + * Return the maximum amount of energy that could be stored. + */ + long getCapacity(); +} diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/EnergyStorageUtil.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/EnergyStorageUtil.java new file mode 100644 index 0000000..000ba7e --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/EnergyStorageUtil.java @@ -0,0 +1,62 @@ +package team.reborn.energy.api; + +import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; +import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +/** + * Helper functions to work with {@link EnergyStorage}s. + */ +@SuppressWarnings({"unused", "deprecation", "UnstableApiUsage"}) +public class EnergyStorageUtil { + /** + * Move energy between two energy storages, and return the amount that was successfully moved. + * + * @param from The source storage. May be null. + * @param to The target storage. May be null. + * @param maxAmount The maximum amount that may be moved. + * @param transaction The transaction this transfer is part of, + * or {@code null} if a transaction should be opened just for this transfer. + * @return The amount of energy that was successfully moved. + */ + public static long move(@Nullable EnergyStorage from, @Nullable EnergyStorage to, long maxAmount, @Nullable TransactionContext transaction) { + if (from == null || to == null) return 0; + + StoragePreconditions.notNegative(maxAmount); + + // Simulate extraction first. + long maxExtracted; + + try (Transaction extractionTestTransaction = Transaction.openNested(transaction)) { + maxExtracted = from.extract(maxAmount, extractionTestTransaction); + } + + try (Transaction moveTransaction = Transaction.openNested(transaction)) { + // Then insert what can be extracted. + long accepted = to.insert(maxExtracted, moveTransaction); + + // Extract for real. + if (from.extract(accepted, moveTransaction) == accepted) { + // Commit if the amounts match. + moveTransaction.commit(); + return accepted; + } + } + + return 0; + } + + /** + * Return true if the passed stack offers an energy storage through {@link EnergyStorage#ITEM}. + * This can typically be used for inventories or slots that want to accept energy storages only. + */ + public static boolean isEnergyStorage(ItemStack stack) { + return ContainerItemContext.withConstant(stack).find(EnergyStorage.ITEM) != null; + } + + private EnergyStorageUtil() { + } +} diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/DelegatingEnergyStorage.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/DelegatingEnergyStorage.java new file mode 100644 index 0000000..00591e0 --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/DelegatingEnergyStorage.java @@ -0,0 +1,90 @@ +package team.reborn.energy.api.base; + +import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import org.jetbrains.annotations.Nullable; +import team.reborn.energy.api.EnergyStorage; + +import java.util.Objects; +import java.util.function.BooleanSupplier; +import java.util.function.Supplier; + +/** + * An energy storage that delegates to another energy storage, + * with an optional boolean supplier to check that the storage is still valid. + * This can be used for easier item energy storage implementation, or overridden for custom delegation logic. + */ +@SuppressWarnings({"deprecation", "UnstableApiUsage"}) +public class DelegatingEnergyStorage implements EnergyStorage { + protected final Supplier backingStorage; + protected final BooleanSupplier validPredicate; + + /** + * Create a new instance. + * @param backingStorage Storage to delegate to. + * @param validPredicate A function that can return false to prevent any operation, or true to call the delegate as usual. + * {@code null} can be passed if no filtering is necessary. + */ + public DelegatingEnergyStorage(EnergyStorage backingStorage, @Nullable BooleanSupplier validPredicate) { + this(() -> backingStorage, validPredicate); + Objects.requireNonNull(backingStorage); + } + + /** + * More general constructor that allows the backing storage to change over time. + */ + public DelegatingEnergyStorage(Supplier backingStorage, @Nullable BooleanSupplier validPredicate) { + this.backingStorage = Objects.requireNonNull(backingStorage); + this.validPredicate = validPredicate == null ? () -> true : validPredicate; + } + + @Override + public boolean supportsInsertion() { + return validPredicate.getAsBoolean() && backingStorage.get().supportsInsertion(); + } + + @Override + public long insert(long maxAmount, TransactionContext transaction) { + StoragePreconditions.notNegative(maxAmount); + + if (validPredicate.getAsBoolean()) { + return backingStorage.get().insert(maxAmount, transaction); + } else { + return 0; + } + } + + @Override + public boolean supportsExtraction() { + return validPredicate.getAsBoolean() && backingStorage.get().supportsExtraction(); + } + + @Override + public long extract(long maxAmount, TransactionContext transaction) { + StoragePreconditions.notNegative(maxAmount); + + if (validPredicate.getAsBoolean()) { + return backingStorage.get().extract(maxAmount, transaction); + } else { + return 0; + } + } + + @Override + public long getAmount() { + if (validPredicate.getAsBoolean()) { + return backingStorage.get().getAmount(); + } else { + return 0; + } + } + + @Override + public long getCapacity() { + if (validPredicate.getAsBoolean()) { + return backingStorage.get().getCapacity(); + } else { + return 0; + } + } +} diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/InfiniteEnergyStorage.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/InfiniteEnergyStorage.java new file mode 100644 index 0000000..0ceaa90 --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/InfiniteEnergyStorage.java @@ -0,0 +1,38 @@ +package team.reborn.energy.api.base; + +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import team.reborn.energy.api.EnergyStorage; + +/** + * An energy storage that can't accept energy, but will allow extracting any amount of energy. + * Creative batteries are a possible use case. + * {@link #INSTANCE} can be used instead of creating a new object every time. + */ +public class InfiniteEnergyStorage implements EnergyStorage { + public static final InfiniteEnergyStorage INSTANCE = new InfiniteEnergyStorage(); + + @Override + public boolean supportsInsertion() { + return false; + } + + @Override + public long insert(long maxAmount, TransactionContext transaction) { + return 0; + } + + @Override + public long extract(long maxAmount, TransactionContext transaction) { + return maxAmount; + } + + @Override + public long getAmount() { + return Long.MAX_VALUE; + } + + @Override + public long getCapacity() { + return Long.MAX_VALUE; + } +} \ No newline at end of file diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/LimitingEnergyStorage.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/LimitingEnergyStorage.java new file mode 100644 index 0000000..452a6ed --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/LimitingEnergyStorage.java @@ -0,0 +1,61 @@ +package team.reborn.energy.api.base; + +import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import team.reborn.energy.api.EnergyStorage; + +import java.util.Objects; + +/** + * An energy storage that will apply additional per-insert and per-extract limits to another storage. + */ +public class LimitingEnergyStorage implements EnergyStorage { + protected final EnergyStorage backingStorage; + protected final long maxInsert, maxExtract; + + /** + * Create a new limiting storage. + * @param backingStorage Storage to delegate to. + * @param maxInsert The maximum amount of energy that can be inserted in one operation. + * @param maxExtract The maximum amount of energy that can be extracted in one operation. + */ + public LimitingEnergyStorage(EnergyStorage backingStorage, long maxInsert, long maxExtract) { + Objects.requireNonNull(backingStorage); + StoragePreconditions.notNegative(maxInsert); + StoragePreconditions.notNegative(maxExtract); + + this.backingStorage = backingStorage; + this.maxInsert = maxInsert; + this.maxExtract = maxExtract; + } + + @Override + public boolean supportsInsertion() { + return maxInsert > 0 && backingStorage.supportsInsertion(); + } + + @Override + public long insert(long maxAmount, TransactionContext transaction) { + return backingStorage.insert(Math.min(maxAmount, maxInsert), transaction); + } + + @Override + public boolean supportsExtraction() { + return maxExtract > 0 && backingStorage.supportsExtraction(); + } + + @Override + public long extract(long maxAmount, TransactionContext transaction) { + return backingStorage.extract(Math.min(maxAmount, maxExtract), transaction); + } + + @Override + public long getAmount() { + return backingStorage.getAmount(); + } + + @Override + public long getCapacity() { + return backingStorage.getCapacity(); + } +} diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java new file mode 100644 index 0000000..2eb0a5f --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java @@ -0,0 +1,112 @@ +package team.reborn.energy.api.base; + +import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import org.jetbrains.annotations.Nullable; +import team.reborn.energy.api.EnergyStorage; +import team.reborn.energy.impl.SimpleItemEnergyStorageImpl; + +/** + * Simple battery-like energy containing item. If this is implemented on an item: + *

    + *
  • The energy will directly be stored in the NBT.
  • + *
  • Helper functions in this class to work with the stored energy can be used.
  • + *
  • An EnergyStorage will automatically be provided for queries through {@link EnergyStorage#ITEM}.
  • + *
+ */ +// TODO: Consider adding a tooltip and a recipe input -> output energy transfer handler like RC has. +public interface SimpleEnergyItem { + String ENERGY_KEY = "energy"; + + /** + * Return a base energy storage implementation for items, with fixed capacity, and per-operation insertion and extraction limits. + * This is used internally for items that implement SimpleEnergyItem, but it may also be used outside of that. + * The energy is stored in the {@code energy} tag of the stacks, the same as the constant {@link #ENERGY_KEY}. + * + *

Stackable energy containers are supported just fine, and they will distribute energy evenly. + * For example, insertion of 3 units of energy into a stack of 2 items using this class will either insert 0 or 2 depending on the remaining capacity. + */ + static EnergyStorage createStorage(ContainerItemContext ctx, long capacity, long maxInsert, long maxExtract) { + return SimpleItemEnergyStorageImpl.createSimpleStorage(ctx, capacity, maxInsert, maxExtract); + } + + /** + * @param stack Current stack. + * @return The max energy that can be stored in this item stack (ignoring current stack size). + */ + long getEnergyCapacity(ItemStack stack); + + /** + * @param stack Current stack. + * @return The max amount of energy that can be inserted in this item stack (ignoring current stack size) in a single operation. + */ + long getEnergyMaxInput(ItemStack stack); + + /** + * @param stack Current stack. + * @return The max amount of energy that can be extracted from this item stack (ignoring current stack size) in a single operation. + */ + long getEnergyMaxOutput(ItemStack stack); + + /** + * @return The energy stored in the stack. Count is ignored. + */ + default long getStoredEnergy(ItemStack stack) { + return getStoredEnergyUnchecked(stack); + } + + /** + * Directly set the energy stored in the stack. Count is ignored. + * It's up to callers to ensure that the new amount is >= 0 and <= capacity. + */ + default void setStoredEnergy(ItemStack stack, long newAmount) { + setStoredEnergyUnchecked(stack, newAmount); + } + + /** + * Try to use exactly {@code amount} energy if there is enough available and return true if successful, + * otherwise do nothing and return false. + * @throws IllegalArgumentException If the count of the stack is not exactly 1! + */ + default boolean tryUseEnergy(ItemStack stack, long amount) { + if (stack.getCount() != 1) { + throw new IllegalArgumentException("Invalid count: " + stack.getCount()); + } + + long newAmount = getStoredEnergy(stack) - amount; + + if (newAmount < 0) { + return false; + } else { + setStoredEnergy(stack, newAmount); + return true; + } + } + + /** + * @return The currently stored energy, ignoring the count and without checking the current item. + */ + static long getStoredEnergyUnchecked(ItemStack stack) { + return getStoredEnergyUnchecked(stack.getNbt()); + } + + /** + * @return The currently stored energy of this raw tag. + */ + static long getStoredEnergyUnchecked(@Nullable NbtCompound nbt) { + return nbt != null ? nbt.getLong(ENERGY_KEY) : 0; + } + + /** + * Set the energy, ignoring the count and without checking the current item. + */ + static void setStoredEnergyUnchecked(ItemStack stack, long newAmount) { + if (newAmount == 0) { + // Make sure newly crafted energy containers stack with emptied ones. + stack.removeSubNbt(ENERGY_KEY); + } else { + stack.getOrCreateNbt().putLong(ENERGY_KEY, newAmount); + } + } +} diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleEnergyStorage.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleEnergyStorage.java new file mode 100644 index 0000000..eb6640a --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleEnergyStorage.java @@ -0,0 +1,87 @@ +package team.reborn.energy.api.base; + +import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; +import team.reborn.energy.api.EnergyStorage; + +/** + * A base energy storage implementation with fixed capacity, and per-operation insertion and extraction limits. + * Make sure to override {@link #onFinalCommit} to call {@code markDirty} and similar functions. + */ +@SuppressWarnings({"unused", "deprecation", "UnstableApiUsage"}) +public class SimpleEnergyStorage extends SnapshotParticipant implements EnergyStorage { + public long amount = 0; + public final long capacity; + public final long maxInsert, maxExtract; + + public SimpleEnergyStorage(long capacity, long maxInsert, long maxExtract) { + StoragePreconditions.notNegative(capacity); + StoragePreconditions.notNegative(maxInsert); + StoragePreconditions.notNegative(maxExtract); + + this.capacity = capacity; + this.maxInsert = maxInsert; + this.maxExtract = maxExtract; + } + + @Override + protected Long createSnapshot() { + return amount; + } + + @Override + protected void readSnapshot(Long snapshot) { + amount = snapshot; + } + + @Override + public boolean supportsInsertion() { + return maxInsert > 0; + } + + @Override + public long insert(long maxAmount, TransactionContext transaction) { + StoragePreconditions.notNegative(maxAmount); + + long inserted = Math.min(maxInsert, Math.min(maxAmount, capacity - amount)); + + if (inserted > 0) { + updateSnapshots(transaction); + amount += inserted; + return inserted; + } + + return 0; + } + + @Override + public boolean supportsExtraction() { + return maxExtract > 0; + } + + @Override + public long extract(long maxAmount, TransactionContext transaction) { + StoragePreconditions.notNegative(maxAmount); + + long extracted = Math.min(maxExtract, Math.min(maxAmount, amount)); + + if (extracted > 0) { + updateSnapshots(transaction); + amount -= extracted; + return extracted; + } + + return 0; + } + + @Override + public long getAmount() { + return amount; + } + + @Override + public long getCapacity() { + return capacity; + } +} diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleSidedEnergyContainer.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleSidedEnergyContainer.java new file mode 100644 index 0000000..41b8156 --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/api/base/SimpleSidedEnergyContainer.java @@ -0,0 +1,115 @@ +package team.reborn.energy.api.base; + +import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; +import net.minecraft.util.math.Direction; +import org.jetbrains.annotations.Nullable; +import team.reborn.energy.api.EnergyStorage; + +/** + * A base energy storage implementation with a dynamic capacity, and per-side per-operation insertion and extraction limits. + * {@link #getSideStorage} can be used to get an {@code EnergyStorage} implementation for a given side. + * Make sure to override {@link #onFinalCommit} to call {@code markDirty} and similar functions. + */ +@SuppressWarnings({"unused", "deprecation", "UnstableApiUsage"}) +public abstract class SimpleSidedEnergyContainer extends SnapshotParticipant { + public long amount = 0; + private final SideStorage[] sideStorages = new SideStorage[7]; + + public SimpleSidedEnergyContainer() { + for (int i = 0; i < 7; ++i) { + sideStorages[i] = new SideStorage(i == 6 ? null : Direction.byId(i)); + } + } + + /** + * @return The current capacity of this storage. + */ + public abstract long getCapacity(); + + /** + * @return The maximum amount of energy that can be inserted in a single operation from the passed side. + */ + public abstract long getMaxInsert(@Nullable Direction side); + + /** + * @return The maximum amount of energy that can be extracted in a single operation from the passed side. + */ + public abstract long getMaxExtract(@Nullable Direction side); + + /** + * @return An {@link EnergyStorage} implementation for the passed side. + */ + public EnergyStorage getSideStorage(@Nullable Direction side) { + return sideStorages[side == null ? 6 : side.getId()]; + } + + @Override + protected Long createSnapshot() { + return amount; + } + + @Override + protected void readSnapshot(Long snapshot) { + amount = snapshot; + } + + private class SideStorage implements EnergyStorage { + private final Direction side; + + private SideStorage(Direction side) { + this.side = side; + } + + @Override + public boolean supportsInsertion() { + return getMaxInsert(side) > 0; + } + + @Override + public long insert(long maxAmount, TransactionContext transaction) { + StoragePreconditions.notNegative(maxAmount); + + long inserted = Math.min(getMaxInsert(side), Math.min(maxAmount, getCapacity() - amount)); + + if (inserted > 0) { + updateSnapshots(transaction); + amount += inserted; + return inserted; + } + + return 0; + } + + @Override + public boolean supportsExtraction() { + return getMaxExtract(side) > 0; + } + + @Override + public long extract(long maxAmount, TransactionContext transaction) { + StoragePreconditions.notNegative(maxAmount); + + long extracted = Math.min(getMaxExtract(side), Math.min(maxAmount, amount)); + + if (extracted > 0) { + updateSnapshots(transaction); + amount -= extracted; + return extracted; + } + + return 0; + } + + @Override + public long getAmount() { + return amount; + } + + @Override + public long getCapacity() { + return SimpleSidedEnergyContainer.this.getCapacity(); + } + } +} diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/impl/EnergyImpl.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/impl/EnergyImpl.java new file mode 100644 index 0000000..7ddd969 --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/impl/EnergyImpl.java @@ -0,0 +1,53 @@ +package team.reborn.energy.impl; + +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import org.jetbrains.annotations.ApiStatus; +import team.reborn.energy.api.EnergyStorage; +import team.reborn.energy.api.base.SimpleEnergyItem; + +@ApiStatus.Internal +public class EnergyImpl { + static { + EnergyStorage.ITEM.registerFallback((stack, ctx) -> { + if (stack.getItem() instanceof SimpleEnergyItem energyItem) { + return SimpleEnergyItem.createStorage(ctx, energyItem.getEnergyCapacity(stack), energyItem.getEnergyMaxInput(stack), energyItem.getEnergyMaxOutput(stack)); + } else if (stack.getItem() instanceof SimpleEnergyItem battery) { + return SimpleEnergyItem.createStorage(ctx, battery.getEnergyCapacity(stack), battery.getEnergyMaxInput(stack), battery.getEnergyMaxOutput(stack)); + } else { + return null; + } + }); + } + + public static final EnergyStorage EMPTY = new EnergyStorage() { + @Override + public boolean supportsInsertion() { + return false; + } + + @Override + public long insert(long maxAmount, TransactionContext transaction) { + return 0; + } + + @Override + public boolean supportsExtraction() { + return false; + } + + @Override + public long extract(long maxAmount, TransactionContext transaction) { + return 0; + } + + @Override + public long getAmount() { + return 0; + } + + @Override + public long getCapacity() { + return 0; + } + }; +} diff --git a/1.20.4/fabric-like/src/main/java/team/reborn/energy/impl/SimpleItemEnergyStorageImpl.java b/1.20.4/fabric-like/src/main/java/team/reborn/energy/impl/SimpleItemEnergyStorageImpl.java new file mode 100644 index 0000000..4ac798b --- /dev/null +++ b/1.20.4/fabric-like/src/main/java/team/reborn/energy/impl/SimpleItemEnergyStorageImpl.java @@ -0,0 +1,118 @@ +package team.reborn.energy.impl; + +import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; +import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; +import team.reborn.energy.api.EnergyStorage; +import team.reborn.energy.api.base.DelegatingEnergyStorage; +import team.reborn.energy.api.base.SimpleEnergyItem; + +/** + * Note: instances of this class do not perform any context validation, + * that is handled by the DelegatingEnergyStorage they are wrapped behind. + */ +@ApiStatus.Internal +@SuppressWarnings({"deprecation", "UnstableApiUsage"}) +public class SimpleItemEnergyStorageImpl implements EnergyStorage { + public static EnergyStorage createSimpleStorage(ContainerItemContext ctx, long capacity, long maxInsert, long maxExtract) { + StoragePreconditions.notNegative(capacity); + StoragePreconditions.notNegative(maxInsert); + StoragePreconditions.notNegative(maxExtract); + + Item startingItem = ctx.getItemVariant().getItem(); + + return new DelegatingEnergyStorage( + new SimpleItemEnergyStorageImpl(ctx, capacity, maxInsert, maxExtract), + () -> ctx.getItemVariant().isOf(startingItem) && ctx.getAmount() > 0 + ); + } + + private final ContainerItemContext ctx; + private final long capacity; + private final long maxInsert, maxExtract; + + private SimpleItemEnergyStorageImpl(ContainerItemContext ctx, long capacity, long maxInsert, long maxExtract) { + this.ctx = ctx; + this.capacity = capacity; + this.maxInsert = maxInsert; + this.maxExtract = maxExtract; + } + + /** + * Try to set the energy of the stack to {@code energyAmountPerCount}, return true if success. + */ + private boolean trySetEnergy(long energyAmountPerCount, long count, TransactionContext transaction) { + ItemStack newStack = ctx.getItemVariant().toStack(); + SimpleEnergyItem.setStoredEnergyUnchecked(newStack, energyAmountPerCount); + ItemVariant newVariant = ItemVariant.of(newStack); + + // Try to convert exactly `count` items. + try (Transaction nested = transaction.openNested()) { + if (ctx.extract(ctx.getItemVariant(), count, nested) == count && ctx.insert(newVariant, count, nested) == count) { + nested.commit(); + return true; + } + } + + return false; + } + + @Override + public boolean supportsInsertion() { + return maxInsert > 0; + } + + @Override + public long insert(long maxAmount, TransactionContext transaction) { + long count = ctx.getAmount(); + + long maxAmountPerCount = maxAmount / count; + long currentAmountPerCount = getAmount() / count; + long insertedPerCount = Math.min(maxInsert, Math.min(maxAmountPerCount, capacity - currentAmountPerCount)); + + if (insertedPerCount > 0) { + if (trySetEnergy(currentAmountPerCount + insertedPerCount, count, transaction)) { + return insertedPerCount * count; + } + } + + return 0; + } + + @Override + public boolean supportsExtraction() { + return maxExtract > 0; + } + + @Override + public long extract(long maxAmount, TransactionContext transaction) { + long count = ctx.getAmount(); + + long maxAmountPerCount = maxAmount / count; + long currentAmountPerCount = getAmount() / count; + long extractedPerCount = Math.min(maxExtract, Math.min(maxAmountPerCount, currentAmountPerCount)); + + if (extractedPerCount > 0) { + if (trySetEnergy(currentAmountPerCount - extractedPerCount, count, transaction)) { + return extractedPerCount * count; + } + } + + return 0; + } + + @Override + public long getAmount() { + return ctx.getAmount() * SimpleEnergyItem.getStoredEnergyUnchecked(ctx.getItemVariant().getNbt()); + } + + @Override + public long getCapacity() { + return ctx.getAmount() * capacity; + } +} diff --git a/1.20.4/fabric/build.gradle b/1.20.4/fabric/build.gradle index 68e02bb..e64bdcb 100644 --- a/1.20.4/fabric/build.gradle +++ b/1.20.4/fabric/build.gradle @@ -65,10 +65,8 @@ dependencies { } processResources { - inputs.property 'version', project.version - filesMatching('fabric.mod.json') { - expand version: project.version + expand rootProject.properties } } diff --git a/1.20.4/fabric/src/main/java/org/Vrglab/fabric/VLDataGenerator.java b/1.20.4/fabric/src/main/java/org/Vrglab/fabric/VLDataGenerator.java index 980ac77..ec9ab81 100644 --- a/1.20.4/fabric/src/main/java/org/Vrglab/fabric/VLDataGenerator.java +++ b/1.20.4/fabric/src/main/java/org/Vrglab/fabric/VLDataGenerator.java @@ -4,7 +4,7 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.minecraft.data.DataProvider; import net.minecraft.registry.RegistryBuilder; -import org.Vrglab.Utils.Modinfo; +import org.Vrglab.Utils.VLModInfo; import org.Vrglab.fabriclike.Utils.FabricLikeRegisteryCreator; public class VLDataGenerator implements DataGeneratorEntrypoint { @@ -30,6 +30,6 @@ public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { */ @Override public void buildRegistry(RegistryBuilder registryBuilder) { - FabricLikeRegisteryCreator.boostrap(registryBuilder, Modinfo.MOD_ID); + FabricLikeRegisteryCreator.boostrap(registryBuilder, VLModInfo.MOD_ID); } } diff --git a/1.20.4/fabric/src/main/java/org/Vrglab/fabric/VLModFabric.java b/1.20.4/fabric/src/main/java/org/Vrglab/fabric/VLModFabric.java index 27b5f7a..cc5d79d 100644 --- a/1.20.4/fabric/src/main/java/org/Vrglab/fabric/VLModFabric.java +++ b/1.20.4/fabric/src/main/java/org/Vrglab/fabric/VLModFabric.java @@ -2,13 +2,13 @@ import net.fabricmc.api.ModInitializer; -import org.Vrglab.Utils.Modinfo; +import org.Vrglab.Utils.VLModInfo; import org.Vrglab.VrglabsLib; import org.Vrglab.fabriclike.VLModFabricLike; public final class VLModFabric implements ModInitializer { @Override public void onInitialize() { - VLModFabricLike.init(Modinfo.MOD_ID, ()-> VrglabsLib.init()); + VLModFabricLike.init(VLModInfo.MOD_ID, ()-> VrglabsLib.init()); } } diff --git a/1.20.4/fabric/src/main/resources/fabric.mod.json b/1.20.4/fabric/src/main/resources/fabric.mod.json index d527655..f2e5db4 100644 --- a/1.20.4/fabric/src/main/resources/fabric.mod.json +++ b/1.20.4/fabric/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "vrglabslib", - "version": "${version}", + "version": "${loader_safe_version}", "name": "Vrglabs Lib", "description": "Architectury based custom data Registration system and Utilities", "authors": [ diff --git a/1.20.4/forge/gradle.properties b/1.20.4/forge/gradle.properties deleted file mode 100644 index a58ba14..0000000 --- a/1.20.4/forge/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -loom.platform = forge diff --git a/1.20.4/forge/src/main/java/org/Vrglab/forge/Utils/ForgeRegistryCreator.java b/1.20.4/forge/src/main/java/org/Vrglab/forge/Utils/ForgeRegistryCreator.java deleted file mode 100644 index 1e34c5c..0000000 --- a/1.20.4/forge/src/main/java/org/Vrglab/forge/Utils/ForgeRegistryCreator.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.Vrglab.forge.Utils; - -import com.google.common.collect.ImmutableSet; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.block.Block; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.registry.Registries; -import net.minecraft.registry.RegistryKey; -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.Identifier; -import net.minecraft.village.TradeOffer; -import net.minecraft.village.TradeOffers; -import net.minecraft.village.VillagerProfession; -import net.minecraft.world.poi.PointOfInterestType; -import net.minecraftforge.event.village.VillagerTradesEvent; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; -import org.Vrglab.Modloader.Registration.Registry; -import org.Vrglab.Modloader.enumTypes.RegistryTypes; -import org.Vrglab.Modloader.Types.ICallBack; - -import java.util.List; -import java.util.function.Supplier; - -public class ForgeRegistryCreator { - - - public static ICallBack TradeRegistryEventCallback = new ICallBack() { - @Override - public Object accept(Object... args) { - Object[] arg = (Object[]) args[0]; - if(((VillagerTradesEvent)args[1]).getType() == ((RegistryObject)arg[1]).get()) { - Int2ObjectMap> trades = ((VillagerTradesEvent)args[1]).getTrades(); - for (TradeOffer data: (TradeOffer[])arg[3]) { - trades.get((int)arg[2]).add((trader, rand) -> data); - } - } - return null; - } - }; - - public static void Create(IEventBus eventBus, String modid) { - DeferredRegister ITEM_REGISTRY = DeferredRegister.create(ForgeRegistries.ITEMS, modid); - ITEM_REGISTRY.register(eventBus); - - DeferredRegister BLOCK_REGISTRY = DeferredRegister.create(ForgeRegistries.BLOCKS, modid); - BLOCK_REGISTRY.register(eventBus); - - DeferredRegister POI_REGISTRY = DeferredRegister.create(ForgeRegistries.POI_TYPES, modid); - POI_REGISTRY.register(eventBus); - - DeferredRegister PROFESSION_REGISTRY = DeferredRegister.create(ForgeRegistries.VILLAGER_PROFESSIONS, modid); - PROFESSION_REGISTRY.register(eventBus); - - ICallBack Itemcallback = new ICallBack() { - @Override - public Object accept(Object... args) { - return ITEM_REGISTRY.register(args[0].toString(), (Supplier) args[1]); - } - }; - - ICallBack Blockcallback = new ICallBack() { - @Override - public Object accept(Object... args) { - RegistryObject b = BLOCK_REGISTRY.register(args[0].toString(), (Supplier) args[1]); - ITEM_REGISTRY.register(args[0].toString(), ()->new BlockItem(b.get(), (Item.Settings) args[2])); - return b; - } - }; - - ICallBack ItemlessBlockcallback = new ICallBack() { - @Override - public Object accept(Object... args) { - return BLOCK_REGISTRY.register(args[0].toString(), (Supplier) args[1]); - } - }; - - ICallBack POIcallback = new ICallBack() { - @Override - public Object accept(Object... args) { - return POI_REGISTRY.register(args[0].toString(), ()-> new PointOfInterestType(ImmutableSet.copyOf(((RegistryObject)args[3]).get().getStateManager().getStates()), 1,1)); - } - }; - - ICallBack Professioncallback = new ICallBack() { - @Override - public Object accept(Object... args) { - RegistryKey poi = RegistryKey.of(Registries.POINT_OF_INTEREST_TYPE.getKey(), new Identifier(modid, args[1].toString())); - return PROFESSION_REGISTRY.register(args[0].toString(), ()->new VillagerProfession(modid+"."+args[0].toString(), entry->entry.matchesKey(poi), entry->entry.matchesKey(poi), args[2] == null ? ImmutableSet.of() : ImmutableSet.copyOf(((Item[])args[2])), args[3] == null ? ImmutableSet.of() : ImmutableSet.copyOf(((Block[])args[3])), args[4] == null ? null : (SoundEvent) args[4])); - } - }; - - Registry.initRegistry(Itemcallback, RegistryTypes.ITEM, modid); - Registry.initRegistry(ItemlessBlockcallback, RegistryTypes.ITEMLESS_BLOCK, modid); - Registry.initRegistry(Blockcallback, RegistryTypes.BLOCK, modid); - Registry.initRegistry(POIcallback, RegistryTypes.POI, modid); - Registry.initRegistry(Professioncallback, RegistryTypes.PROFESSION, modid); - } - - public static void villagerTradeEventResolver(VillagerTradesEvent e, String modid) { - Registry.ForgeLikeEventResolver(e, TradeRegistryEventCallback, RegistryTypes.TRADE, modid); - } - -} diff --git a/1.20.4/forge/src/main/java/org/Vrglab/forge/VLModForge.java b/1.20.4/forge/src/main/java/org/Vrglab/forge/VLModForge.java deleted file mode 100644 index 1102547..0000000 --- a/1.20.4/forge/src/main/java/org/Vrglab/forge/VLModForge.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.Vrglab.forge; - -import net.minecraftforge.fml.common.Mod; -import org.Vrglab.Utils.Modinfo; - -@Mod(Modinfo.MOD_ID) -public final class VLModForge { - public VLModForge() { - - } -} diff --git a/1.20.4/forge/src/main/java/org/Vrglab/forge/events/VillagerTradeRegisteration.java b/1.20.4/forge/src/main/java/org/Vrglab/forge/events/VillagerTradeRegisteration.java deleted file mode 100644 index 7f21874..0000000 --- a/1.20.4/forge/src/main/java/org/Vrglab/forge/events/VillagerTradeRegisteration.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.Vrglab.forge.events; - -import net.minecraftforge.event.village.VillagerTradesEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import org.Vrglab.Utils.Modinfo; -import org.Vrglab.forge.Utils.ForgeRegistryCreator; - -@Mod.EventBusSubscriber(modid = Modinfo.MOD_ID) -public class VillagerTradeRegisteration { - - @SubscribeEvent - public static void addCustomTrades(VillagerTradesEvent e){ - ForgeRegistryCreator.villagerTradeEventResolver(e, Modinfo.MOD_ID); - } -} diff --git a/1.20.4/forge/src/main/resources/META-INF/mods.toml b/1.20.4/forge/src/main/resources/META-INF/mods.toml deleted file mode 100644 index a9d463c..0000000 --- a/1.20.4/forge/src/main/resources/META-INF/mods.toml +++ /dev/null @@ -1,35 +0,0 @@ -modLoader = "javafml" -loaderVersion = "[49,)" -issueTrackerURL = "https://github.com/vrglab/VrglabsLib/issues" -license = "MIT" - -[[mods]] -modId = "vrglabslib" -version = "1.0.0" -displayName = "Vrglabs Lib" -authors = "Vrglab" -description = ''' -Architectury based custom data Registration system and Utilities -''' -logoFile = "logo.png" - -[[dependencies.vrglabslib]] -modId = "forge" -mandatory = true -versionRange = "[49,)" -ordering = "NONE" -side = "BOTH" - -[[dependencies.vrglabslib]] -modId = "minecraft" -mandatory = true -versionRange = "[1.20.4,)" -ordering = "NONE" -side = "BOTH" - -[[dependencies.vrglabslib]] -modId = "architectury" -mandatory = true -versionRange = "[11.1.17,)" -ordering = "AFTER" -side = "BOTH" diff --git a/1.20.4/forge/src/main/resources/logo.png b/1.20.4/forge/src/main/resources/logo.png deleted file mode 100644 index eb9c833..0000000 Binary files a/1.20.4/forge/src/main/resources/logo.png and /dev/null differ diff --git a/1.20.4/forge/src/main/resources/pack.mcmeta b/1.20.4/forge/src/main/resources/pack.mcmeta deleted file mode 100644 index 15db291..0000000 --- a/1.20.4/forge/src/main/resources/pack.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pack": { - "description": "Vrglabs Lib", - "pack_format": 22 - } -} diff --git a/1.20.4/gradle.properties b/1.20.4/gradle.properties index c912b84..5269b0d 100644 --- a/1.20.4/gradle.properties +++ b/1.20.4/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true # Mod properties -mod_version = 1.0.0-mc1.20.4 +loader_safe_version=1.0.0 maven_group = org.Vrglab archives_name = vrglabslib -enabled_platforms = fabric,forge,neoforge,quilt +enabled_platforms = fabric,neoforge,quilt # Minecraft properties minecraft_version = 1.20.4 diff --git a/1.20.4/neoforge/build.gradle b/1.20.4/neoforge/build.gradle index 9380496..a24abaa 100644 --- a/1.20.4/neoforge/build.gradle +++ b/1.20.4/neoforge/build.gradle @@ -7,6 +7,21 @@ architectury { neoForge() } +loom { + runs { + // This adds a new gradle task that runs the datagen API: "gradlew runDatagen" + datagen { + inherit server + name "Data Generation" + vmArg "-Dfabric-api.datagen" + vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}" + vmArg "-Dfabric-api.datagen.modid=vrglabslib" + + runDir "build/datagen" + } + } +} + configurations { common { canBeResolved = true @@ -42,10 +57,8 @@ dependencies { } processResources { - inputs.property 'version', project.version - filesMatching('META-INF/mods.toml') { - expand version: project.version + expand rootProject.properties } } diff --git a/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/Utils/NeoForgeRegistryCreator.java b/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/Utils/NeoForgeRegistryCreator.java index 6a956db..1d432aa 100644 --- a/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/Utils/NeoForgeRegistryCreator.java +++ b/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/Utils/NeoForgeRegistryCreator.java @@ -4,10 +4,19 @@ import dev.architectury.registry.level.biome.BiomeModifications; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.block.Block; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.HandledScreens; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.RecipeType; import net.minecraft.registry.*; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; import net.minecraft.sound.SoundEvent; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOffers; @@ -34,8 +43,10 @@ import net.neoforged.neoforge.registries.NeoForgeRegistries; import org.Vrglab.Modloader.CreationHelpers.OreGenFeatCreationHelper; import org.Vrglab.Modloader.CreationHelpers.PlacementModifierCreationHelper; +import org.Vrglab.Modloader.CreationHelpers.TypeTransformer; import org.Vrglab.Modloader.Registration.Bootstrapper; import org.Vrglab.Modloader.Registration.Registry; +import org.Vrglab.Modloader.Types.IScreenHandledCreationFunction; import org.Vrglab.Modloader.enumTypes.BootstrapType; import org.Vrglab.Modloader.enumTypes.RegistryTypes; import org.Vrglab.Modloader.Types.ICallBack; @@ -65,6 +76,9 @@ public Object accept(Object... args) { public static void Create(IEventBus eventBus, String modid) { + DeferredRegister ITEM_GROUP_REGISTRY = DeferredRegister.create(Registries.ITEM_GROUP.getKey(), modid); + ITEM_GROUP_REGISTRY.register(eventBus); + DeferredRegister.Items ITEM_REGISTRY = DeferredRegister.createItems(modid); ITEM_REGISTRY.register(eventBus); @@ -77,6 +91,18 @@ public static void Create(IEventBus eventBus, String modid) { DeferredRegister PROFESSION_REGISTRY = DeferredRegister.create(Registries.VILLAGER_PROFESSION.getKey(), modid); PROFESSION_REGISTRY.register(eventBus); + DeferredRegister> RECIPE_SERIALIZER_REGISTRY = DeferredRegister.create(Registries.RECIPE_SERIALIZER.getKey(), modid); + RECIPE_SERIALIZER_REGISTRY.register(eventBus); + + DeferredRegister> RECIPE_TYPE_REGISTRY = DeferredRegister.create(Registries.RECIPE_TYPE.getKey(), modid); + RECIPE_TYPE_REGISTRY.register(eventBus); + + TypeTransformer.ObjectToType = new ICallBack() { + @Override + public Object accept(Object... args) { + return ((DeferredHolder)args[0]).get(); + } + }; OreGenFeatCreationHelper.ObjectBlockToStateConverted = new ICallBack() { @Override @@ -103,7 +129,7 @@ public Object accept(Object... args) { @Override public Object accept(Object... args) { DeferredHolder b = BLOCK_REGISTRY.register(args[0].toString(), (Supplier) args[1]); - ITEM_REGISTRY.register(args[0].toString(), ()->new BlockItem(b.get(), (Item.Settings) args[2])); + ITEM_REGISTRY.register(args[0].toString(), ()->new BlockItem(b.get(), ((Supplier) args[2]).get())); return b; } }; @@ -150,6 +176,28 @@ public Object accept(Object... args) { } }; + ICallBack RecipeSerializerRegistryCallBack = new ICallBack() { + @Override + public Object accept(Object... args) { + return RECIPE_SERIALIZER_REGISTRY.register(args[0].toString(), ()->(RecipeSerializer)args[1]); + } + }; + + ICallBack RecipeTypeRegistryCallBack = new ICallBack() { + @Override + public Object accept(Object... args) { + return RECIPE_TYPE_REGISTRY.register(args[0].toString(), ()->(RecipeType)args[1]); + } + }; + + ICallBack CreativeModeTabcallback = new ICallBack() { + @Override + public Object accept(Object... args) { + return ITEM_GROUP_REGISTRY.register(args[0].toString(), ()->(ItemGroup)args[1]); + } + }; + + Registry.initRegistry(CreativeModeTabcallback, RegistryTypes.CREATIVE_MODE_TAB, modid); Registry.initRegistry(Itemcallback, RegistryTypes.ITEM, modid); Registry.initRegistry(ItemlessBlockcallback, RegistryTypes.ITEMLESS_BLOCK, modid); Registry.initRegistry(Blockcallback, RegistryTypes.BLOCK, modid); @@ -157,10 +205,30 @@ public Object accept(Object... args) { Registry.initRegistry(Professioncallback, RegistryTypes.PROFESSION, modid); Registry.initRegistry(OreGenRegistryCallBack, RegistryTypes.CONFIGURED_FEAT_ORE, modid); Registry.initRegistry(PlacedFeatCallBack, RegistryTypes.PLACED_FEAT, modid); + Registry.initRegistry(RecipeSerializerRegistryCallBack, RegistryTypes.RECIPE_SERIALIZER, modid); + Registry.initRegistry(RecipeTypeRegistryCallBack, RegistryTypes.RECIPE_TYPE, modid); } public static void villagerTradeEventResolver(VillagerTradesEvent e, String modid) { - Registry.ForgeLikeEventResolver(e, TradeRegistryEventCallback, RegistryTypes.TRADE, modid); + Registry.ForgeEventResolver(e, TradeRegistryEventCallback, RegistryTypes.TRADE, modid); + } + + public static void CreateClient(String modid){ + ICallBack HandledScreensRegistryCallBack = new ICallBack() { + @Override + public Object accept(Object... args) { + + HandledScreens.Provider provider = new HandledScreens.Provider() { + @Override + public Screen create(ScreenHandler handler, PlayerInventory playerInventory, Text title) { + return ((IScreenHandledCreationFunction)args[2]).create((org.Vrglab.Screen.ScreenHandler) handler, playerInventory, title); + } + }; + HandledScreens.register((ScreenHandlerType)args[1], provider); + return null; + } + }; + Registry.initRegistry(HandledScreensRegistryCallBack, RegistryTypes.HANDLED_SCREEN, modid); } diff --git a/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/VLModNeoForge.java b/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/VLModNeoForge.java index a4ca2e3..2cea2a3 100644 --- a/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/VLModNeoForge.java +++ b/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/VLModNeoForge.java @@ -2,14 +2,14 @@ import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.common.Mod; -import org.Vrglab.Utils.Modinfo; +import org.Vrglab.Utils.VLModInfo; import org.Vrglab.VrglabsLib; import org.Vrglab.neoforge.Utils.NeoForgeRegistryCreator; -@Mod(Modinfo.MOD_ID) +@Mod(VLModInfo.MOD_ID) public final class VLModNeoForge { public VLModNeoForge() { - NeoForgeRegistryCreator.Create(ModLoadingContext.get().getActiveContainer().getEventBus(), Modinfo.MOD_ID); + NeoForgeRegistryCreator.Create(ModLoadingContext.get().getActiveContainer().getEventBus(), VLModInfo.MOD_ID); VrglabsLib.init(); } } diff --git a/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/events/VillagerTradeRegisteration.java b/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/events/VillagerTradeRegisteration.java index 8e3ae6b..2c67906 100644 --- a/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/events/VillagerTradeRegisteration.java +++ b/1.20.4/neoforge/src/main/java/org/Vrglab/neoforge/events/VillagerTradeRegisteration.java @@ -3,13 +3,13 @@ import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.event.village.VillagerTradesEvent; -import org.Vrglab.Utils.Modinfo; +import org.Vrglab.Utils.VLModInfo; import org.Vrglab.neoforge.Utils.NeoForgeRegistryCreator; -@Mod.EventBusSubscriber(modid = Modinfo.MOD_ID) +@Mod.EventBusSubscriber(modid = VLModInfo.MOD_ID) public class VillagerTradeRegisteration { @SubscribeEvent public static void addCustomTrades(VillagerTradesEvent e){ - NeoForgeRegistryCreator.villagerTradeEventResolver(e, Modinfo.MOD_ID); + NeoForgeRegistryCreator.villagerTradeEventResolver(e, VLModInfo.MOD_ID); } } diff --git a/1.20.4/neoforge/src/main/resources/META-INF/mods.toml b/1.20.4/neoforge/src/main/resources/META-INF/mods.toml index 1aac1f9..9718a07 100644 --- a/1.20.4/neoforge/src/main/resources/META-INF/mods.toml +++ b/1.20.4/neoforge/src/main/resources/META-INF/mods.toml @@ -5,7 +5,7 @@ license = "MIT" [[mods]] modId = "vrglabslib" -version = "1.0.0" +version = "${loader_safe_version}" displayName = "Vrglabs Lib" authors = "Vrglab" description = ''' diff --git a/1.20.4/quilt/build.gradle b/1.20.4/quilt/build.gradle index abd2ca4..b97df59 100644 --- a/1.20.4/quilt/build.gradle +++ b/1.20.4/quilt/build.gradle @@ -73,17 +73,15 @@ dependencies { } processResources { - inputs.property 'group', project.group - inputs.property 'version', project.version - filesMatching('quilt.mod.json') { - expand group: project.group, version: project.version + expand rootProject.properties } } shadowJar { - configurations = [project.configurations.shadowBundle] - archiveClassifier = 'dev-shadow' + filesMatching('quilt.mod.json') { + expand rootProject.properties + } } remapJar { diff --git a/1.20.4/quilt/src/main/java/org/Vrglab/quilt/VLDataGenerator.java b/1.20.4/quilt/src/main/java/org/Vrglab/quilt/VLDataGenerator.java index 337e02d..7c4fef7 100644 --- a/1.20.4/quilt/src/main/java/org/Vrglab/quilt/VLDataGenerator.java +++ b/1.20.4/quilt/src/main/java/org/Vrglab/quilt/VLDataGenerator.java @@ -4,7 +4,7 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.minecraft.data.DataProvider; import net.minecraft.registry.RegistryBuilder; -import org.Vrglab.Utils.Modinfo; +import org.Vrglab.Utils.VLModInfo; import org.Vrglab.fabriclike.Utils.FabricLikeRegisteryCreator; public class VLDataGenerator implements DataGeneratorEntrypoint { @@ -30,6 +30,6 @@ public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { */ @Override public void buildRegistry(RegistryBuilder registryBuilder) { - FabricLikeRegisteryCreator.boostrap(registryBuilder, Modinfo.MOD_ID); + FabricLikeRegisteryCreator.boostrap(registryBuilder, VLModInfo.MOD_ID); } } diff --git a/1.20.4/quilt/src/main/java/org/Vrglab/quilt/VLModQuilt.java b/1.20.4/quilt/src/main/java/org/Vrglab/quilt/VLModQuilt.java index cd2576e..6533aae 100644 --- a/1.20.4/quilt/src/main/java/org/Vrglab/quilt/VLModQuilt.java +++ b/1.20.4/quilt/src/main/java/org/Vrglab/quilt/VLModQuilt.java @@ -1,7 +1,6 @@ package org.Vrglab.quilt; -import net.minecraft.registry.RegistryWrapper; -import org.Vrglab.Utils.Modinfo; +import org.Vrglab.Utils.VLModInfo; import org.Vrglab.VrglabsLib; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; @@ -11,6 +10,6 @@ public final class VLModQuilt implements ModInitializer { @Override public void onInitialize(ModContainer mod) { - VLModFabricLike.init(Modinfo.MOD_ID, ()-> VrglabsLib.init()); + VLModFabricLike.init(VLModInfo.MOD_ID, ()-> VrglabsLib.init()); } } diff --git a/1.20.4/quilt/src/main/resources/quilt.mod.json b/1.20.4/quilt/src/main/resources/quilt.mod.json index 5fc17e2..088b2e9 100644 --- a/1.20.4/quilt/src/main/resources/quilt.mod.json +++ b/1.20.4/quilt/src/main/resources/quilt.mod.json @@ -3,7 +3,7 @@ "quilt_loader": { "group": "${group}", "id": "vrglabslib", - "version": "${version}", + "version": "${loader_safe_version}", "metadata": { "name": "Vrglabs Lib", "description": "Architectury based custom data Registration system and Utilities", diff --git a/1.20.4/settings.gradle b/1.20.4/settings.gradle index 6d83e49..d8492b5 100644 --- a/1.20.4/settings.gradle +++ b/1.20.4/settings.gradle @@ -12,6 +12,5 @@ rootProject.name = 'vrglabslib' include 'common' include 'fabric' include 'fabric-like' -include 'forge' include 'neoforge' include 'quilt' diff --git a/Modules/1.20.4/AzureLib/build.gradle b/Modules/1.20.4/AzureLib/build.gradle new file mode 100644 index 0000000..621123f --- /dev/null +++ b/Modules/1.20.4/AzureLib/build.gradle @@ -0,0 +1,78 @@ +plugins { + id 'dev.architectury.loom' version '1.6-SNAPSHOT' apply false + id 'architectury-plugin' version '3.4-SNAPSHOT' + id 'com.github.johnrengelman.shadow' version '8.1.1' apply false +} + +architectury { + minecraft = project.minecraft_version +} + +allprojects { + group = rootProject.maven_group + version = "$project.name-$rootProject.mod_version-mc$rootProject.minecraft_version" + repositories { + maven {url 'https://libs.azuredoom.com:4443/mods'} + maven { url "https://maven.terraformersmc.com/releases" } + maven { url "https://maven.thevrglab.com/" } + } +} + +subprojects { + apply plugin: 'dev.architectury.loom' + apply plugin: 'architectury-plugin' + apply plugin: 'maven-publish' + + base { + // Set up a suffixed format for the mod jar names, e.g. `example-fabric`. + archivesName = "$rootProject.archives_name" + } + + repositories { + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. + } + + dependencies { + minecraft "net.minecraft:minecraft:$rootProject.minecraft_version" + mappings loom.layered() { + "net.fabricmc:yarn:$rootProject.yarn_mappings:v2" + officialMojangMappings() + } + } + + java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + tasks.withType(JavaCompile).configureEach { + it.options.release = 17 + } + + // Configure Maven publishing. + publishing { + publications { + mavenJava(MavenPublication) { + artifactId = base.archivesName.get() + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } + } +} diff --git a/Modules/1.20.4/AzureLib/common/build.gradle b/Modules/1.20.4/AzureLib/common/build.gradle new file mode 100644 index 0000000..1ccbaa5 --- /dev/null +++ b/Modules/1.20.4/AzureLib/common/build.gradle @@ -0,0 +1,17 @@ +architectury { + common rootProject.enabled_platforms.split(',') +} + +dependencies { + // We depend on Fabric Loader here to use the Fabric @Environment annotations, + // which get remapped to the correct annotations on each platform. + // Do NOT use other classes from Fabric Loader. + modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version" + + modImplementation "mod.azure.azurelib:azurelib-common-1.20.4:2.1.12" + modImplementation "org.Vrglab:vrglabslib:common-$rootProject.vrglabs_lib_version-mc$rootProject.minecraft_version" + + // Architectury API. This is optional, and you can comment it out if you don't need it. + modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version" + +} diff --git a/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Armor/AzureArmor.java b/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Armor/AzureArmor.java new file mode 100644 index 0000000..980e9ed --- /dev/null +++ b/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Armor/AzureArmor.java @@ -0,0 +1,80 @@ +package org.Vrglab.AzureLib.Armor; + +import mod.azure.azurelib.common.api.client.model.GeoModel; +import mod.azure.azurelib.common.api.client.renderer.GeoArmorRenderer; +import mod.azure.azurelib.common.api.common.animatable.GeoItem; +import mod.azure.azurelib.common.internal.client.RenderProvider; +import mod.azure.azurelib.common.internal.common.core.animatable.instance.AnimatableInstanceCache; +import mod.azure.azurelib.common.internal.common.core.animation.AnimatableManager; +import mod.azure.azurelib.common.internal.common.core.animation.AnimationController; +import mod.azure.azurelib.common.internal.common.util.AzureLibUtil; +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ArmorItem; +import net.minecraft.world.item.ArmorMaterial; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.Vrglab.Modloader.Types.ICallBack; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Properties; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public abstract class AzureArmor extends ArmorItem implements GeoItem { + protected final AnimatableInstanceCache cache = AzureLibUtil.createInstanceCache(this); + protected final Supplier renderProvider = GeoItem.makeRenderer(this); + + public AzureArmor(ArmorMaterial armorMaterial, Type type, Properties properties) { + super(armorMaterial, type, properties); + } + + + @Override + public AnimatableInstanceCache getAnimatableInstanceCache() { + return cache; + } + + @Override + public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { + List controllerList = (List)getControllers().accept(controllers); + for (AnimationController controller: controllerList) { + controllers.add(controller); + } + } + + @Override + public void createRenderer(Consumer consumer) { + consumer.accept(new RenderProvider() { + private Renderer renderer; + + @Override + public @NotNull HumanoidModel getHumanoidArmorModel(LivingEntity livingEntity, ItemStack itemStack, EquipmentSlot equipmentSlot, HumanoidModel original) { + if (renderer == null) + renderer = new Renderer<>(getModel().get()); + renderer.prepForRender(livingEntity, itemStack, equipmentSlot, original); + return this.renderer; + } + }); + } + + @Override + public Supplier getRenderProvider() { + return renderProvider; + } + + /* ABSTRACT FUNCTIONS */ + public abstract ICallBack getControllers(); + public abstract Supplier> getModel(); + + + /* SUB CLASSES */ + + public class Renderer extends GeoArmorRenderer { + public Renderer(GeoModel model) { + super(model); + } + } +} diff --git a/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Block/AzureEntityBlock.java b/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Block/AzureEntityBlock.java new file mode 100644 index 0000000..830f0a9 --- /dev/null +++ b/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Block/AzureEntityBlock.java @@ -0,0 +1,42 @@ +package org.Vrglab.AzureLib.Block; + +import mod.azure.azurelib.common.api.common.animatable.GeoBlockEntity; +import mod.azure.azurelib.common.internal.common.core.animatable.instance.AnimatableInstanceCache; +import mod.azure.azurelib.common.internal.common.core.animation.AnimatableManager; +import mod.azure.azurelib.common.internal.common.core.animation.AnimationController; +import mod.azure.azurelib.common.internal.common.util.AzureLibUtil; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.state.BlockState; +import org.Vrglab.Modloader.Types.ICallBack; + +import java.util.List; + +public abstract class AzureEntityBlock extends BaseEntityBlock implements GeoBlockEntity { + protected final AnimatableInstanceCache cache = AzureLibUtil.createInstanceCache(this); + + protected AzureEntityBlock(Properties properties) { + super(properties); + } + + @Override + public AnimatableInstanceCache getAnimatableInstanceCache() { + return cache; + } + + @Override + public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { + List controllerList = (List)getControllers().accept(controllers); + for (AnimationController controller: controllerList) { + controllers.add(controller); + } + } + + @Override + public RenderShape getRenderShape(BlockState blockState) { + return RenderShape.ENTITYBLOCK_ANIMATED; + } + + /* ABSTRACT FUNCTIONS */ + public abstract ICallBack getControllers(); +} diff --git a/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Item/AzureItem.java b/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Item/AzureItem.java new file mode 100644 index 0000000..afbd03b --- /dev/null +++ b/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/Item/AzureItem.java @@ -0,0 +1,71 @@ +package org.Vrglab.AzureLib.Item; + +import mod.azure.azurelib.common.api.client.model.GeoModel; +import mod.azure.azurelib.common.api.client.renderer.GeoItemRenderer; +import mod.azure.azurelib.common.api.common.animatable.GeoItem; +import mod.azure.azurelib.common.internal.client.RenderProvider; +import mod.azure.azurelib.common.internal.common.core.animatable.instance.AnimatableInstanceCache; +import mod.azure.azurelib.common.internal.common.core.animation.AnimatableManager; +import mod.azure.azurelib.common.internal.common.core.animation.AnimationController; +import mod.azure.azurelib.common.internal.common.util.AzureLibUtil; +import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; +import net.minecraft.world.item.Item; +import org.Vrglab.Modloader.Types.ICallBack; + +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public abstract class AzureItem extends Item implements GeoItem { + protected final AnimatableInstanceCache cache = AzureLibUtil.createInstanceCache(this); + private final Supplier renderProvider = GeoItem.makeRenderer(this); + public AzureItem(Properties properties) { + super(properties); + } + + @Override + public AnimatableInstanceCache getAnimatableInstanceCache() { + return cache; + } + + @Override + public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { + List controllerList = (List)getControllers().accept(controllers); + for (AnimationController controller: controllerList) { + controllers.add(controller); + } + } + + @Override + public void createRenderer(Consumer consumer) { + consumer.accept(new RenderProvider() { + private AzureItem.Renderer renderer; + + @Override + public BlockEntityWithoutLevelRenderer getCustomRenderer() { + if (renderer == null) + renderer = new AzureItem.Renderer<>(getModel().get()); + return this.renderer; + } + }); + } + + @Override + public Supplier getRenderProvider() { + return renderProvider; + } + + + /* ABSTRACT FUNCTIONS */ + public abstract ICallBack getControllers(); + public abstract Supplier> getModel(); + + + /* SUB CLASSES */ + + public class Renderer extends GeoItemRenderer { + public Renderer(GeoModel model) { + super(model); + } + } +} diff --git a/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/VlAzureLibMod.java b/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/VlAzureLibMod.java new file mode 100644 index 0000000..e444599 --- /dev/null +++ b/Modules/1.20.4/AzureLib/common/src/main/java/org/Vrglab/AzureLib/VlAzureLibMod.java @@ -0,0 +1,11 @@ +package org.Vrglab.AzureLib; + +import mod.azure.azurelib.common.internal.common.AzureLib; + +public final class VlAzureLibMod { + public static final String MOD_ID = "vrglabs_azurelib"; + + public static void init() { + AzureLib.initialize(); + } +} diff --git a/Modules/1.20.4/AzureLib/common/src/main/resources/logo.png b/Modules/1.20.4/AzureLib/common/src/main/resources/logo.png new file mode 100644 index 0000000..797b266 Binary files /dev/null and b/Modules/1.20.4/AzureLib/common/src/main/resources/logo.png differ diff --git a/Modules/1.20.4/AzureLib/common/src/main/resources/vrglabs_azurelib.mixins.json b/Modules/1.20.4/AzureLib/common/src/main/resources/vrglabs_azurelib.mixins.json new file mode 100644 index 0000000..5856e4e --- /dev/null +++ b/Modules/1.20.4/AzureLib/common/src/main/resources/vrglabs_azurelib.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "org.Vrglab.AzureLib.Mixins", + "compatibilityLevel": "JAVA_19", + "minVersion": "0.8", + "client": [ + ], + "mixins": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/Modules/1.20.4/AzureLib/fabric-like/build.gradle b/Modules/1.20.4/AzureLib/fabric-like/build.gradle new file mode 100644 index 0000000..c52006c --- /dev/null +++ b/Modules/1.20.4/AzureLib/fabric-like/build.gradle @@ -0,0 +1,15 @@ +architectury { + common rootProject.enabled_platforms.split(',') +} + +dependencies { + modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version" + modImplementation "net.fabricmc.fabric-api:fabric-api:$rootProject.fabric_api_version" + modImplementation "mod.azure.azurelib:azurelib-fabric-1.20.4:2.1.12" + modImplementation "org.Vrglab:vrglabslib:fabric-like-$rootProject.vrglabs_lib_version-mc$rootProject.minecraft_version" + + // Architectury API. This is optional, and you can comment it out if you don't need it. + modImplementation "dev.architectury:architectury-fabric:$rootProject.architectury_api_version" + + compileOnly(project(path: ':common', configuration: 'namedElements')) { transitive false } +} diff --git a/Modules/1.20.4/AzureLib/fabric-like/src/main/java/org/Vrglab/AzureLib/fabriclike/VlAzureLibModFabricLike.java b/Modules/1.20.4/AzureLib/fabric-like/src/main/java/org/Vrglab/AzureLib/fabriclike/VlAzureLibModFabricLike.java new file mode 100644 index 0000000..1250568 --- /dev/null +++ b/Modules/1.20.4/AzureLib/fabric-like/src/main/java/org/Vrglab/AzureLib/fabriclike/VlAzureLibModFabricLike.java @@ -0,0 +1,9 @@ +package org.Vrglab.AzureLib.fabriclike; + +import org.Vrglab.AzureLib.VlAzureLibMod; + +public final class VlAzureLibModFabricLike { + public static void init() { + VlAzureLibMod.init(); + } +} diff --git a/Modules/1.20.4/AzureLib/fabric/build.gradle b/Modules/1.20.4/AzureLib/fabric/build.gradle new file mode 100644 index 0000000..6494cc0 --- /dev/null +++ b/Modules/1.20.4/AzureLib/fabric/build.gradle @@ -0,0 +1,57 @@ +plugins { + id 'com.github.johnrengelman.shadow' +} + +architectury { + platformSetupLoomIde() + fabric() +} + +configurations { + common { + canBeResolved = true + canBeConsumed = false + } + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentFabric.extendsFrom common + + // Files in this configuration will be bundled into your mod using the Shadow plugin. + // Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files. + shadowBundle { + canBeResolved = true + canBeConsumed = false + } +} + +dependencies { + modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version" + + // Fabric API. This is technically optional, but you probably want it anyway. + modImplementation "net.fabricmc.fabric-api:fabric-api:$rootProject.fabric_api_version" + modImplementation "mod.azure.azurelib:azurelib-fabric-1.20.4:2.1.12" + + // Architectury API. This is optional, and you can comment it out if you don't need it. + modImplementation "dev.architectury:architectury-fabric:$rootProject.architectury_api_version" + modImplementation "org.Vrglab:vrglabslib:fabric-$rootProject.vrglabs_lib_version-mc$rootProject.minecraft_version" + + common(project(path: ':common', configuration: 'namedElements')) { transitive false } + shadowBundle project(path: ':common', configuration: 'transformProductionFabric') + common(project(path: ':fabric-like', configuration: 'namedElements')) { transitive false } + shadowBundle project(path: ':fabric-like', configuration: 'transformProductionFabric') +} + +processResources { + filesMatching('fabric.mod.json') { + expand rootProject.properties + } +} + +shadowJar { + configurations = [project.configurations.shadowBundle] + archiveClassifier = 'dev-shadow' +} + +remapJar { + input.set shadowJar.archiveFile +} diff --git a/Modules/1.20.4/AzureLib/fabric/src/main/java/org/Vrglab/AzureLib/fabric/VlAzureLibModFabric.java b/Modules/1.20.4/AzureLib/fabric/src/main/java/org/Vrglab/AzureLib/fabric/VlAzureLibModFabric.java new file mode 100644 index 0000000..62ac582 --- /dev/null +++ b/Modules/1.20.4/AzureLib/fabric/src/main/java/org/Vrglab/AzureLib/fabric/VlAzureLibModFabric.java @@ -0,0 +1,16 @@ +package org.Vrglab.AzureLib.fabric; + +import net.fabricmc.api.ModInitializer; + +import org.Vrglab.AzureLib.VlAzureLibMod; +import org.Vrglab.AzureLib.fabriclike.VlAzureLibModFabricLike; +import org.Vrglab.fabriclike.VLModFabricLike; + +public final class VlAzureLibModFabric implements ModInitializer { + @Override + public void onInitialize() { + VLModFabricLike.init(VlAzureLibMod.MOD_ID, ()->{ + VlAzureLibModFabricLike.init(); + }); + } +} diff --git a/Modules/1.20.4/AzureLib/fabric/src/main/java/org/Vrglab/AzureLib/fabric/client/VlAzureLibModFabricClient.java b/Modules/1.20.4/AzureLib/fabric/src/main/java/org/Vrglab/AzureLib/fabric/client/VlAzureLibModFabricClient.java new file mode 100644 index 0000000..db69e4d --- /dev/null +++ b/Modules/1.20.4/AzureLib/fabric/src/main/java/org/Vrglab/AzureLib/fabric/client/VlAzureLibModFabricClient.java @@ -0,0 +1,10 @@ +package org.Vrglab.AzureLib.fabric.client; + +import net.fabricmc.api.ClientModInitializer; + +public final class VlAzureLibModFabricClient implements ClientModInitializer { + @Override + public void onInitializeClient() { + // This entrypoint is suitable for setting up client-specific logic, such as rendering. + } +} diff --git a/Modules/1.20.4/AzureLib/fabric/src/main/resources/fabric.mod.json b/Modules/1.20.4/AzureLib/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..5b0ef70 --- /dev/null +++ b/Modules/1.20.4/AzureLib/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,40 @@ +{ + "schemaVersion": 1, + "id": "vrglabs_azurelib", + "version": "${mod_version}", + "name": "Vrglabs AzureLib", + "description": "Utility classes for AzureLib for using with VrglabsLib", + "authors": [ + "Vrglab" + ], + "contact": { + "homepage": "https://fabricmc.net/", + "sources": "https://github.com/FabricMC/fabric-example-mod" + }, + "license": "MIT", + "icon": "logo.png", + "environment": "*", + "entrypoints": { + "main": [ + "org.Vrglab.AzureLib.fabric.VlAzureLibModFabric" + ], + "client": [ + "org.Vrglab.AzureLib.fabric.client.VlAzureLibModFabricClient" + ] + }, + "mixins": [ + "vrglabs_azurelib.mixins.json" + ], + "depends": { + "fabricloader": ">=0.15.11", + "minecraft": "~1.20.4", + "java": ">=17", + "architectury": ">=11.1.17", + "fabric-api": "*", + "azurelib": ">=2.1.12", + "vrglabslib": ">=1.0.0" + }, + "suggests": { + "another-mod": "*" + } +} diff --git a/Modules/1.20.4/AzureLib/gradle.properties b/Modules/1.20.4/AzureLib/gradle.properties new file mode 100644 index 0000000..f3d44aa --- /dev/null +++ b/Modules/1.20.4/AzureLib/gradle.properties @@ -0,0 +1,22 @@ +# Done to increase the memory available to Gradle. +org.gradle.jvmargs=-Xmx2G +org.gradle.parallel=true + +# Mod properties +mod_version = 1.0.0 +maven_group = org.Vrglab.AzureLib +archives_name = azureLib +enabled_platforms = fabric,neoforge,quilt + +# Minecraft properties +minecraft_version = 1.20.4 +yarn_mappings = 1.20.4+build.1 + +# Dependencies +architectury_api_version = 11.1.17 +fabric_loader_version = 0.15.11 +fabric_api_version = 0.97.1+1.20.4 +neoforge_version = 20.4.234 +quilt_loader_version = 0.26.1-beta.1 +quilted_fabric_api_version = 9.0.0-alpha.8+0.97.0-1.20.4 +vrglabs_lib_version=1.0.0 diff --git a/Modules/1.20.4/AzureLib/gradle/wrapper/gradle-wrapper.jar b/Modules/1.20.4/AzureLib/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d64cd49 Binary files /dev/null and b/Modules/1.20.4/AzureLib/gradle/wrapper/gradle-wrapper.jar differ diff --git a/Modules/1.20.4/AzureLib/gradle/wrapper/gradle-wrapper.properties b/Modules/1.20.4/AzureLib/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..b82aa23 --- /dev/null +++ b/Modules/1.20.4/AzureLib/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/Modules/1.20.4/AzureLib/gradlew b/Modules/1.20.4/AzureLib/gradlew new file mode 100644 index 0000000..1aa94a4 --- /dev/null +++ b/Modules/1.20.4/AzureLib/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/Modules/1.20.4/AzureLib/gradlew.bat b/Modules/1.20.4/AzureLib/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/Modules/1.20.4/AzureLib/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/1.20.4/forge/build.gradle b/Modules/1.20.4/AzureLib/neoforge/build.gradle similarity index 64% rename from 1.20.4/forge/build.gradle rename to Modules/1.20.4/AzureLib/neoforge/build.gradle index 95bed36..8b299c2 100644 --- a/1.20.4/forge/build.gradle +++ b/Modules/1.20.4/AzureLib/neoforge/build.gradle @@ -2,15 +2,9 @@ plugins { id 'com.github.johnrengelman.shadow' } -loom { - forge { - mixinConfig "vrglabslib.mixins.json" - } -} - architectury { platformSetupLoomIde() - forge() + neoForge() } configurations { @@ -20,7 +14,7 @@ configurations { } compileClasspath.extendsFrom common runtimeClasspath.extendsFrom common - developmentForge.extendsFrom common + developmentNeoForge.extendsFrom common // Files in this configuration will be bundled into your mod using the Shadow plugin. // Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files. @@ -30,21 +24,28 @@ configurations { } } +repositories { + maven { + name = 'NeoForged' + url = 'https://maven.neoforged.net/releases' + } +} + dependencies { - forge "net.minecraftforge:forge:$rootProject.forge_version" + neoForge "net.neoforged:neoforge:$rootProject.neoforge_version" // Architectury API. This is optional, and you can comment it out if you don't need it. - modImplementation "dev.architectury:architectury-forge:$rootProject.architectury_api_version" + modImplementation "dev.architectury:architectury-neoforge:$rootProject.architectury_api_version" + modImplementation "mod.azure.azurelib:azurelib-neo-1.20.4:2.1.12" + modImplementation "org.Vrglab:vrglabslib:neoforge-$rootProject.vrglabs_lib_version-mc$rootProject.minecraft_version" common(project(path: ':common', configuration: 'namedElements')) { transitive false } - shadowBundle project(path: ':common', configuration: 'transformProductionForge') + shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge') } processResources { - inputs.property 'version', project.version - filesMatching('META-INF/mods.toml') { - expand version: project.version + expand rootProject.properties } } diff --git a/Modules/1.20.4/AzureLib/neoforge/gradle.properties b/Modules/1.20.4/AzureLib/neoforge/gradle.properties new file mode 100644 index 0000000..2e6ed76 --- /dev/null +++ b/Modules/1.20.4/AzureLib/neoforge/gradle.properties @@ -0,0 +1 @@ +loom.platform = neoforge diff --git a/Modules/1.20.4/AzureLib/neoforge/src/main/java/org/Vrglab/AzureLib/neoforge/VlAzureLibModNeoForge.java b/Modules/1.20.4/AzureLib/neoforge/src/main/java/org/Vrglab/AzureLib/neoforge/VlAzureLibModNeoForge.java new file mode 100644 index 0000000..961daf8 --- /dev/null +++ b/Modules/1.20.4/AzureLib/neoforge/src/main/java/org/Vrglab/AzureLib/neoforge/VlAzureLibModNeoForge.java @@ -0,0 +1,13 @@ +package org.Vrglab.AzureLib.neoforge; + +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.common.Mod; + +import org.Vrglab.AzureLib.VlAzureLibMod; + +@Mod(VlAzureLibMod.MOD_ID) +public final class VlAzureLibModNeoForge { + public VlAzureLibModNeoForge() { + VlAzureLibMod.init(); + } +} diff --git a/Modules/1.20.4/AzureLib/neoforge/src/main/resources/META-INF/mods.toml b/Modules/1.20.4/AzureLib/neoforge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..40edfb8 --- /dev/null +++ b/Modules/1.20.4/AzureLib/neoforge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,45 @@ +modLoader = "javafml" +loaderVersion = "[2,)" +#issueTrackerURL = "" +license = "MIT" + +[[mods]] +modId = "vrglabs_azurelib" +version = "${mod_version}" +displayName = "Vrglabs AzureLib" +authors = "Vrglab" +description = ''' +Utility classes for AzureLib for using with VrglabsLib +''' +logoFile = "logo.png" + +[[dependencies.vrglabs_azurelib]] +modId = "neoforge" +type = "required" +versionRange = "[20.4,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.vrglabs_azurelib]] +modId = "minecraft" +type = "required" +versionRange = "[1.20.4,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.vrglabs_azurelib]] +modId = "architectury" +type = "required" +versionRange = "[11.1.17,)" +ordering = "AFTER" +side = "BOTH" + +[[dependencies.vrglabs_azurelib]] +modId = "azurelib" +type = "required" +versionRange = "[2.1.12,)" +ordering = "AFTER" +side = "BOTH" + +#[[mixins]] +#config = "vrglabs_azurelib.mixins.json" diff --git a/Modules/1.20.4/AzureLib/quilt/build.gradle b/Modules/1.20.4/AzureLib/quilt/build.gradle new file mode 100644 index 0000000..8a06b3f --- /dev/null +++ b/Modules/1.20.4/AzureLib/quilt/build.gradle @@ -0,0 +1,65 @@ +plugins { + id 'com.github.johnrengelman.shadow' +} + +repositories { + maven { url 'https://maven.quiltmc.org/repository/release/' } +} + +architectury { + platformSetupLoomIde() + loader('quilt') +} + +configurations { + common { + canBeResolved = true + canBeConsumed = false + } + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentQuilt.extendsFrom common + + // Files in this configuration will be bundled into your mod using the Shadow plugin. + // Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files. + shadowBundle { + canBeResolved = true + canBeConsumed = false + } +} + +dependencies { + modImplementation "org.quiltmc:quilt-loader:$rootProject.quilt_loader_version" + + // Quilt Standard Libraries and QSL. + modImplementation "org.quiltmc.quilted-fabric-api:quilted-fabric-api:$rootProject.quilted_fabric_api_version" + + modImplementation "org.Vrglab:vrglabslib:quilt-$rootProject.vrglabs_lib_version-mc$rootProject.minecraft_version" + + // Architectury API. This is optional, and you can comment it out if you don't need it. + modImplementation("dev.architectury:architectury-fabric:$rootProject.architectury_api_version") { + // We must not pull Fabric Loader and Fabric API from Architectury Fabric. + exclude group: 'net.fabricmc' + exclude group: 'net.fabricmc.fabric-api' + } + + common(project(path: ':common', configuration: 'namedElements')) { transitive false } + shadowBundle project(path: ':common', configuration: 'transformProductionQuilt') + common(project(path: ':fabric-like', configuration: 'namedElements')) { transitive false } + shadowBundle project(path: ':fabric-like', configuration: 'transformProductionQuilt') +} + +processResources { + filesMatching('quilt.mod.json') { + expand rootProject.properties + } +} + +shadowJar { + configurations = [project.configurations.shadowBundle] + archiveClassifier = 'dev-shadow' +} + +remapJar { + input.set shadowJar.archiveFile +} diff --git a/Modules/1.20.4/AzureLib/quilt/gradle.properties b/Modules/1.20.4/AzureLib/quilt/gradle.properties new file mode 100644 index 0000000..56fe802 --- /dev/null +++ b/Modules/1.20.4/AzureLib/quilt/gradle.properties @@ -0,0 +1 @@ +loom.platform = quilt diff --git a/Modules/1.20.4/AzureLib/quilt/src/main/java/org/Vrglab/AzureLib/quilt/VlAzureLibModQuilt.java b/Modules/1.20.4/AzureLib/quilt/src/main/java/org/Vrglab/AzureLib/quilt/VlAzureLibModQuilt.java new file mode 100644 index 0000000..7e74987 --- /dev/null +++ b/Modules/1.20.4/AzureLib/quilt/src/main/java/org/Vrglab/AzureLib/quilt/VlAzureLibModQuilt.java @@ -0,0 +1,17 @@ +package org.Vrglab.AzureLib.quilt; + +import org.Vrglab.AzureLib.VlAzureLibMod; +import org.Vrglab.fabriclike.VLModFabricLike; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; + +import org.Vrglab.AzureLib.fabriclike.VlAzureLibModFabricLike; + +public final class VlAzureLibModQuilt implements ModInitializer { + @Override + public void onInitialize(ModContainer mod) { + VLModFabricLike.init(VlAzureLibMod.MOD_ID, ()->{ + VlAzureLibModFabricLike.init(); + }); + } +} diff --git a/Modules/1.20.4/AzureLib/quilt/src/main/resources/quilt.mod.json b/Modules/1.20.4/AzureLib/quilt/src/main/resources/quilt.mod.json new file mode 100644 index 0000000..31dfb6c --- /dev/null +++ b/Modules/1.20.4/AzureLib/quilt/src/main/resources/quilt.mod.json @@ -0,0 +1,43 @@ +{ + "schema_version": 1, + "quilt_loader": { + "group": "${group}", + "id": "vrglabs_azurelib", + "version": "${mod_version}", + "metadata": { + "name": "Vrglabs AzureLib", + "description": "Utility classes for AzureLib for using with VrglabsLib", + "contributors": { + "Vrglab": "Author" + }, + "icon": "logo.png" + }, + "intermediate_mappings": "net.fabricmc:intermediary", + "entrypoints": { + "init": [ + "org.Vrglab.AzureLib.quilt.VlAzureLibModQuilt" + ] + }, + "depends": [ + { + "id": "quilt_loader", + "version": "*" + }, + { + "id": "quilt_base", + "version": "*" + }, + { + "id": "minecraft", + "version": ">=1.20.4" + }, + { + "id": "architectury", + "version": ">=11.1.17" + } + ] + }, + "mixin": [ + + ] +} diff --git a/Modules/1.20.4/AzureLib/settings.gradle b/Modules/1.20.4/AzureLib/settings.gradle new file mode 100644 index 0000000..076a348 --- /dev/null +++ b/Modules/1.20.4/AzureLib/settings.gradle @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + maven { url "https://maven.fabricmc.net/" } + maven { url "https://maven.architectury.dev/" } + maven { url "https://files.minecraftforge.net/maven/" } + gradlePluginPortal() + } +} + +rootProject.name = 'vrglabs_azurelib' + +include 'common' +include 'fabric' +include 'fabric-like' +include 'neoforge' +include 'quilt'