Skip to content

Commit

Permalink
Add back chest/drive cell models
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jul 14, 2024
1 parent 65bc21c commit a96089a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
29 changes: 19 additions & 10 deletions src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.neoforged.neoforge.event.server.ServerStartedEvent;

import appeng.api.AECapabilities;
import appeng.api.client.StorageCellModels;
import appeng.api.features.HotkeyAction;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.GridServices;
Expand Down Expand Up @@ -77,7 +78,6 @@
import gripe._90.megacells.menu.MEGAPatternProviderMenu;
import gripe._90.megacells.misc.CompressionService;
import gripe._90.megacells.misc.DecompressionService;
import gripe._90.megacells.misc.LavaTransformLogic;

@Mod(MEGACells.MODID)
public class MEGACells {
Expand All @@ -93,11 +93,10 @@ public MEGACells(ModContainer container, IEventBus modEventBus) {

modEventBus.addListener(MEGACells::initUpgrades);
modEventBus.addListener(MEGACells::initStorageCells);
modEventBus.addListener(MEGACells::initVillagerTrades);
modEventBus.addListener(MEGACells::initCapabilities);
modEventBus.addListener(MEGACells::initVillagerTrades);

initCompression();
initLavaTransform();

container.registerConfig(ModConfig.Type.COMMON, MEGAConfig.SPEC);

Expand Down Expand Up @@ -223,13 +222,6 @@ private static void initCompression() {
GridServices.register(DecompressionService.class, DecompressionService.class);
}

private static void initLavaTransform() {
NeoForge.EVENT_BUS.addListener((ServerStartedEvent event) -> LavaTransformLogic.clearCache());
NeoForge.EVENT_BUS.addListener((OnDatapackSyncEvent event) -> {
if (event.getPlayer() == null) LavaTransformLogic.clearCache();
});
}

@SuppressWarnings("UnstableApiUsage")
private static void initCapabilities(RegisterCapabilitiesEvent event) {
for (var type : MEGABlockEntities.DR.getEntries()) {
Expand Down Expand Up @@ -269,6 +261,7 @@ private static void init(IEventBus modEventBus) {
modEventBus.addListener(Client::initScreens);
modEventBus.addListener(Client::initCraftingUnitModels);
modEventBus.addListener(Client::initEnergyCellProps);
modEventBus.addListener(Client::initStorageCellModels);
modEventBus.addListener(Client::initItemColours);
}

Expand Down Expand Up @@ -313,6 +306,22 @@ private static void initEnergyCellProps(FMLClientSetupEvent event) {
}));
}

private static void initStorageCellModels(FMLClientSetupEvent event) {
event.enqueueWork(() -> {
var modelPrefix = "block/drive/cells/";

for (var cell : MEGAItems.getAllCells()) {
StorageCellModels.registerModel(
cell.item(),
makeId(modelPrefix + cell.tier().namePrefix() + "_" + cell.keyType() + "_cell"));
}

StorageCellModels.registerModel(
MEGAItems.BULK_ITEM_CELL,
makeId(modelPrefix + MEGAItems.BULK_ITEM_CELL.id().getPath()));
});
}

private static void initItemColours(RegisterColorHandlersEvent.Item event) {
var standardCells = new ArrayList<ItemLike>();
standardCells.addAll(MEGAItems.getItemCells());
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/gripe/_90/megacells/definition/MEGAItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ public final class MEGAItems {
public static final DeferredRegister.Items DR = DeferredRegister.createItems(MEGACells.MODID);

private static final List<ItemDefinition<?>> ITEMS = new ArrayList<>();
private static final List<CellDefinition> CELLS = new ArrayList<>();

public static List<ItemDefinition<?>> getItems() {
return Collections.unmodifiableList(ITEMS);
}

public static List<CellDefinition> getAllCells() {
return Collections.unmodifiableList(CELLS);
}

public static final ItemDefinition<MaterialItem> SKY_STEEL_INGOT =
item("Sky Steel Ingot", "sky_steel_ingot", p -> new MaterialItem(p.fireResistant()));
public static final ItemDefinition<MaterialItem> SKY_BRONZE_INGOT =
Expand Down Expand Up @@ -125,11 +130,11 @@ public static List<ItemDefinition<?>> getItems() {
DecompressionModulePart.class,
DecompressionModulePart::new);

public static List<ItemDefinition<?>> getItemCells() {
public static List<ItemDefinition<BasicStorageCell>> getItemCells() {
return List.of(ITEM_CELL_1M, ITEM_CELL_4M, ITEM_CELL_16M, ITEM_CELL_64M, ITEM_CELL_256M);
}

public static List<ItemDefinition<?>> getFluidCells() {
public static List<ItemDefinition<BasicStorageCell>> getFluidCells() {
return List.of(FLUID_CELL_1M, FLUID_CELL_4M, FLUID_CELL_16M, FLUID_CELL_64M, FLUID_CELL_256M);
}

Expand Down Expand Up @@ -164,7 +169,7 @@ private static ItemDefinition<StorageComponentItem> component(int mb) {
}

private static ItemDefinition<BasicStorageCell> itemCell(StorageTier tier) {
return item(
var cell = item(
tier.namePrefix().toUpperCase() + " MEGA Item Storage Cell",
"item_storage_cell_" + tier.namePrefix(),
p -> new BasicStorageCell(
Expand All @@ -176,10 +181,12 @@ private static ItemDefinition<BasicStorageCell> itemCell(StorageTier tier) {
tier.bytes() / 128,
63,
AEKeyType.items()));
CELLS.add(new CellDefinition(cell, tier, "item"));
return cell;
}

private static ItemDefinition<BasicStorageCell> fluidCell(StorageTier tier) {
return item(
var cell = item(
tier.namePrefix().toUpperCase() + " MEGA Fluid Storage Cell",
"fluid_storage_cell_" + tier.namePrefix(),
p -> new BasicStorageCell(
Expand All @@ -191,21 +198,27 @@ private static ItemDefinition<BasicStorageCell> fluidCell(StorageTier tier) {
tier.bytes() / 128,
18,
AEKeyType.fluids()));
CELLS.add(new CellDefinition(cell, tier, "fluid"));
return cell;
}

private static ItemDefinition<MEGAPortableCell> itemPortable(StorageTier tier) {
return item(
var cell = item(
tier.namePrefix().toUpperCase() + " Portable Item Cell",
"portable_item_cell_" + tier.namePrefix(),
p -> new MEGAPortableCell(p, tier, AEKeyType.items(), MEStorageMenu.PORTABLE_ITEM_CELL_TYPE, 0x80caff));
CELLS.add(new CellDefinition(cell, tier, "item"));
return cell;
}

private static ItemDefinition<MEGAPortableCell> fluidPortable(StorageTier tier) {
return item(
var cell = item(
tier.namePrefix().toUpperCase() + " Portable Fluid Cell",
"portable_fluid_cell_" + tier.namePrefix(),
p -> new MEGAPortableCell(
p, tier, AEKeyType.fluids(), MEStorageMenu.PORTABLE_FLUID_CELL_TYPE, 0x80caff));
CELLS.add(new CellDefinition(cell, tier, "fluid"));
return cell;
}

private static <T extends IPart> ItemDefinition<PartItem<T>> part(
Expand All @@ -220,4 +233,6 @@ public static <T extends Item> ItemDefinition<T> item(
ITEMS.add(definition);
return definition;
}

public record CellDefinition(ItemDefinition<?> item, StorageTier tier, String keyType) {}
}
14 changes: 10 additions & 4 deletions src/main/java/gripe/_90/megacells/misc/LavaTransformLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.OnDatapackSyncEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent;

import appeng.recipes.transform.TransformRecipe;

public final class LavaTransformLogic {
private static final Set<Item> lavaCache = new HashSet<>();

static {
NeoForge.EVENT_BUS.addListener((ServerStartedEvent event) -> lavaCache.clear());
NeoForge.EVENT_BUS.addListener((OnDatapackSyncEvent event) -> {
if (event.getPlayer() == null) lavaCache.clear();
});
}

public static boolean canTransformInLava(ItemEntity entity) {
return getLavaTransformableItems(entity.level())
.contains(entity.getItem().getItem());
Expand Down Expand Up @@ -68,8 +78,4 @@ private static Set<Item> getLavaTransformableItems(Level level) {

return lavaCache;
}

public static void clearCache() {
lavaCache.clear();
}
}

0 comments on commit a96089a

Please sign in to comment.