From 817fed59af576aa4ec666b568ee6bb036c3d13ee Mon Sep 17 00:00:00 2001 From: 90 Date: Sun, 15 Oct 2023 16:31:41 +0100 Subject: [PATCH] Slight cell refactor --- .../java/gripe/_90/megacells/MEGACells.java | 4 +-- .../_90/megacells/definition/MEGAItems.java | 36 +++++++++---------- .../item/cell/BulkCellInventory.java | 3 +- .../{MEGABulkCell.java => BulkCellItem.java} | 12 +++---- ...bleCell.java => MEGAPortableCellItem.java} | 4 +-- .../integration/appmek/AppMekIntegration.java | 4 +-- .../integration/appmek/AppMekItems.java | 6 ++-- .../appmek/item/RadioactiveCellInventory.java | 3 +- ...tiveCell.java => RadioactiveCellItem.java} | 12 +++---- 9 files changed, 41 insertions(+), 43 deletions(-) rename common/src/main/java/gripe/_90/megacells/item/cell/{MEGABulkCell.java => BulkCellItem.java} (91%) rename common/src/main/java/gripe/_90/megacells/item/cell/{MEGAPortableCell.java => MEGAPortableCellItem.java} (93%) rename forge/src/main/java/gripe/_90/megacells/integration/appmek/item/{MEGARadioactiveCell.java => RadioactiveCellItem.java} (89%) diff --git a/common/src/main/java/gripe/_90/megacells/MEGACells.java b/common/src/main/java/gripe/_90/megacells/MEGACells.java index 665ba442..d03cc77c 100644 --- a/common/src/main/java/gripe/_90/megacells/MEGACells.java +++ b/common/src/main/java/gripe/_90/megacells/MEGACells.java @@ -29,7 +29,7 @@ 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.MEGABulkCell; +import gripe._90.megacells.item.cell.BulkCellItem; public final class MEGACells { private MEGACells() {} @@ -74,7 +74,7 @@ private static void initStorageCells() { .forEach( c -> StorageCellModels.registerModel(c, MEGACells.makeId("block/drive/cells/mega_fluid_cell"))); - StorageCells.addCellHandler(MEGABulkCell.HANDLER); + StorageCells.addCellHandler(BulkCellItem.HANDLER); StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, MEGACells.makeId("block/drive/cells/bulk_item_cell")); MEGAItems.getItemPortables() diff --git a/common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java b/common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java index 28dd21f6..37508c48 100644 --- a/common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java +++ b/common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java @@ -24,8 +24,8 @@ import gripe._90.megacells.MEGACells; import gripe._90.megacells.crafting.DecompressionPatternItem; -import gripe._90.megacells.item.cell.MEGABulkCell; -import gripe._90.megacells.item.cell.MEGAPortableCell; +import gripe._90.megacells.item.cell.BulkCellItem; +import gripe._90.megacells.item.cell.MEGAPortableCellItem; import gripe._90.megacells.item.part.DecompressionModulePart; import gripe._90.megacells.item.part.MEGAInterfacePart; import gripe._90.megacells.item.part.MEGAPatternProviderPart; @@ -84,20 +84,20 @@ public static List> getItems() { public static final ItemDefinition BULK_CELL_COMPONENT = item("MEGA Bulk Storage Component", "bulk_cell_component", MaterialItem::new); - public static final ItemDefinition BULK_ITEM_CELL = - item("MEGA Bulk Item Storage Cell", "bulk_item_cell", MEGABulkCell::new); + public static final ItemDefinition BULK_ITEM_CELL = + item("MEGA Bulk Item Storage Cell", "bulk_item_cell", BulkCellItem::new); - public static final ItemDefinition PORTABLE_ITEM_CELL_1M = itemPortable(TIER_1M); - public static final ItemDefinition PORTABLE_ITEM_CELL_4M = itemPortable(TIER_4M); - public static final ItemDefinition PORTABLE_ITEM_CELL_16M = itemPortable(TIER_16M); - public static final ItemDefinition PORTABLE_ITEM_CELL_64M = itemPortable(TIER_64M); - public static final ItemDefinition PORTABLE_ITEM_CELL_256M = itemPortable(TIER_256M); + public static final ItemDefinition PORTABLE_ITEM_CELL_1M = itemPortable(TIER_1M); + public static final ItemDefinition PORTABLE_ITEM_CELL_4M = itemPortable(TIER_4M); + public static final ItemDefinition PORTABLE_ITEM_CELL_16M = itemPortable(TIER_16M); + public static final ItemDefinition PORTABLE_ITEM_CELL_64M = itemPortable(TIER_64M); + public static final ItemDefinition PORTABLE_ITEM_CELL_256M = itemPortable(TIER_256M); - public static final ItemDefinition PORTABLE_FLUID_CELL_1M = fluidPortable(TIER_1M); - public static final ItemDefinition PORTABLE_FLUID_CELL_4M = fluidPortable(TIER_4M); - public static final ItemDefinition PORTABLE_FLUID_CELL_16M = fluidPortable(TIER_16M); - public static final ItemDefinition PORTABLE_FLUID_CELL_64M = fluidPortable(TIER_64M); - public static final ItemDefinition PORTABLE_FLUID_CELL_256M = fluidPortable(TIER_256M); + public static final ItemDefinition PORTABLE_FLUID_CELL_1M = fluidPortable(TIER_1M); + public static final ItemDefinition PORTABLE_FLUID_CELL_4M = fluidPortable(TIER_4M); + public static final ItemDefinition PORTABLE_FLUID_CELL_16M = fluidPortable(TIER_16M); + public static final ItemDefinition PORTABLE_FLUID_CELL_64M = fluidPortable(TIER_64M); + public static final ItemDefinition PORTABLE_FLUID_CELL_256M = fluidPortable(TIER_256M); public static final ItemDefinition GREATER_ENERGY_CARD = item("Greater Energy Card", "greater_energy_card", p -> new EnergyCardItem(p, 8)); @@ -196,18 +196,18 @@ private static ItemDefinition fluidCell(StorageTier tier) { AEKeyType.fluids())); } - private static ItemDefinition itemPortable(StorageTier tier) { + private static ItemDefinition itemPortable(StorageTier tier) { return item( tier.namePrefix().toUpperCase() + " Portable Item Cell", "portable_item_cell_" + tier.namePrefix(), - p -> new MEGAPortableCell(p, tier, AEKeyType.items(), MEStorageMenu.PORTABLE_ITEM_CELL_TYPE, 0x353535)); + p -> new MEGAPortableCellItem(p, tier, AEKeyType.items(), MEStorageMenu.PORTABLE_ITEM_CELL_TYPE, 0x353535)); } - private static ItemDefinition fluidPortable(StorageTier tier) { + private static ItemDefinition fluidPortable(StorageTier tier) { return item( tier.namePrefix().toUpperCase() + " Portable Fluid Cell", "portable_fluid_cell_" + tier.namePrefix(), - p -> new MEGAPortableCell( + p -> new MEGAPortableCellItem( p, tier, AEKeyType.fluids(), MEStorageMenu.PORTABLE_FLUID_CELL_TYPE, 0x00F1C5)); } diff --git a/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java b/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java index 4d6de906..3e1ff0b2 100644 --- a/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java +++ b/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellInventory.java @@ -38,10 +38,11 @@ public class BulkCellInventory implements StorageCell { private boolean isPersisted = true; - public BulkCellInventory(MEGABulkCell cell, ItemStack stack, ISaveProvider container) { + BulkCellInventory(ItemStack stack, ISaveProvider container) { this.stack = stack; this.container = container; + var cell = (BulkCellItem) stack.getItem(); var filter = cell.getConfigInventory(this.stack).getKey(0); filterItem = filter instanceof AEItemKey item ? item : null; diff --git a/common/src/main/java/gripe/_90/megacells/item/cell/MEGABulkCell.java b/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellItem.java similarity index 91% rename from common/src/main/java/gripe/_90/megacells/item/cell/MEGABulkCell.java rename to common/src/main/java/gripe/_90/megacells/item/cell/BulkCellItem.java index f0aa3c91..6a33f0cd 100644 --- a/common/src/main/java/gripe/_90/megacells/item/cell/MEGABulkCell.java +++ b/common/src/main/java/gripe/_90/megacells/item/cell/BulkCellItem.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.Optional; import org.jetbrains.annotations.NotNull; @@ -33,10 +32,10 @@ import gripe._90.megacells.definition.MEGAItems; import gripe._90.megacells.definition.MEGATranslations; -public class MEGABulkCell extends AEBaseItem implements ICellWorkbenchItem { +public class BulkCellItem extends AEBaseItem implements ICellWorkbenchItem { public static final Handler HANDLER = new Handler(); - public MEGABulkCell(Properties properties) { + public BulkCellItem(Properties properties) { super(properties.stacksTo(1)); } @@ -133,14 +132,13 @@ private Handler() {} @Override public boolean isCell(ItemStack is) { - return is != null && is.getItem() instanceof MEGABulkCell; + return is != null && is.getItem() instanceof BulkCellItem; } @Nullable @Override - public BulkCellInventory getCellInventory(ItemStack is, @Nullable ISaveProvider container) { - Objects.requireNonNull(is, "Cannot create cell inventory for null itemstack"); - return isCell(is) ? new BulkCellInventory((MEGABulkCell) is.getItem(), is, container) : null; + public BulkCellInventory getCellInventory(ItemStack is, @Nullable ISaveProvider host) { + return isCell(is) ? new BulkCellInventory(is, host) : null; } } } diff --git a/common/src/main/java/gripe/_90/megacells/item/cell/MEGAPortableCell.java b/common/src/main/java/gripe/_90/megacells/item/cell/MEGAPortableCellItem.java similarity index 93% rename from common/src/main/java/gripe/_90/megacells/item/cell/MEGAPortableCell.java rename to common/src/main/java/gripe/_90/megacells/item/cell/MEGAPortableCellItem.java index 91fb346f..9dbcda54 100644 --- a/common/src/main/java/gripe/_90/megacells/item/cell/MEGAPortableCell.java +++ b/common/src/main/java/gripe/_90/megacells/item/cell/MEGAPortableCellItem.java @@ -13,10 +13,10 @@ import gripe._90.megacells.MEGACells; -public class MEGAPortableCell extends PortableCellItem { +public class MEGAPortableCellItem extends PortableCellItem { private final StorageTier tier; - public MEGAPortableCell( + public MEGAPortableCellItem( Properties props, StorageTier tier, AEKeyType keyType, MenuType menu, int defaultColour) { super( keyType, diff --git a/forge/src/main/java/gripe/_90/megacells/integration/appmek/AppMekIntegration.java b/forge/src/main/java/gripe/_90/megacells/integration/appmek/AppMekIntegration.java index 78431b42..ebec344b 100644 --- a/forge/src/main/java/gripe/_90/megacells/integration/appmek/AppMekIntegration.java +++ b/forge/src/main/java/gripe/_90/megacells/integration/appmek/AppMekIntegration.java @@ -14,7 +14,7 @@ import gripe._90.megacells.MEGACells; import gripe._90.megacells.definition.MEGAItems; -import gripe._90.megacells.integration.appmek.item.MEGARadioactiveCell; +import gripe._90.megacells.integration.appmek.item.RadioactiveCellItem; public final class AppMekIntegration { public static void initUpgrades() { @@ -50,7 +50,7 @@ public static void initStorageCells() { .forEach(c -> StorageCellModels.registerModel(c, MEGACells.makeId("block/drive/cells/mega_chemical_cell"))); - StorageCells.addCellHandler(MEGARadioactiveCell.HANDLER); + StorageCells.addCellHandler(RadioactiveCellItem.HANDLER); StorageCellModels.registerModel( AppMekItems.RADIOACTIVE_CHEMICAL_CELL.asItem(), MEGACells.makeId("block/drive/cells/radioactive_chemical_cell")); diff --git a/forge/src/main/java/gripe/_90/megacells/integration/appmek/AppMekItems.java b/forge/src/main/java/gripe/_90/megacells/integration/appmek/AppMekItems.java index fa602937..518f1b01 100644 --- a/forge/src/main/java/gripe/_90/megacells/integration/appmek/AppMekItems.java +++ b/forge/src/main/java/gripe/_90/megacells/integration/appmek/AppMekItems.java @@ -13,7 +13,7 @@ import gripe._90.megacells.MEGACells; import gripe._90.megacells.definition.MEGAItems; -import gripe._90.megacells.integration.appmek.item.MEGARadioactiveCell; +import gripe._90.megacells.integration.appmek.item.RadioactiveCellItem; public final class AppMekItems { public static void init() { @@ -43,8 +43,8 @@ public static void init() { public static final ItemDefinition RADIOACTIVE_CELL_COMPONENT = MEGAItems.item("MEGA Radioactive Storage Component", "radioactive_cell_component", MaterialItem::new); - public static final ItemDefinition RADIOACTIVE_CHEMICAL_CELL = MEGAItems.item( - "MEGA Radioactive Chemical Storage Cell", "radioactive_chemical_cell", MEGARadioactiveCell::new); + public static final ItemDefinition RADIOACTIVE_CHEMICAL_CELL = MEGAItems.item( + "MEGA Radioactive Chemical Storage Cell", "radioactive_chemical_cell", RadioactiveCellItem::new); public static List> getCells() { return List.of(CHEMICAL_CELL_1M, CHEMICAL_CELL_4M, CHEMICAL_CELL_16M, CHEMICAL_CELL_64M, CHEMICAL_CELL_256M); diff --git a/forge/src/main/java/gripe/_90/megacells/integration/appmek/item/RadioactiveCellInventory.java b/forge/src/main/java/gripe/_90/megacells/integration/appmek/item/RadioactiveCellInventory.java index 38283866..d0f1c4b6 100644 --- a/forge/src/main/java/gripe/_90/megacells/integration/appmek/item/RadioactiveCellInventory.java +++ b/forge/src/main/java/gripe/_90/megacells/integration/appmek/item/RadioactiveCellInventory.java @@ -37,10 +37,11 @@ public class RadioactiveCellInventory implements StorageCell { private long chemAmount; private boolean isPersisted = true; - public RadioactiveCellInventory(MEGARadioactiveCell cell, ItemStack stack, ISaveProvider container) { + RadioactiveCellInventory(ItemStack stack, ISaveProvider container) { this.stack = stack; this.container = container; + var cell = (RadioactiveCellItem) stack.getItem(); var filter = cell.getConfigInventory(this.stack).getKey(0); filterChemical = filter instanceof MekanismKey chemical ? chemical : null; diff --git a/forge/src/main/java/gripe/_90/megacells/integration/appmek/item/MEGARadioactiveCell.java b/forge/src/main/java/gripe/_90/megacells/integration/appmek/item/RadioactiveCellItem.java similarity index 89% rename from forge/src/main/java/gripe/_90/megacells/integration/appmek/item/MEGARadioactiveCell.java rename to forge/src/main/java/gripe/_90/megacells/integration/appmek/item/RadioactiveCellItem.java index 4c8b8cc5..75f9f42b 100644 --- a/forge/src/main/java/gripe/_90/megacells/integration/appmek/item/MEGARadioactiveCell.java +++ b/forge/src/main/java/gripe/_90/megacells/integration/appmek/item/RadioactiveCellItem.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.Optional; import org.jetbrains.annotations.NotNull; @@ -31,10 +30,10 @@ import gripe._90.megacells.definition.MEGATranslations; -public class MEGARadioactiveCell extends AEBaseItem implements ICellWorkbenchItem { +public class RadioactiveCellItem extends AEBaseItem implements ICellWorkbenchItem { public static final Handler HANDLER = new Handler(); - public MEGARadioactiveCell(Properties properties) { + public RadioactiveCellItem(Properties properties) { super(properties.stacksTo(1)); } @@ -108,14 +107,13 @@ private Handler() {} @Override public boolean isCell(ItemStack is) { - return is != null && is.getItem() instanceof MEGARadioactiveCell; + return is != null && is.getItem() instanceof RadioactiveCellItem; } @Nullable @Override - public RadioactiveCellInventory getCellInventory(ItemStack is, @Nullable ISaveProvider container) { - Objects.requireNonNull(is, "Cannot create cell inventory for null itemstack"); - return isCell(is) ? new RadioactiveCellInventory((MEGARadioactiveCell) is.getItem(), is, container) : null; + public RadioactiveCellInventory getCellInventory(ItemStack is, @Nullable ISaveProvider host) { + return isCell(is) ? new RadioactiveCellInventory(is, host) : null; } } }