diff --git a/dependencies.gradle b/dependencies.gradle index 7eea75bce..2b8fee0ab 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -65,4 +65,6 @@ dependencies { compileOnly rfg.deobf("curse.maven:bubbles-a-baubles-fork-995393:5719448") compileOnly rfg.deobf("curse.maven:barrels-drums-storage-more-319404:2708193") + + api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700") } diff --git a/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java b/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java new file mode 100644 index 000000000..aae5ae1c3 --- /dev/null +++ b/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java @@ -0,0 +1,63 @@ +package supersymmetry.api.recipes; + +import gregtech.api.recipes.Recipe; +import gregtech.api.recipes.RecipeBuilder; +import gregtech.api.recipes.RecipeMap; +import gregtech.api.recipes.builders.SimpleRecipeBuilder; +import gregtech.api.recipes.category.GTRecipeCategory; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +public class RecipeMapGroup> extends RecipeMap { + + protected final RecipeMap[] recipeMaps; + + protected RecipeMapGroup(@NotNull String unlocalizedName, int maxInputs, int maxOutputs, int maxFluidInputs, int maxFluidOutputs, @NotNull R defaultRecipeBuilder, boolean isHidden, @NotNull RecipeMap[] recipeMaps) { + super(unlocalizedName, maxInputs, maxOutputs, maxFluidInputs, maxFluidOutputs, defaultRecipeBuilder, isHidden); + this.recipeMaps = recipeMaps; + } + + @Nonnull + public static RecipeMapGroup create(@NotNull String unlocalizedName, @NotNull RecipeMap... recipeMaps) { + int maxInputs = 0, maxOutputs = 0, maxFluidInputs = 0, maxFluidOutputs = 0; + for (RecipeMap recipeMap : recipeMaps) { + maxInputs = Math.max(maxInputs, recipeMap.getMaxInputs()); + maxOutputs = Math.max(maxOutputs, recipeMap.getMaxOutputs()); + maxFluidInputs = Math.max(maxFluidInputs, recipeMap.getMaxFluidInputs()); + maxFluidOutputs = Math.max(maxFluidOutputs, recipeMap.getMaxFluidOutputs()); + } + return new RecipeMapGroup<>(unlocalizedName, maxInputs, maxOutputs, maxFluidInputs, maxFluidOutputs, new SimpleRecipeBuilder(), true, recipeMaps); + } + + @Nullable + @Override + public Recipe findRecipe(long voltage, List inputs, List fluidInputs, boolean exactVoltage) { + AtomicReference recipe = new AtomicReference<>(); + Arrays.stream(recipeMaps) + .parallel() + .map(recipeMap -> recipeMap.findRecipe(voltage, inputs, fluidInputs, exactVoltage)) + .filter(java.util.Objects::nonNull) + .findFirst().ifPresent(recipe::set); + return recipe.get(); + } + + @Nonnull + @Override + public Map> getRecipesByCategory() { + Map> res = new Object2ObjectOpenHashMap<>(); + for (RecipeMap recipeMap : recipeMaps) { + res.putAll(recipeMap.getRecipesByCategory()); + } + return Collections.unmodifiableMap(res); + } +} diff --git a/src/main/java/supersymmetry/common/CommonProxy.java b/src/main/java/supersymmetry/common/CommonProxy.java index 0cfd35adf..72163e39d 100644 --- a/src/main/java/supersymmetry/common/CommonProxy.java +++ b/src/main/java/supersymmetry/common/CommonProxy.java @@ -1,11 +1,13 @@ package supersymmetry.common; import gregtech.api.block.VariantItemBlock; +import gregtech.api.modules.ModuleContainerRegistryEvent; import gregtech.api.unification.material.event.MaterialEvent; import gregtech.api.unification.material.event.PostMaterialEvent; import gregtech.client.utils.TooltipHelper; import gregtech.common.blocks.BlockWireCoil; import gregtech.common.items.MetaItems; +import gregtech.modules.ModuleManager; import net.minecraft.block.Block; import net.minecraft.client.resources.I18n; import net.minecraft.entity.monster.EntityZombie; @@ -38,6 +40,7 @@ import supersymmetry.loaders.SuSyWorldLoader; import supersymmetry.loaders.SusyOreDictionaryLoader; import supersymmetry.loaders.recipes.SuSyRecipeLoader; +import supersymmetry.modules.SuSyModules; import java.util.Objects; import java.util.function.Function; @@ -172,6 +175,12 @@ public static void registerRecipes(RegistryEvent.Register event) { SuSyRecipeLoader.init(); } + @SubscribeEvent + public static void registerModuleContainer(ModuleContainerRegistryEvent event) { + ModuleManager.getInstance().registerContainer(new SuSyModules()); + } + + private static ItemBlock createItemBlock(T block, Function producer) { ItemBlock itemBlock = producer.apply(block); itemBlock.setRegistryName(Objects.requireNonNull(block.getRegistryName())); diff --git a/src/main/java/supersymmetry/integration/bubbles/BaublesModule.java b/src/main/java/supersymmetry/integration/baubles/BaublesModule.java similarity index 73% rename from src/main/java/supersymmetry/integration/bubbles/BaublesModule.java rename to src/main/java/supersymmetry/integration/baubles/BaublesModule.java index 51b4e54b6..0bd3270c8 100644 --- a/src/main/java/supersymmetry/integration/bubbles/BaublesModule.java +++ b/src/main/java/supersymmetry/integration/baubles/BaublesModule.java @@ -1,15 +1,17 @@ -package supersymmetry.integration.bubbles; +package supersymmetry.integration.baubles; import baubles.api.BaubleType; -import gregtech.api.GTValues; import gregtech.api.modules.GregTechModule; import gregtech.common.items.MetaItems; import gregtech.integration.IntegrationSubmodule; import net.minecraft.item.Item; import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.jetbrains.annotations.NotNull; +import supersymmetry.Supersymmetry; +import supersymmetry.api.SusyLog; import supersymmetry.common.item.behavior.ArmorBaubleBehavior; import supersymmetry.modules.SuSyModules; @@ -17,11 +19,11 @@ import java.util.List; @GregTechModule( - moduleID = SuSyModules.MODULE_BUBBLES, - containerID = GTValues.MODID, + moduleID = SuSyModules.MODULE_BAUBLES, + containerID = Supersymmetry.MODID, modDependencies = "baubles", name = "SuSy Baubles Integration", - description = "Baubles Integration Module") + description = "SuSy Baubles Integration Module") public class BaublesModule extends IntegrationSubmodule { @SubscribeEvent(priority = EventPriority.LOW) @@ -36,4 +38,9 @@ public static void registerItems(RegistryEvent.Register event) { public List> getEventBusSubscribers() { return Collections.singletonList(BaublesModule.class); } + + @Override + public void init(FMLInitializationEvent event) { + SusyLog.logger.info("Baubles found. Enabling integration..."); + } } diff --git a/src/main/java/supersymmetry/integration/bdsandm/BDSAndMModule.java b/src/main/java/supersymmetry/integration/bdsandm/BDSAndMModule.java index fde2c0eff..df1365bd0 100644 --- a/src/main/java/supersymmetry/integration/bdsandm/BDSAndMModule.java +++ b/src/main/java/supersymmetry/integration/bdsandm/BDSAndMModule.java @@ -1,24 +1,21 @@ package supersymmetry.integration.bdsandm; -import funwayguy.bdsandm.blocks.tiles.TileEntityBarrel; import funwayguy.bdsandm.core.BDSM; -import gregtech.api.GTValues; import gregtech.api.cover.CoverRayTracer; import gregtech.api.modules.GregTechModule; import gregtech.common.items.tool.rotation.CustomBlockRotations; import gregtech.common.items.tool.rotation.ICustomRotationBehavior; import gregtech.integration.IntegrationSubmodule; import net.minecraft.block.BlockDirectional; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import supersymmetry.Supersymmetry; +import supersymmetry.api.SusyLog; import supersymmetry.modules.SuSyModules; -import java.util.Objects; - @GregTechModule( moduleID = SuSyModules.MODULE_BDSAndM, - containerID = GTValues.MODID, + containerID = Supersymmetry.MODID, modDependencies = "bdsandm", name = "SuSy BDSAndM Integration", description = "BDSAndM Integration Module") @@ -29,21 +26,15 @@ public class BDSAndMModule extends IntegrationSubmodule { if (gridSide == null) return false; gridSide = gridSide.getOpposite(); // IDK what's happening here, blame the original author if (gridSide != state.getValue(BlockDirectional.FACING)) { - TileEntityBarrel barrel = ((TileEntityBarrel) world.getTileEntity(pos)); - if (barrel != null) { - state = state.withProperty(BlockDirectional.FACING, gridSide); - NBTTagCompound tagCompound = barrel.writeToNBT(new NBTTagCompound()); - world.setBlockState(pos, state); - Objects.requireNonNull(world.getTileEntity(pos)).readFromNBT(tagCompound); - return true; - } + world.setBlockState(pos, state.withProperty(BlockDirectional.FACING, gridSide)); + return true; } return false; }; @Override public void init(FMLInitializationEvent event) { - getLogger().info("BDSAndM found. Enabling integration..."); + SusyLog.logger.info("BDSAndM found. Enabling integration..."); CustomBlockRotations.registerCustomRotation(BDSM.blockMetalBarrel, BDSAndM_BARREL_BEHAVIOR); CustomBlockRotations.registerCustomRotation(BDSM.blockWoodBarrel, BDSAndM_BARREL_BEHAVIOR); } diff --git a/src/main/java/supersymmetry/mixins/bdsandm/TileEntityBarrelMixin.java b/src/main/java/supersymmetry/mixins/bdsandm/TileEntityBarrelMixin.java new file mode 100644 index 000000000..6d6f9acb1 --- /dev/null +++ b/src/main/java/supersymmetry/mixins/bdsandm/TileEntityBarrelMixin.java @@ -0,0 +1,18 @@ +package supersymmetry.mixins.bdsandm; + +import funwayguy.bdsandm.blocks.tiles.TileEntityBarrel; +import net.minecraft.block.state.IBlockState; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(TileEntityBarrel.class) +public abstract class TileEntityBarrelMixin extends TileEntity { + + @Override + public boolean shouldRefresh(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState oldState, @NotNull IBlockState newSate) { + return oldState.getBlock() != newSate.getBlock(); + } +} diff --git a/src/main/java/supersymmetry/modules/SuSyCoreModule.java b/src/main/java/supersymmetry/modules/SuSyCoreModule.java new file mode 100644 index 000000000..7e11fe00d --- /dev/null +++ b/src/main/java/supersymmetry/modules/SuSyCoreModule.java @@ -0,0 +1,22 @@ +package supersymmetry.modules; + +import gregtech.api.modules.GregTechModule; +import gregtech.api.modules.IGregTechModule; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import supersymmetry.Supersymmetry; +import supersymmetry.api.SusyLog; + +@GregTechModule( + moduleID = SuSyModules.MODULE_CORE, + containerID = Supersymmetry.MODID, + name = "SuSy Core", + description = "Core module of SuSy Core, so this should call SuSy Core Core ngl.", + coreModule = true) +public class SuSyCoreModule implements IGregTechModule { + + @Override + public @NotNull Logger getLogger() { + return SusyLog.logger; + } +} diff --git a/src/main/java/supersymmetry/modules/SuSyModules.java b/src/main/java/supersymmetry/modules/SuSyModules.java index fa001a8d1..3924cd29a 100644 --- a/src/main/java/supersymmetry/modules/SuSyModules.java +++ b/src/main/java/supersymmetry/modules/SuSyModules.java @@ -1,12 +1,15 @@ package supersymmetry.modules; import gregtech.api.modules.IModuleContainer; +import gregtech.api.modules.ModuleContainer; import supersymmetry.Supersymmetry; +@ModuleContainer public class SuSyModules implements IModuleContainer { + public static final String MODULE_CORE = "susy_core"; public static final String MODULE_BDSAndM = "bdsandm_integration"; - public static final String MODULE_BUBBLES = "baubles_integration"; + public static final String MODULE_BAUBLES = "baubles_integration"; @Override public String getID() { diff --git a/src/main/resources/mixins.susy.bdsandm.json b/src/main/resources/mixins.susy.bdsandm.json index 8eba3bb30..3e409716d 100644 --- a/src/main/resources/mixins.susy.bdsandm.json +++ b/src/main/resources/mixins.susy.bdsandm.json @@ -6,6 +6,7 @@ "compatibilityLevel" : "JAVA_8", "mixins" : [ "BlockBarrelBaseMixin", - "ItemBarrelMixin" + "ItemBarrelMixin", + "TileEntityBarrelMixin" ] }