Skip to content

Commit

Permalink
Cleanups + enum constants for add-on integration
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jul 29, 2023
1 parent fbb98e6 commit 666cda9
Show file tree
Hide file tree
Showing 25 changed files with 201 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import gripe._90.megacells.part.MEGAPatternProviderPart;

public final class MEGAParts {

public static void init() {
// controls static load order
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.item.MEGABulkCell;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

public class InitStorageCells {
Expand All @@ -21,7 +22,7 @@ public static void init() {
StorageCells.addCellHandler(MEGABulkCell.HANDLER);
StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, Utils.makeId("block/drive/cells/bulk_item_cell"));

if (Utils.PLATFORM.isModLoaded("appbot")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
Stream.of(AppBotItems.getCells(),
AppBotItems.getPortables()).flatMap(Collection::stream)
.forEach(c -> StorageCellModels.registerModel(c,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.ae2wt.AE2WTIntegration;
import gripe._90.megacells.integration.appbot.AppBotIntegration;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

public class InitUpgrades {
Expand Down Expand Up @@ -60,11 +61,11 @@ public static void init() {
Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, portableCell, 2, portableCellGroup);
}

if (Utils.PLATFORM.isModLoaded("ae2wtlib")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.AE2WTLIB)) {
AE2WTIntegration.initUpgrades();
}

if (Utils.PLATFORM.isModLoaded("appbot")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
AppBotIntegration.initUpgrades();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public FuzzyMode getFuzzyMode(ItemStack itemStack) {
public void setFuzzyMode(ItemStack itemStack, FuzzyMode fuzzyMode) {
}

private static class Handler implements ICellHandler {
public static class Handler implements ICellHandler {
private Handler() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public BulkCellInventory(MEGABulkCell cell, ItemStack o, ISaveProvider container
this.unitFactor = decompressed.values().intStream().asLongStream().reduce(1, Math::multiplyExact);

this.storedItem = getTag().contains(KEY) ? AEItemKey.fromTag(getTag().getCompound(KEY)) : null;
this.unitCount = !getTag().getString(UNIT_COUNT).equals("")
this.unitCount = !getTag().getString(UNIT_COUNT).isEmpty()
? new BigInteger(getTag().getString(UNIT_COUNT))
: BigInteger.ZERO;
this.highestCompressed = storedItem;
Expand Down
17 changes: 17 additions & 0 deletions common/src/main/java/gripe/_90/megacells/util/Addons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gripe._90.megacells.util;

public enum Addons {
APPMEK("appmek"),
APPBOT("appbot"),
AE2WTLIB("ae2wtlib");

private final String modId;

Addons(String modId) {
this.modId = modId;
}

public String getModId() {
return modId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import net.minecraft.world.item.CreativeModeTab;

import gripe._90.megacells.util.Addons;

public interface Platform {
Loader getLoader();

CreativeModeTab getCreativeTab(CreativeModeTab.DisplayItemsGenerator display);

boolean isModLoaded(String modId);
boolean isAddonLoaded(Addons modId);

enum Loader {
FABRIC, FORGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

class ModelProvider extends FabricModelProvider {
Expand Down Expand Up @@ -125,15 +126,13 @@ public void generateItemModels(ItemModelGenerators generator) {
cells.addAll(MEGAItems.getFluidCells());
cells.add(MEGAItems.BULK_ITEM_CELL);

if (Utils.PLATFORM.isModLoaded("appbot")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
cells.addAll(AppBotItems.getCells());
generator.generateFlatItem(AppBotItems.MEGA_MANA_CELL_HOUSING.asItem(), ModelTemplates.FLAT_ITEM);

for (var portable : AppBotItems.getPortables()) {
// lot of assumptions being made here in advance
portableModel(portable, "mana", new ResourceLocation("appbot", "item/portable_cell_mana_housing"),
generator);
}
// lot of assumptions being made here in advance
AppBotItems.getPortables().forEach(p -> portableModel(p, "mana",
new ResourceLocation(Addons.APPBOT.getModId(), "item/portable_cell_mana_housing"), generator));

driveCell("mega_mana_cell", generator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import gripe._90.megacells.definition.MEGAParts;
import gripe._90.megacells.definition.MEGATags;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

class RecipeProvider extends FabricRecipeProvider {
Expand Down Expand Up @@ -216,7 +217,7 @@ public void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_cable_mega_pattern_provider", has(MEGAParts.MEGA_PATTERN_PROVIDER))
.save(consumer, Utils.makeId("network/mega_pattern_provider_block"));

if (Utils.PLATFORM.isModLoaded("appbot")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
manaCells(consumer, AppBotItems.MANA_CELL_1M, AppBotItems.PORTABLE_MANA_CELL_1M, MEGAItems.TIER_1M);
manaCells(consumer, AppBotItems.MANA_CELL_4M, AppBotItems.PORTABLE_MANA_CELL_4M, MEGAItems.TIER_4M);
manaCells(consumer, AppBotItems.MANA_CELL_16M, AppBotItems.PORTABLE_MANA_CELL_16M, MEGAItems.TIER_16M);
Expand Down
3 changes: 2 additions & 1 deletion fabric/src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.service.CompressionService;
import gripe._90.megacells.service.DecompressionService;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

public class MEGACells implements IAEAddonEntrypoint {
Expand All @@ -41,7 +42,7 @@ private void initAll() {
MEGAParts.init();
MEGABlockEntities.init();

if (Utils.PLATFORM.isModLoaded("appbot")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
AppBotItems.init();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

@Environment(EnvType.CLIENT)
Expand Down Expand Up @@ -83,7 +84,7 @@ private void initItemColors() {
var portables = new ArrayList<>(MEGAItems.getItemPortables());
portables.addAll(MEGAItems.getFluidPortables());

if (Utils.PLATFORM.isModLoaded("appbot")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
cells.addAll(AppBotItems.getCells());
portables.addAll(AppBotItems.getPortables());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public CreativeModeTab getCreativeTab(CreativeModeTab.DisplayItemsGenerator disp
}

@Override
public boolean isModLoaded(String modId) {
return FabricLoaderImpl.INSTANCE.isModLoaded(modId);
public boolean isAddonLoaded(Addons addon) {
return FabricLoaderImpl.INSTANCE.isModLoaded(addon.getModId());
}
}
47 changes: 38 additions & 9 deletions forge/src/main/java/gripe/_90/megacells/datagen/ModelProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.definition.MEGAParts;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.integration.appmek.AppMekItems;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

abstract class ModelProvider {
Expand All @@ -47,6 +50,7 @@ static class Items extends ItemModelProvider {
private static final ResourceLocation PORTABLE_CELL_FLUID_HOUSING = AppEng.makeId("item/portable_cell_fluid_housing");

private static final ResourceLocation CABLE_INTERFACE = AppEng.makeId("item/cable_interface");
private static final ResourceLocation DRIVE_CELL = AppEng.makeId("block/drive/drive_cell");
//spotless:on

public Items(PackOutput output, ExistingFileHelper existing) {
Expand All @@ -57,6 +61,7 @@ public Items(PackOutput output, ExistingFileHelper existing) {
existing.trackGenerated(PORTABLE_CELL_ITEM_HOUSING, TEXTURE);
existing.trackGenerated(PORTABLE_CELL_FLUID_HOUSING, TEXTURE);
existing.trackGenerated(CABLE_INTERFACE, MODEL);
existing.trackGenerated(DRIVE_CELL, MODEL);
}

@Override
Expand Down Expand Up @@ -86,10 +91,38 @@ protected void registerModels() {
MEGAItems.getItemPortables().forEach(p -> portableModel(p, "item", PORTABLE_CELL_ITEM_HOUSING));
MEGAItems.getFluidPortables().forEach(p -> portableModel(p, "fluid", PORTABLE_CELL_FLUID_HOUSING));

driveCell("mega_item_cell");
driveCell("mega_fluid_cell");
driveCell("bulk_item_cell");

var cells = new ArrayList<>(MEGAItems.getItemCells());
cells.addAll(MEGAItems.getFluidCells());
cells.add(MEGAItems.BULK_ITEM_CELL);

if (Utils.PLATFORM.isAddonLoaded(Addons.APPMEK)) {
basicItem(AppMekItems.MEGA_CHEMICAL_CELL_HOUSING.asItem());

cells.addAll(AppMekItems.getCells());
// TODO
AppMekItems.getPortables().forEach(p -> portableModel(p, "chemical", PORTABLE_CELL_ITEM_HOUSING));

basicItem(AppMekItems.RADIOACTIVE_CELL_COMPONENT.asItem());
cells.add(AppMekItems.RADIOACTIVE_CHEMICAL_CELL);

driveCell("mega_chemical_cell");
driveCell("radioactive_chemical_cell");
}

if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
basicItem(AppBotItems.MEGA_MANA_CELL_HOUSING.asItem());

cells.addAll(AppBotItems.getCells());
// TODO
AppBotItems.getPortables().forEach(p -> portableModel(p, "mana", PORTABLE_CELL_ITEM_HOUSING));

driveCell("mega_mana_cell");
}

cells.forEach(this::cellModel);

patternProviderPart();
Expand All @@ -110,6 +143,11 @@ private void portableModel(ItemDefinition<?> portable, String screenType, Resour
.texture("layer3", "item/cell/portable/portable_cell_side_%s".formatted(tierSuffix));
}

private void driveCell(String texture) {
var path = "block/drive/cells/" + texture;
withExistingParent(path, DRIVE_CELL).texture("cell", path);
}

private void patternProviderPart() {
withExistingParent(MEGAParts.MEGA_PATTERN_PROVIDER.id().getPath(), CABLE_INTERFACE)
.texture("back", "part/mega_monitor_back")
Expand Down Expand Up @@ -147,15 +185,6 @@ protected void registerStatesAndModels() {
Pair.of(MEGABlocks.CRAFTING_ACCELERATOR, "accelerator"));
craftingUnits.forEach(block -> craftingModel(block.first, block.second));
craftingMonitor();

driveCell("mega_item_cell");
driveCell("mega_fluid_cell");
driveCell("bulk_item_cell");
}

private void driveCell(String texture) {
var path = "block/drive/cells/" + texture;
models().withExistingParent(path, DRIVE_CELL).texture("cell", path);
}

private void energyCell() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
Expand All @@ -31,11 +33,17 @@
import appeng.recipes.transform.TransformCircumstance;
import appeng.recipes.transform.TransformRecipeBuilder;

import mekanism.common.registries.MekanismBlocks;
import mekanism.common.registries.MekanismItems;
import mekanism.generators.common.registries.GeneratorsBlocks;

import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.definition.MEGAParts;
import gripe._90.megacells.definition.MEGATags;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.integration.appmek.AppMekItems;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

public class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
Expand Down Expand Up @@ -216,7 +224,46 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_cable_mega_pattern_provider", has(MEGAParts.MEGA_PATTERN_PROVIDER))
.save(consumer, Utils.makeId("network/mega_pattern_provider_block"));

if (Utils.PLATFORM.isModLoaded("appbot")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPMEK)) {
var osmiumTag = ItemTags.create(new ResourceLocation("forge", "ingots/osmium"));

// spotless:off
housing(consumer, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING, osmiumTag);

cell(consumer, AppMekItems.CHEMICAL_CELL_1M, MEGAItems.CELL_COMPONENT_1M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING, osmiumTag);
cell(consumer, AppMekItems.CHEMICAL_CELL_4M, MEGAItems.CELL_COMPONENT_4M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING, osmiumTag);
cell(consumer, AppMekItems.CHEMICAL_CELL_16M, MEGAItems.CELL_COMPONENT_16M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING, osmiumTag);
cell(consumer, AppMekItems.CHEMICAL_CELL_64M, MEGAItems.CELL_COMPONENT_64M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING, osmiumTag);
cell(consumer, AppMekItems.CHEMICAL_CELL_256M, MEGAItems.CELL_COMPONENT_256M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING, osmiumTag);

portable(consumer, AppMekItems.PORTABLE_CHEMICAL_CELL_1M, MEGAItems.CELL_COMPONENT_1M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING);
portable(consumer, AppMekItems.PORTABLE_CHEMICAL_CELL_4M, MEGAItems.CELL_COMPONENT_4M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING);
portable(consumer, AppMekItems.PORTABLE_CHEMICAL_CELL_16M, MEGAItems.CELL_COMPONENT_16M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING);
portable(consumer, AppMekItems.PORTABLE_CHEMICAL_CELL_64M, MEGAItems.CELL_COMPONENT_64M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING);
portable(consumer, AppMekItems.PORTABLE_CHEMICAL_CELL_256M, MEGAItems.CELL_COMPONENT_256M, AppMekItems.MEGA_CHEMICAL_CELL_HOUSING);
//spotless:on

// TODO
InscriberRecipeBuilder.inscribe(AEItems.SINGULARITY, AppMekItems.RADIOACTIVE_CELL_COMPONENT, 1)
.setMode(InscriberProcessType.PRESS)
.setTop(Ingredient.of(AEItems.CELL_COMPONENT_256K))
.setBottom(Ingredient.of(MekanismBlocks.RADIOACTIVE_WASTE_BARREL))
.save(consumer, Utils.makeId("inscriber/radioactive_cell_component"));

ShapedRecipeBuilder.shaped(RecipeCategory.MISC, AppMekItems.RADIOACTIVE_CHEMICAL_CELL)
.pattern("aba")
.pattern("bcb")
.pattern("ded")
.define('a', GeneratorsBlocks.REACTOR_GLASS)
.define('b', AEItems.SKY_DUST)
.define('c', AppMekItems.RADIOACTIVE_CELL_COMPONENT)
.define('d', MekanismItems.HDPE_SHEET)
.define('e', MekanismItems.POLONIUM_PELLET)
.unlockedBy("has_radioactive_cell_component", has(AppMekItems.RADIOACTIVE_CELL_COMPONENT))
.save(consumer, Utils.makeId("cells/standard/radioactive_chemical_cell"));
}

if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
manaCells(consumer, AppBotItems.MANA_CELL_1M, AppBotItems.PORTABLE_MANA_CELL_1M, MEGAItems.TIER_1M);
manaCells(consumer, AppBotItems.MANA_CELL_4M, AppBotItems.PORTABLE_MANA_CELL_4M, MEGAItems.TIER_4M);
manaCells(consumer, AppBotItems.MANA_CELL_16M, AppBotItems.PORTABLE_MANA_CELL_16M, MEGAItems.TIER_16M);
Expand Down
7 changes: 4 additions & 3 deletions forge/src/main/java/gripe/_90/megacells/forge/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import gripe._90.megacells.integration.appmek.AppMekItems;
import gripe._90.megacells.service.CompressionService;
import gripe._90.megacells.service.DecompressionService;
import gripe._90.megacells.util.Addons;
import gripe._90.megacells.util.Utils;

@Mod(Utils.MODID)
Expand All @@ -54,11 +55,11 @@ private void initAll() {
MEGAParts.init();
MEGABlockEntities.init();

if (Utils.PLATFORM.isModLoaded("appmek")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPMEK)) {
AppMekItems.init();
}

if (Utils.PLATFORM.isModLoaded("appbot")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
AppBotItems.init();
}
}
Expand Down Expand Up @@ -94,7 +95,7 @@ private void initCells(FMLCommonSetupEvent event) {
event.enqueueWork(InitUpgrades::init);

event.enqueueWork(() -> {
if (Utils.PLATFORM.isModLoaded("appmek")) {
if (Utils.PLATFORM.isAddonLoaded(Addons.APPMEK)) {
AppMekIntegration.initUpgrades();
AppMekIntegration.initStorageCells();
}
Expand Down
Loading

0 comments on commit 666cda9

Please sign in to comment.