Skip to content

Commit

Permalink
Slight cell refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Oct 15, 2023
1 parent ace762f commit 817fed5
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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()
Expand Down
36 changes: 18 additions & 18 deletions common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,20 +84,20 @@ public static List<ItemDefinition<?>> getItems() {

public static final ItemDefinition<MaterialItem> BULK_CELL_COMPONENT =
item("MEGA Bulk Storage Component", "bulk_cell_component", MaterialItem::new);
public static final ItemDefinition<MEGABulkCell> BULK_ITEM_CELL =
item("MEGA Bulk Item Storage Cell", "bulk_item_cell", MEGABulkCell::new);
public static final ItemDefinition<BulkCellItem> BULK_ITEM_CELL =
item("MEGA Bulk Item Storage Cell", "bulk_item_cell", BulkCellItem::new);

public static final ItemDefinition<MEGAPortableCell> PORTABLE_ITEM_CELL_1M = itemPortable(TIER_1M);
public static final ItemDefinition<MEGAPortableCell> PORTABLE_ITEM_CELL_4M = itemPortable(TIER_4M);
public static final ItemDefinition<MEGAPortableCell> PORTABLE_ITEM_CELL_16M = itemPortable(TIER_16M);
public static final ItemDefinition<MEGAPortableCell> PORTABLE_ITEM_CELL_64M = itemPortable(TIER_64M);
public static final ItemDefinition<MEGAPortableCell> PORTABLE_ITEM_CELL_256M = itemPortable(TIER_256M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_ITEM_CELL_1M = itemPortable(TIER_1M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_ITEM_CELL_4M = itemPortable(TIER_4M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_ITEM_CELL_16M = itemPortable(TIER_16M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_ITEM_CELL_64M = itemPortable(TIER_64M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_ITEM_CELL_256M = itemPortable(TIER_256M);

public static final ItemDefinition<MEGAPortableCell> PORTABLE_FLUID_CELL_1M = fluidPortable(TIER_1M);
public static final ItemDefinition<MEGAPortableCell> PORTABLE_FLUID_CELL_4M = fluidPortable(TIER_4M);
public static final ItemDefinition<MEGAPortableCell> PORTABLE_FLUID_CELL_16M = fluidPortable(TIER_16M);
public static final ItemDefinition<MEGAPortableCell> PORTABLE_FLUID_CELL_64M = fluidPortable(TIER_64M);
public static final ItemDefinition<MEGAPortableCell> PORTABLE_FLUID_CELL_256M = fluidPortable(TIER_256M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_FLUID_CELL_1M = fluidPortable(TIER_1M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_FLUID_CELL_4M = fluidPortable(TIER_4M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_FLUID_CELL_16M = fluidPortable(TIER_16M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_FLUID_CELL_64M = fluidPortable(TIER_64M);
public static final ItemDefinition<MEGAPortableCellItem> PORTABLE_FLUID_CELL_256M = fluidPortable(TIER_256M);

public static final ItemDefinition<EnergyCardItem> GREATER_ENERGY_CARD =
item("Greater Energy Card", "greater_energy_card", p -> new EnergyCardItem(p, 8));
Expand Down Expand Up @@ -196,18 +196,18 @@ private static ItemDefinition<BasicStorageCell> fluidCell(StorageTier tier) {
AEKeyType.fluids()));
}

private static ItemDefinition<MEGAPortableCell> itemPortable(StorageTier tier) {
private static ItemDefinition<MEGAPortableCellItem> 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<MEGAPortableCell> fluidPortable(StorageTier tier) {
private static ItemDefinition<MEGAPortableCellItem> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MEStorageMenu> menu, int defaultColour) {
super(
keyType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -43,8 +43,8 @@ public static void init() {

public static final ItemDefinition<MaterialItem> RADIOACTIVE_CELL_COMPONENT =
MEGAItems.item("MEGA Radioactive Storage Component", "radioactive_cell_component", MaterialItem::new);
public static final ItemDefinition<MEGARadioactiveCell> RADIOACTIVE_CHEMICAL_CELL = MEGAItems.item(
"MEGA Radioactive Chemical Storage Cell", "radioactive_chemical_cell", MEGARadioactiveCell::new);
public static final ItemDefinition<RadioactiveCellItem> RADIOACTIVE_CHEMICAL_CELL = MEGAItems.item(
"MEGA Radioactive Chemical Storage Cell", "radioactive_chemical_cell", RadioactiveCellItem::new);

public static List<ItemDefinition<?>> getCells() {
return List.of(CHEMICAL_CELL_1M, CHEMICAL_CELL_4M, CHEMICAL_CELL_16M, CHEMICAL_CELL_64M, CHEMICAL_CELL_256M);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 817fed5

Please sign in to comment.