Skip to content

Commit

Permalink
Register chem cells regardless of AppMek installation
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed May 13, 2022
1 parent 956f503 commit 8a8e039
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 276 deletions.
34 changes: 14 additions & 20 deletions src/main/java/ninety/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.stream.Stream;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor;
Expand All @@ -13,7 +11,7 @@

import ninety.megacells.datagen.MEGADataGenerators;
import ninety.megacells.init.MEGACellsClient;
import ninety.megacells.integration.appmek.MEGAMekIntegration;
import ninety.megacells.integration.appmek.ChemicalCellType;
import ninety.megacells.item.MEGAItems;
import ninety.megacells.item.util.MEGACellType;
import ninety.megacells.util.MEGACellsUtil;
Expand All @@ -26,22 +24,12 @@
@Mod(MEGACells.MODID)
public class MEGACells {

public static ResourceLocation makeId(String path) {
return new ResourceLocation(MEGACells.MODID, path);
}

public static String getItemPath(Item item) {
return item.getRegistryName().getPath();
}

public static final String MODID = "megacells";

public MEGACells() {
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
MEGAItems.init(bus);

bus.addGenericListener(Item.class, MEGAMekIntegration::registerItems);

bus.addListener(MEGADataGenerators::onGatherData);
bus.addListener((FMLCommonSetupEvent event) -> {
event.enqueueWork(this::initCellModels);
Expand All @@ -52,9 +40,10 @@ public MEGACells() {
}

private void initCellModels() {
for (var cell : Stream.concat(
for (var cell : Stream.of(
MEGACellType.ITEM.getCells().stream(),
MEGACellType.FLUID.getCells().stream()).toList()) {
MEGACellType.FLUID.getCells().stream(),
ChemicalCellType.TYPE.getCells().stream()).flatMap(s -> s).toList()) {
StorageCellModels.registerModel(cell,
MEGACellsUtil.makeId("block/drive/cells/" + MEGACellsUtil.getItemPath(cell)));
}
Expand All @@ -66,7 +55,10 @@ private void initCellModels() {
StorageCellModels.registerModel(portableFluidCell,
MEGACellsUtil.makeId("block/drive/cells/portable_mega_fluid_cell"));
}
MEGAMekIntegration.initCellModels();
for (var portable : ChemicalCellType.TYPE.getPortableCells()) {
StorageCellModels.registerModel(portable,
MEGACellsUtil.makeId("block/drive/cells/portable_mega_item_cell"));
}
}

private void initUpgrades() {
Expand All @@ -80,17 +72,19 @@ private void initUpgrades() {
Upgrades.add(AEItems.VOID_CARD, itemCell, 1, storageCellGroup);
}

for (var fluidCell : MEGACellType.FLUID.getCells()) {
for (var fluidCell : Stream.concat(
MEGACellType.FLUID.getCells().stream(), ChemicalCellType.TYPE.getCells().stream()).toList()) {
Upgrades.add(AEItems.INVERTER_CARD, fluidCell, 1, storageCellGroup);
}

for (var portableCell : Stream.concat(MEGACellType.ITEM.getPortableCells().stream(),
MEGACellType.FLUID.getPortableCells().stream()).toList()) {
for (var portableCell : Stream.of(
MEGACellType.ITEM.getPortableCells().stream(),
MEGACellType.FLUID.getPortableCells().stream(),
ChemicalCellType.TYPE.getPortableCells().stream()).flatMap(s -> s).toList()) {
Upgrades.add(AEItems.FUZZY_CARD, portableCell, 1, portableCellGroup);
Upgrades.add(AEItems.INVERTER_CARD, portableCell, 1, portableCellGroup);
Upgrades.add(AEItems.ENERGY_CARD, portableCell, 2, portableCellGroup);
}
MEGAMekIntegration.initUpgrades();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraftforge.common.data.ExistingFileHelper;

import ninety.megacells.MEGACells;
import ninety.megacells.integration.appmek.ChemicalCellType;
import ninety.megacells.item.util.MEGACellType;
import ninety.megacells.util.MEGACellsUtil;

Expand All @@ -24,8 +25,10 @@ public MEGABlockModelProvider(DataGenerator generator, ExistingFileHelper existi

@Override
protected void registerModels() {
for (var cell : Stream.concat(MEGACellType.ITEM.getCells().stream(),
MEGACellType.FLUID.getCells().stream()).toList()) {
for (var cell : Stream.of(
MEGACellType.ITEM.getCells().stream(),
MEGACellType.FLUID.getCells().stream(),
ChemicalCellType.TYPE.getCells().stream()).flatMap(s -> s).toList()) {
String path = "block/drive/cells/" + MEGACellsUtil.getItemPath(cell);
withExistingParent(path, DRIVE_CELL).texture("cell", path);
}
Expand All @@ -35,5 +38,8 @@ protected void registerModels() {

String portableFluidCell = "block/drive/cells/portable_mega_fluid_cell";
withExistingParent(portableFluidCell, DRIVE_CELL).texture("cell", portableFluidCell);

String portableChemicalCell = "block/drive/cells/portable_mega_chemical_cell";
withExistingParent(portableChemicalCell, DRIVE_CELL).texture("cell", portableChemicalCell);
}
}
10 changes: 0 additions & 10 deletions src/main/java/ninety/megacells/datagen/MEGADataGenerators.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;

import ninety.megacells.MEGACells;
import ninety.megacells.integration.appmek.MEGAMekIntegration;
import ninety.megacells.integration.appmek.data.MEGAMekBlockModelProvider;
import ninety.megacells.integration.appmek.data.MEGAMekItemModelProvider;
import ninety.megacells.integration.appmek.data.MEGAMekRecipeProvider;

@Mod.EventBusSubscriber(modid = MEGACells.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class MEGADataGenerators {
Expand All @@ -23,11 +19,5 @@ public static void onGatherData(GatherDataEvent event) {
generator.addProvider(new MEGAItemModelProvider(generator, existingFileHelper));
generator.addProvider(new MEGABlockModelProvider(generator, existingFileHelper));
generator.addProvider(new MEGARecipeProvider(generator));

if (MEGAMekIntegration.isLoaded()) {
generator.addProvider(new MEGAMekItemModelProvider(generator, existingFileHelper));
generator.addProvider(new MEGAMekBlockModelProvider(generator, existingFileHelper));
generator.addProvider(new MEGAMekRecipeProvider(generator));
}
}
}
24 changes: 14 additions & 10 deletions src/main/java/ninety/megacells/datagen/MEGAItemModelProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import net.minecraftforge.common.data.ExistingFileHelper;

import ninety.megacells.MEGACells;
import ninety.megacells.integration.appmek.ChemicalCellType;
import ninety.megacells.item.MEGAItems;
import ninety.megacells.item.util.MEGACellTier;
import ninety.megacells.item.util.MEGACellType;
import ninety.megacells.util.MEGACellsUtil;

Expand All @@ -31,20 +33,22 @@ public MEGAItemModelProvider(DataGenerator generator, ExistingFileHelper existin
protected void registerModels() {
flatSingleLayer(MEGAItems.MEGA_ITEM_CELL_HOUSING.get());
flatSingleLayer(MEGAItems.MEGA_FLUID_CELL_HOUSING.get());
flatSingleLayer(MEGAItems.MEGA_CHEMICAL_CELL_HOUSING.get());

flatSingleLayer(MEGAItems.CELL_COMPONENT_1M.get());
flatSingleLayer(MEGAItems.CELL_COMPONENT_4M.get());
flatSingleLayer(MEGAItems.CELL_COMPONENT_16M.get());
flatSingleLayer(MEGAItems.CELL_COMPONENT_64M.get());
flatSingleLayer(MEGAItems.CELL_COMPONENT_256M.get());
for (var tier : MEGACellTier.values()) {
flatSingleLayer(tier.getComponent());
}

for (var storage : Stream.concat(MEGACellType.ITEM.getCells().stream(), MEGACellType.FLUID.getCells().stream())
.toList()) {
for (var storage : Stream.of(
MEGACellType.ITEM.getCells().stream(),
MEGACellType.FLUID.getCells().stream(),
ChemicalCellType.TYPE.getCells().stream()).flatMap(s -> s).toList()) {
cell(storage);
}
for (var portable : Stream
.concat(MEGACellType.ITEM.getPortableCells().stream(), MEGACellType.FLUID.getPortableCells().stream())
.toList()) {
for (var portable : Stream.of(
MEGACellType.ITEM.getPortableCells().stream(),
MEGACellType.FLUID.getPortableCells().stream(),
ChemicalCellType.TYPE.getPortableCells().stream()).flatMap(s -> s).toList()) {
portable(portable);
}
}
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/ninety/megacells/datagen/MEGARecipeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
import net.minecraft.world.item.Item;

import ninety.megacells.integration.appmek.AppMekIntegration;
import ninety.megacells.integration.appmek.ChemicalCellType;
import ninety.megacells.item.MEGAItems;
import ninety.megacells.item.MEGAPortableCell;
import ninety.megacells.item.MEGAStorageCell;
Expand Down Expand Up @@ -45,6 +47,16 @@ protected void buildCraftingRecipes(@NotNull Consumer<FinishedRecipe> consumer)
for (var portable : Stream.concat(MEGACellType.ITEM.getPortableCells().stream(), MEGACellType.FLUID.getPortableCells().stream()).toList()) {
portable(consumer, portable);
}

if (AppMekIntegration.isAppMekLoaded()) {
housing(consumer, ChemicalCellType.TYPE);
for (var chemStorage : ChemicalCellType.TYPE.getCells()) {
cell(consumer, chemStorage);
}
for (var chemPortable : ChemicalCellType.TYPE.getPortableCells()) {
portable(consumer, chemPortable);
}
}
// spotless:on
}

Expand All @@ -61,7 +73,7 @@ private void component(Consumer<FinishedRecipe> consumer, Item preceding, Item o
.save(consumer, MEGACellsUtil.makeId("cells/" + MEGACellsUtil.getItemPath(output)));
}

protected void cell(Consumer<FinishedRecipe> consumer, Item cellItem) {
private void cell(Consumer<FinishedRecipe> consumer, Item cellItem) {
var cell = (MEGAStorageCell) cellItem;

var component = cell.getTier().getComponent();
Expand All @@ -80,16 +92,16 @@ protected void cell(Consumer<FinishedRecipe> consumer, Item cellItem) {
.define('c', component)
.define('d', housingMaterial)
.unlockedBy("has_" + componentPath, has(component))
.save(consumer, MEGACellsUtil.makeId("cells/standard" + cellPath));
.save(consumer, MEGACellsUtil.makeId("cells/standard/" + cellPath));
ShapelessRecipeBuilder.shapeless(cellItem)
.requires(housing)
.requires(component)
.unlockedBy("has_" + componentPath, has(component))
.unlockedBy("has_" + MEGACellsUtil.getItemPath(housing), has(housing))
.save(consumer, MEGACellsUtil.makeId("cells/standard" + cellPath + "_with_housing"));
.save(consumer, MEGACellsUtil.makeId("cells/standard/" + cellPath + "_with_housing"));
}

protected void portable(Consumer<FinishedRecipe> consumer, Item portableCellItem) {
private void portable(Consumer<FinishedRecipe> consumer, Item portableCellItem) {
var portableCell = (MEGAPortableCell) portableCellItem;
var housing = portableCell.type.housing();
ShapelessRecipeBuilder.shapeless(portableCell)
Expand All @@ -102,7 +114,7 @@ protected void portable(Consumer<FinishedRecipe> consumer, Item portableCellItem
.save(consumer, MEGACellsUtil.makeId("cells/portable/" + MEGACellsUtil.getItemPath(portableCell)));
}

protected void housing(Consumer<FinishedRecipe> consumer, IMEGACellType type) {
private void housing(Consumer<FinishedRecipe> consumer, IMEGACellType type) {
var housing = type.housing();
ShapedRecipeBuilder.shaped(type.housing())
.pattern("aba")
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/ninety/megacells/init/MEGACellsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

import ninety.megacells.integration.appmek.MEGAMekIntegration;
import ninety.megacells.integration.appmek.ChemicalCellType;
import ninety.megacells.item.MEGAPortableCell;
import ninety.megacells.item.MEGAStorageCell;
import ninety.megacells.item.util.MEGACellType;
Expand All @@ -17,16 +17,17 @@ public static void initialize() {
}

private static void initItemColors(ColorHandlerEvent.Item event) {
for (var cell : Stream.concat(
for (var cell : Stream.of(
MEGACellType.ITEM.getCells().stream(),
MEGACellType.FLUID.getCells().stream()).toList()) {
MEGACellType.FLUID.getCells().stream(),
ChemicalCellType.TYPE.getCells().stream()).flatMap(s -> s).toList()) {
event.getItemColors().register(MEGAStorageCell::getColor, cell);
}
for (var cell : Stream.concat(
for (var cell : Stream.of(
MEGACellType.ITEM.getPortableCells().stream(),
MEGACellType.FLUID.getPortableCells().stream()).toList()) {
MEGACellType.FLUID.getPortableCells().stream(),
ChemicalCellType.TYPE.getPortableCells().stream()).flatMap(s -> s).toList()) {
event.getItemColors().register(MEGAPortableCell::getColor, cell);
}
MEGAMekIntegration.initItemColors(event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ninety.megacells.integration.appmek;

import net.minecraftforge.fml.ModList;

public final class AppMekIntegration {
public static boolean isAppMekLoaded() {
return ModList.get().isLoaded("appmek");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ninety.megacells.integration.appmek;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.resources.ResourceLocation;
Expand All @@ -11,6 +10,7 @@

import me.ramidzkh.mekae2.AMMenus;
import me.ramidzkh.mekae2.ae2.MekanismKeyType;
import ninety.megacells.item.MEGAItems;
import ninety.megacells.item.util.IMEGACellType;

import appeng.api.stacks.AEKeyType;
Expand All @@ -21,7 +21,7 @@ public enum ChemicalCellType implements IMEGACellType {

@Override
public AEKeyType keyType() {
return MekanismKeyType.TYPE;
return AppMekIntegration.isAppMekLoaded() ? MekanismKeyType.TYPE : AEKeyType.fluids();
}

@Override
Expand All @@ -31,7 +31,7 @@ public String affix() {

@Override
public Item housing() {
return MEGAMekItems.MEGA_CHEMICAL_CELL_HOUSING;
return MEGAItems.MEGA_CHEMICAL_CELL_HOUSING.get();
}

@Override
Expand All @@ -41,28 +41,22 @@ public TagKey<Item> housingMaterial() {

@Override
public MenuType<MEStorageMenu> portableCellMenu() {
return AMMenus.PORTABLE_CHEMICAL_CELL_TYPE;
return AppMekIntegration.isAppMekLoaded()
? AMMenus.PORTABLE_CHEMICAL_CELL_TYPE
: MEStorageMenu.PORTABLE_FLUID_CELL_TYPE;
}

@Override
public List<Item> getCells() {
var cells = new ArrayList<Item>();
cells.add(MEGAMekItems.CHEMICAL_STORAGE_CELL_1M);
cells.add(MEGAMekItems.CHEMICAL_STORAGE_CELL_4M);
cells.add(MEGAMekItems.CHEMICAL_STORAGE_CELL_16M);
cells.add(MEGAMekItems.CHEMICAL_STORAGE_CELL_64M);
cells.add(MEGAMekItems.CHEMICAL_STORAGE_CELL_256M);
return cells;
return List.of(MEGAItems.CHEMICAL_CELL_1M.get(), MEGAItems.CHEMICAL_CELL_4M.get(),
MEGAItems.CHEMICAL_CELL_16M.get(), MEGAItems.CHEMICAL_CELL_64M.get(),
MEGAItems.CHEMICAL_CELL_256M.get());
}

@Override
public List<Item> getPortableCells() {
var cells = new ArrayList<Item>();
cells.add(MEGAMekItems.PORTABLE_CHEMICAL_CELL_1M);
cells.add(MEGAMekItems.PORTABLE_CHEMICAL_CELL_4M);
cells.add(MEGAMekItems.PORTABLE_CHEMICAL_CELL_16M);
cells.add(MEGAMekItems.PORTABLE_CHEMICAL_CELL_64M);
cells.add(MEGAMekItems.PORTABLE_CHEMICAL_CELL_256M);
return cells;
return List.of(MEGAItems.PORTABLE_CHEMICAL_CELL_1M.get(), MEGAItems.PORTABLE_CHEMICAL_CELL_4M.get(),
MEGAItems.PORTABLE_CHEMICAL_CELL_16M.get(), MEGAItems.PORTABLE_CHEMICAL_CELL_64M.get(),
MEGAItems.PORTABLE_CHEMICAL_CELL_256M.get());
}
}
Loading

0 comments on commit 8a8e039

Please sign in to comment.