Skip to content

Commit

Permalink
MI Compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Leclowndu93150 committed Oct 7, 2024
1 parent aaa5f07 commit 62f46bc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ public MorePlatesMod(IEventBus modEventBus, ModContainer modContainer) {
modEventBus.addListener(MorePlatesMod::onCreativeTab);
DynamicResourcePack.init();
DynamicDataPack.INSTANCE.register();
/*
if(ModList.get().isLoaded("modern_industrialization")) {
LOGGER.info("Modern Industrialization detected, adding compatibility");
LOGGER.info("Modern Industrialization detected, adding recipes !");
MIDynamicDataPack.INSTANCE.register();
}
*/
}

public static void onCreativeTab(BuildCreativeModeTabContentsEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.portingdeadmods.moreplates.datagen.compat;
import aztech.modern_industrialization.MIFluids;
import aztech.modern_industrialization.machines.init.MIMachineRecipeTypes;
import aztech.modern_industrialization.machines.recipe.MachineRecipeBuilder;
import aztech.modern_industrialization.machines.recipe.MachineRecipeType;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void regenerateDynamicAssets(ResourceManager manager) {

Item inputItem = BuiltInRegistries.ITEM.get(inputIngot);

MachineRecipeBuilder recipeBuilder = new MachineRecipeBuilder(MIMachineRecipeTypes.COMPRESSOR, 16, 100)
MachineRecipeBuilder recipeBuilder = new MachineRecipeBuilder(MIMachineRecipeTypes.COMPRESSOR, 2, 400)
.addItemInput((ItemLike) inputItem,1)
.addItemOutput(item, 1);

Expand All @@ -75,9 +76,11 @@ public void regenerateDynamicAssets(ResourceManager manager) {

@Override
public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?> recipe, @Nullable AdvancementHolder advancementHolder, ICondition... iConditions) {
//Change namespace from modern_industrialization to moreplates
resourceLocation = ResourceLocation.fromNamespaceAndPath(MorePlatesMod.MODID, resourceLocation.getPath());
dynamicPack.addRecipe(recipe, resourceLocation);
}
},"compressor/moreplates/"+itemId.getPath());
}, "compressor/"+itemId.getPath());
}

// Gears
Expand All @@ -88,9 +91,10 @@ public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?

Item inputItem = BuiltInRegistries.ITEM.get(inputIngot);

MachineRecipeBuilder recipeBuilder = new MachineRecipeBuilder(MIMachineRecipeTypes.ASSEMBLER, 16, 100)
MachineRecipeBuilder recipeBuilder = new MachineRecipeBuilder(MIMachineRecipeTypes.ASSEMBLER, 2, 200)
.addItemInput((ItemLike) inputItem,4)
.addItemOutput(item, 1);
.addFluidInput(MIFluids.SOLDERING_ALLOY, 100)
.addItemOutput(item, 2);

recipeBuilder.offerTo(new RecipeOutput() {
@Override
Expand All @@ -100,9 +104,11 @@ public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?

@Override
public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?> recipe, @Nullable AdvancementHolder advancementHolder, ICondition... iConditions) {
//Change namespace from modern_industrialization to moreplates
resourceLocation = ResourceLocation.fromNamespaceAndPath(MorePlatesMod.MODID, resourceLocation.getPath());
dynamicPack.addRecipe(recipe, resourceLocation);
}
},"assembler/moreplates/"+itemId.getPath());
}, "assembler/"+itemId.getPath());
}

// Rods
Expand All @@ -113,26 +119,25 @@ public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?

Item inputItem = BuiltInRegistries.ITEM.get(inputIngot);

MachineRecipeBuilder recipeBuilder = new MachineRecipeBuilder(MIMachineRecipeTypes.CUTTING_MACHINE, 2, 200)
.addItemInput((ItemLike) inputItem,2)
.addFluidInput(MIFluids.LUBRICANT, 1)
.addItemOutput(item, 2);

ShapedRecipeBuilder recipeBuilder = ShapedRecipeBuilder.shaped(RecipeCategory.MISC, item, 2)
.pattern("H")
.pattern("I")
.pattern("I")
.define('H', MPItems.HAMMER)
.define('I', inputItem)
.unlockedBy("has_item", InventoryChangeTrigger.TriggerInstance.hasItems(inputItem));

recipeBuilder.save(new RecipeOutput() {
recipeBuilder.offerTo(new RecipeOutput() {
@Override
public Advancement.@NotNull Builder advancement() {
return Advancement.Builder.advancement();
}

@Override
public void accept(@NotNull ResourceLocation resourceLocation, @NotNull Recipe<?> recipe, @Nullable AdvancementHolder advancementHolder, ICondition... iConditions) {
//Change namespace from modern_industrialization to moreplates
resourceLocation = ResourceLocation.fromNamespaceAndPath(MorePlatesMod.MODID, resourceLocation.getPath());
dynamicPack.addRecipe(recipe, resourceLocation);
}
});
}, "cutting_machine/"+itemId.getPath());

}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private static class ItemRegistrationCallback implements AddCallback<Item> {
@Override
public void onAdd(Registry<Item> registry, int id, ResourceKey<Item> key, Item value) {
ResourceLocation itemId = key.location();

registerPlateFor(itemId, false, (plateId, plate) -> Registry.register(registry, plateId, plate));
registerGearFor(itemId, false, (gearId, gear) -> Registry.register(registry, gearId, gear));
registerRodFor(itemId, false, (rodId, rod) -> Registry.register(registry, rodId, rod));
Expand All @@ -44,7 +45,7 @@ public static void onRegisterItems(RegisterEvent event) {
}

private static void registerPlateFor(ResourceLocation id, boolean onlyVanilla, BiConsumer<ResourceLocation, Item> regCallback) {
if (!MorePlatesMod.MODID.equals(id.getNamespace()) && IngotUtil.isValidIngot(id, onlyVanilla)) {
if (!MorePlatesMod.MODID.equals(id.getNamespace()) && IngotUtil.isValidIngotPlate(id, onlyVanilla)) {
String ingotType = IngotUtil.getIngotType(id);
ItemUtil.registerPlateIfNotYetDone(ingotType, id, regCallback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import net.minecraft.resources.ResourceLocation;

public class IngotUtil {

public static boolean isValidIngotPlate(ResourceLocation location, boolean onlyVanilla) {
String path = location.getPath();
return !path.contains("_hot") && (path.startsWith("ingot_") || path.endsWith("_ingot")) && !path.contains("block") && (!onlyVanilla || "minecraft".equals(location.getNamespace()));
}

public static boolean isValidIngot(ResourceLocation location, boolean onlyVanilla) {
String path = location.getPath();
return (path.startsWith("ingot_") || path.endsWith("_ingot")) && !path.contains("block") && (!onlyVanilla || "minecraft".equals(location.getNamespace()));
return !path.contains("_double_") && !path.contains("_hot") && (path.startsWith("ingot_") || path.endsWith("_ingot")) && !path.contains("block") && (!onlyVanilla || "minecraft".equals(location.getNamespace()));
}

public static String getIngotType(ResourceLocation itemId) {
Expand Down

0 comments on commit 62f46bc

Please sign in to comment.