Skip to content

Commit

Permalink
De-duplicate all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Nov 16, 2023
1 parent 7d19f3a commit 72408e9
Show file tree
Hide file tree
Showing 21 changed files with 505 additions and 504 deletions.
127 changes: 30 additions & 97 deletions common/src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
package gripe._90.megacells;

import java.util.Collection;
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.resources.ResourceLocation;

import appeng.api.client.StorageCellModels;
import appeng.api.features.HotkeyAction;
import appeng.api.networking.GridServices;
import appeng.api.storage.StorageCells;
import appeng.api.upgrades.Upgrades;
import appeng.core.definitions.AEItems;
import appeng.core.localization.GuiText;
import appeng.client.render.crafting.CraftingMonitorRenderer;
import appeng.hotkeys.HotkeyActions;
import appeng.items.storage.BasicStorageCell;
import appeng.items.tools.powered.PortableCellItem;

import gripe._90.megacells.core.Addons;
import gripe._90.megacells.core.Platform;
import gripe._90.megacells.definition.MEGABlockEntities;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAConfig;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.ae2wt.AE2WTIntegration;
import gripe._90.megacells.integration.appbot.AppBotIntegration;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.item.cell.BulkCellItem;
import gripe._90.megacells.misc.DecompressionService;
Expand All @@ -40,9 +37,6 @@ private MEGACells() {}

public static final Platform PLATFORM =
ServiceLoader.load(Platform.class).findFirst().orElseThrow();
public static final Platform.Client PLATFORM_CLIENT = PLATFORM.isClient()
? ServiceLoader.load(Platform.Client.class).findFirst().orElseThrow()
: null;

public static ResourceLocation makeId(String path) {
return new ResourceLocation(MODID, path);
Expand All @@ -51,13 +45,9 @@ public static ResourceLocation makeId(String path) {
public static void initCommon() {
MEGAConfig.load();

MEGAItems.init();
MEGABlocks.init();
MEGABlockEntities.init();

if (PLATFORM.isAddonLoaded(Addons.APPBOT)) {
AppBotItems.init();
}
PLATFORM.initItems();
PLATFORM.register();
PLATFORM.initUpgrades();

StorageCells.addCellHandler(BulkCellItem.HANDLER);

Expand All @@ -66,8 +56,6 @@ public static void initCommon() {
MEGAItems.getFluidPortables()
.forEach(cell -> HotkeyActions.registerPortableCell(cell, HotkeyAction.PORTABLE_FLUID_CELL));

initStorageCellModels();

PLATFORM.initCompression();
GridServices.register(DecompressionService.class, DecompressionService.class);

Expand All @@ -77,91 +65,36 @@ public static void initCommon() {
PLATFORM.addVillagerTrade(MEGAItems.ACCUMULATION_PROCESSOR_PRESS, 40, 1, 50);
}

private static void initStorageCellModels() {
Stream.of(MEGAItems.getItemCells(), MEGAItems.getItemPortables())
.flatMap(Collection::stream)
.forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_item_cell")));
Stream.of(MEGAItems.getFluidCells(), MEGAItems.getFluidPortables())
.flatMap(Collection::stream)
.forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_fluid_cell")));

StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, makeId("block/drive/cells/bulk_item_cell"));

if (PLATFORM.isAddonLoaded(Addons.APPBOT)) {
Stream.of(AppBotItems.getCells(), AppBotItems.getPortables())
.flatMap(Collection::stream)
.forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_mana_cell")));
}
}
public static class Client {
private Client() {}

// has to be done post-registration
public static void initUpgrades() {
var storageCellGroup = GuiText.StorageCells.getTranslationKey();
var portableCellGroup = GuiText.PortableCells.getTranslationKey();
var interfaceGroup = GuiText.Interface.getTranslationKey();
var wirelessTerminalGroup = GuiText.WirelessTerminals.getTranslationKey();

for (var itemCell : MEGAItems.getItemCells()) {
Upgrades.add(AEItems.FUZZY_CARD, itemCell, 1, storageCellGroup);
Upgrades.add(AEItems.INVERTER_CARD, itemCell, 1, storageCellGroup);
Upgrades.add(AEItems.EQUAL_DISTRIBUTION_CARD, itemCell, 1, storageCellGroup);
Upgrades.add(AEItems.VOID_CARD, itemCell, 1, storageCellGroup);
}
public static final Platform.Client PLATFORM =
ServiceLoader.load(Platform.Client.class).findFirst().orElseThrow();

for (var fluidCell : MEGAItems.getFluidCells()) {
Upgrades.add(AEItems.INVERTER_CARD, fluidCell, 1, storageCellGroup);
Upgrades.add(AEItems.EQUAL_DISTRIBUTION_CARD, fluidCell, 1, storageCellGroup);
Upgrades.add(AEItems.VOID_CARD, fluidCell, 1, storageCellGroup);
}
public static void initClient() {
PLATFORM.initScreens();
PLATFORM.initEnergyCellProps();
PLATFORM.initCraftingUnitModels();

for (var itemPortable : MEGAItems.getItemPortables()) {
Upgrades.add(AEItems.FUZZY_CARD, itemPortable, 1, portableCellGroup);
Upgrades.add(AEItems.INVERTER_CARD, itemPortable, 1, portableCellGroup);
Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, itemPortable, 2, portableCellGroup);
Upgrades.add(AEItems.EQUAL_DISTRIBUTION_CARD, itemPortable, 1, storageCellGroup);
Upgrades.add(AEItems.VOID_CARD, itemPortable, 1, storageCellGroup);
}
Stream.of(MEGAItems.getItemCells(), MEGAItems.getItemPortables())
.flatMap(Collection::stream)
.forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_item_cell")));
Stream.of(MEGAItems.getFluidCells(), MEGAItems.getFluidPortables())
.flatMap(Collection::stream)
.forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_fluid_cell")));

for (var fluidPortable : MEGAItems.getFluidPortables()) {
Upgrades.add(AEItems.INVERTER_CARD, fluidPortable, 1, portableCellGroup);
Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, fluidPortable, 2, portableCellGroup);
Upgrades.add(AEItems.EQUAL_DISTRIBUTION_CARD, fluidPortable, 1, storageCellGroup);
Upgrades.add(AEItems.VOID_CARD, fluidPortable, 1, storageCellGroup);
}
StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, makeId("block/drive/cells/bulk_item_cell"));

Upgrades.add(AEItems.CRAFTING_CARD, MEGABlocks.MEGA_INTERFACE, 1, interfaceGroup);
Upgrades.add(AEItems.CRAFTING_CARD, MEGAItems.MEGA_INTERFACE, 1, interfaceGroup);
Upgrades.add(AEItems.FUZZY_CARD, MEGABlocks.MEGA_INTERFACE, 1, interfaceGroup);
Upgrades.add(AEItems.FUZZY_CARD, MEGAItems.MEGA_INTERFACE, 1, interfaceGroup);

Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, AEItems.WIRELESS_TERMINAL, 2, wirelessTerminalGroup);
Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, AEItems.WIRELESS_CRAFTING_TERMINAL, 2, wirelessTerminalGroup);

Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, AEItems.COLOR_APPLICATOR, 2);
Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, AEItems.MATTER_CANNON, 2);

Upgrades.add(MEGAItems.COMPRESSION_CARD, MEGAItems.BULK_ITEM_CELL, 1);

for (var portableCell : List.of(
AEItems.PORTABLE_ITEM_CELL1K,
AEItems.PORTABLE_ITEM_CELL4K,
AEItems.PORTABLE_ITEM_CELL16K,
AEItems.PORTABLE_ITEM_CELL64K,
AEItems.PORTABLE_ITEM_CELL256K,
AEItems.PORTABLE_FLUID_CELL1K,
AEItems.PORTABLE_FLUID_CELL4K,
AEItems.PORTABLE_FLUID_CELL16K,
AEItems.PORTABLE_FLUID_CELL64K,
AEItems.PORTABLE_FLUID_CELL256K)) {
Upgrades.add(MEGAItems.GREATER_ENERGY_CARD, portableCell, 2, portableCellGroup);
}
if (MEGACells.PLATFORM.isAddonLoaded(Addons.APPBOT)) {
Stream.of(AppBotItems.getCells(), AppBotItems.getPortables())
.flatMap(Collection::stream)
.forEach(c -> StorageCellModels.registerModel(c, makeId("block/drive/cells/mega_mana_cell")));
}

if (PLATFORM.isAddonLoaded(Addons.AE2WTLIB)) {
AE2WTIntegration.initUpgrades();
}
BlockEntityRenderers.register(MEGABlockEntities.MEGA_CRAFTING_MONITOR, CraftingMonitorRenderer::new);

if (PLATFORM.isAddonLoaded(Addons.APPBOT)) {
AppBotIntegration.initUpgrades();
PLATFORM.initItemColours(BasicStorageCell::getColor, MEGACells.PLATFORM.getAllCells());
PLATFORM.initItemColours(PortableCellItem::getColor, MEGACells.PLATFORM.getAllPortables());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import appeng.menu.locator.MenuLocator;

import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.menu.MEGAInterfaceMenu;
import gripe._90.megacells.definition.MEGAMenus;

public class MEGAInterfaceBlockEntity extends InterfaceBlockEntity {
public MEGAInterfaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState blockState) {
Expand All @@ -27,12 +27,12 @@ protected InterfaceLogic createLogic() {

@Override
public void openMenu(Player player, MenuLocator locator) {
MenuOpener.open(MEGAInterfaceMenu.TYPE, player, locator);
MenuOpener.open(MEGAMenus.MEGA_INTERFACE, player, locator);
}

@Override
public void returnToMainMenu(Player player, ISubMenu subMenu) {
MenuOpener.returnTo(MEGAInterfaceMenu.TYPE, player, subMenu.getLocator());
MenuOpener.returnTo(MEGAMenus.MEGA_INTERFACE, player, subMenu.getLocator());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import gripe._90.megacells.block.MEGAPatternProviderBlock;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.menu.MEGAPatternProviderMenu;
import gripe._90.megacells.definition.MEGAMenus;

public class MEGAPatternProviderBlockEntity extends PatternProviderBlockEntity {

Expand All @@ -30,12 +30,12 @@ public PatternProviderLogic createLogic() {

@Override
public void openMenu(Player player, MenuLocator locator) {
MenuOpener.open(MEGAPatternProviderMenu.TYPE, player, locator);
MenuOpener.open(MEGAMenus.MEGA_PATTERN_PROVIDER, player, locator);
}

@Override
public void returnToMainMenu(Player player, ISubMenu subMenu) {
MenuOpener.returnTo(MEGAPatternProviderMenu.TYPE, player, subMenu.getLocator());
MenuOpener.returnTo(MEGAMenus.MEGA_PATTERN_PROVIDER, player, subMenu.getLocator());
}

@Override
Expand Down
Loading

0 comments on commit 72408e9

Please sign in to comment.