Skip to content

Commit

Permalink
Switch to generalised item definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed May 16, 2022
1 parent e843209 commit 36cf509
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 138 deletions.
11 changes: 9 additions & 2 deletions src/main/java/ninety/megacells/MEGACells.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ninety.megacells;

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 @@ -9,18 +11,23 @@

import ninety.megacells.datagen.MEGADataGenerators;
import ninety.megacells.init.InitCellModels;
import ninety.megacells.init.InitItems;
import ninety.megacells.init.InitUpgrades;
import ninety.megacells.init.client.InitItemColors;
import ninety.megacells.item.MEGAItems;

@Mod(MEGACells.MODID)
public class MEGACells {

public static final String MODID = "megacells";

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

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

bus.addGenericListener(Item.class, InitItems::register);

bus.addListener(MEGADataGenerators::onGatherData);
bus.addListener((FMLCommonSetupEvent event) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import ninety.megacells.MEGACells;
import ninety.megacells.integration.appmek.ChemicalCellType;
import ninety.megacells.item.util.MEGACellType;
import ninety.megacells.util.MEGACellsUtil;

import appeng.core.AppEng;

Expand All @@ -29,7 +28,7 @@ protected void registerModels() {
MEGACellType.ITEM.getCells().stream(),
MEGACellType.FLUID.getCells().stream(),
ChemicalCellType.TYPE.getCells().stream()).flatMap(s -> s).toList()) {
String path = "block/drive/cells/" + MEGACellsUtil.getItemPath(cell);
String path = "block/drive/cells/" + cell.getRegistryName().getPath();
withExistingParent(path, DRIVE_CELL).texture("cell", path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import ninety.megacells.item.MEGAItems;
import ninety.megacells.item.util.MEGACellTier;
import ninety.megacells.item.util.MEGACellType;
import ninety.megacells.util.MEGACellsUtil;

import appeng.core.AppEng;

Expand All @@ -31,9 +30,9 @@ public MEGAItemModelProvider(DataGenerator generator, ExistingFileHelper existin

@Override
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.MEGA_ITEM_CELL_HOUSING.asItem());
flatSingleLayer(MEGAItems.MEGA_FLUID_CELL_HOUSING.asItem());
flatSingleLayer(MEGAItems.MEGA_CHEMICAL_CELL_HOUSING.asItem());

for (var tier : MEGACellTier.values()) {
flatSingleLayer(tier.getComponent());
Expand Down Expand Up @@ -62,7 +61,7 @@ protected void portable(Item cell) {
}

protected ItemModelBuilder flatSingleLayer(Item item) {
String path = MEGACellsUtil.getItemPath(item);
return singleTexture(path, mcLoc("item/generated"), "layer0", MEGACellsUtil.makeId("item/" + path));
String path = MEGAItems.getItemPath(item);
return singleTexture(path, mcLoc("item/generated"), "layer0", MEGACells.makeId("item/" + path));
}
}
23 changes: 12 additions & 11 deletions src/main/java/ninety/megacells/datagen/MEGARecipeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
import net.minecraft.world.item.Item;

import ninety.megacells.MEGACells;
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;
import ninety.megacells.item.util.IMEGACellType;
import ninety.megacells.item.util.MEGACellTier;
import ninety.megacells.item.util.MEGACellType;
import ninety.megacells.util.MEGACellsUtil;

import appeng.core.definitions.AEBlocks;
import appeng.core.definitions.AEItems;
Expand Down Expand Up @@ -72,8 +73,8 @@ private void component(Consumer<FinishedRecipe> consumer, MEGACellTier tier, Ite
.define('b', AEItems.CALCULATION_PROCESSOR)
.define('c', preceding)
.define('d', AEBlocks.QUARTZ_VIBRANT_GLASS)
.unlockedBy("has_" + MEGACellsUtil.getItemPath(preceding), has(preceding))
.save(consumer, MEGACellsUtil.makeId("cells/" + MEGACellsUtil.getItemPath(tier.getComponent())));
.unlockedBy("has_" + MEGAItems.getItemPath(preceding), has(preceding))
.save(consumer, MEGACells.makeId("cells/" + MEGAItems.getItemPath(tier.getComponent())));
}

private void cell(Consumer<FinishedRecipe> consumer, Item cellItem) {
Expand All @@ -83,8 +84,8 @@ private void cell(Consumer<FinishedRecipe> consumer, Item cellItem) {
var housing = cell.getType().housing();
var housingMaterial = cell.getType().housingMaterial();

var componentPath = MEGACellsUtil.getItemPath(component);
var cellPath = MEGACellsUtil.getItemPath(cellItem);
var componentPath = MEGAItems.getItemPath(component);
var cellPath = MEGAItems.getItemPath(cellItem);

ShapedRecipeBuilder.shaped(cellItem)
.pattern("aba")
Expand All @@ -95,13 +96,13 @@ private 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, MEGACells.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"));
.unlockedBy("has_" + MEGAItems.getItemPath(housing), has(housing))
.save(consumer, MEGACells.makeId("cells/standard/" + cellPath + "_with_housing"));
}

private void portable(Consumer<FinishedRecipe> consumer, Item portableCellItem) {
Expand All @@ -112,9 +113,9 @@ private void portable(Consumer<FinishedRecipe> consumer, Item portableCellItem)
.requires(portableCell.tier.getComponent())
.requires(AEBlocks.DENSE_ENERGY_CELL)
.requires(housing)
.unlockedBy("has_" + MEGACellsUtil.getItemPath(housing), has(housing))
.unlockedBy("has_" + MEGAItems.getItemPath(housing), has(housing))
.unlockedBy("has_dense_energy_cell", has(AEBlocks.DENSE_ENERGY_CELL))
.save(consumer, MEGACellsUtil.makeId("cells/portable/" + MEGACellsUtil.getItemPath(portableCell)));
.save(consumer, MEGACells.makeId("cells/portable/" + MEGAItems.getItemPath(portableCell)));
}

private void housing(Consumer<FinishedRecipe> consumer, IMEGACellType type) {
Expand All @@ -127,6 +128,6 @@ private void housing(Consumer<FinishedRecipe> consumer, IMEGACellType type) {
.define('b', AEItems.SKY_DUST)
.define('d', type.housingMaterial())
.unlockedBy("has_dusts/sky_stone", has(AEItems.SKY_DUST))
.save(consumer, MEGACellsUtil.makeId("cells/" + MEGACellsUtil.getItemPath(housing)));
.save(consumer, MEGACells.makeId("cells/" + MEGAItems.getItemPath(housing)));
}
}
11 changes: 6 additions & 5 deletions src/main/java/ninety/megacells/init/InitCellModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import java.util.stream.Stream;

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

import appeng.api.client.StorageCellModels;

Expand All @@ -15,19 +16,19 @@ public static void init() {
MEGACellType.FLUID.getCells().stream(),
ChemicalCellType.TYPE.getCells().stream()).flatMap(s -> s).toList()) {
StorageCellModels.registerModel(cell,
MEGACellsUtil.makeId("block/drive/cells/" + MEGACellsUtil.getItemPath(cell)));
MEGACells.makeId("block/drive/cells/" + MEGAItems.getItemPath(cell)));
}
for (var portableItemCell : MEGACellType.ITEM.getPortableCells()) {
StorageCellModels.registerModel(portableItemCell,
MEGACellsUtil.makeId("block/drive/cells/portable_mega_item_cell"));
MEGACells.makeId("block/drive/cells/portable_mega_item_cell"));
}
for (var portableFluidCell : MEGACellType.FLUID.getPortableCells()) {
StorageCellModels.registerModel(portableFluidCell,
MEGACellsUtil.makeId("block/drive/cells/portable_mega_fluid_cell"));
MEGACells.makeId("block/drive/cells/portable_mega_fluid_cell"));
}
for (var portable : ChemicalCellType.TYPE.getPortableCells()) {
StorageCellModels.registerModel(portable,
MEGACellsUtil.makeId("block/drive/cells/portable_mega_item_cell"));
MEGACells.makeId("block/drive/cells/portable_mega_item_cell"));
}
}
}
21 changes: 21 additions & 0 deletions src/main/java/ninety/megacells/init/InitItems.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ninety.megacells.init;

import net.minecraft.world.item.Item;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.registries.IForgeRegistry;

import ninety.megacells.item.MEGAItems;

public class InitItems {
public static void init(IForgeRegistry<Item> registry) {
for (var definition : MEGAItems.getItems()) {
var item = definition.asItem();
item.setRegistryName(definition.getId());
registry.register(item);
}
}

public static void register(RegistryEvent.Register<Item> event) {
init(event.getRegistry());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum ChemicalCellType implements IMEGACellType {

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

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

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

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

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

@Override
public List<Item> getCells() {
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());
return List.of(
MEGAItems.CHEMICAL_CELL_1M.asItem(),
MEGAItems.CHEMICAL_CELL_4M.asItem(),
MEGAItems.CHEMICAL_CELL_16M.asItem(),
MEGAItems.CHEMICAL_CELL_64M.asItem(),
MEGAItems.CHEMICAL_CELL_256M.asItem());
}

@Override
public List<Item> getPortableCells() {
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());
return List.of(
MEGAItems.PORTABLE_CHEMICAL_CELL_1M.asItem(),
MEGAItems.PORTABLE_CHEMICAL_CELL_4M.asItem(),
MEGAItems.PORTABLE_CHEMICAL_CELL_16M.asItem(),
MEGAItems.PORTABLE_CHEMICAL_CELL_64M.asItem(),
MEGAItems.PORTABLE_CHEMICAL_CELL_256M.asItem());
}
}
Loading

0 comments on commit 36cf509

Please sign in to comment.