Skip to content

Commit

Permalink
Switch to registry lookup over reflection for AppBot portables
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Oct 3, 2023
1 parent 3e57346 commit 36e73da
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 46 deletions.
6 changes: 0 additions & 6 deletions common/src/main/java/gripe/_90/megacells/core/Loaders.java

This file was deleted.

2 changes: 0 additions & 2 deletions common/src/main/java/gripe/_90/megacells/core/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import net.minecraft.world.item.CreativeModeTab;

public interface Platform {
Loaders getLoader();

CreativeModeTab getCreativeTab();

boolean isAddonLoaded(Addons addon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,30 @@

import java.util.List;

import net.minecraft.core.Registry;
import net.minecraft.world.item.Item;

import appeng.api.upgrades.Upgrades;
import appeng.core.localization.GuiText;

import gripe._90.megacells.MEGACells;
import appbot.AppliedBotanics;

public final class AppBotIntegration {
private static final Class<?> APPBOT_ITEMS;

static {
try {
APPBOT_ITEMS = Class.forName("appbot.%s.ABItems"
.formatted(
switch (MEGACells.PLATFORM.getLoader()) {
case FABRIC -> "fabric";
case FORGE -> "forge";
}));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

public static void initUpgrades() {
AppBotItems.getPortables()
.forEach(c -> Upgrades.add(GREATER_ENERGY_CARD, c, 2, GuiText.PortableCells.getTranslationKey()));

for (var portable : List.of(
cell("PORTABLE_MANA_CELL_1K"),
cell("PORTABLE_MANA_CELL_4K"),
cell("PORTABLE_MANA_CELL_16K"),
cell("PORTABLE_MANA_CELL_64K"),
cell("PORTABLE_MANA_CELL_256K"))) {
cell("portable_mana_storage_cell_1k"),
cell("portable_mana_storage_cell_4k"),
cell("portable_mana_storage_cell_16k"),
cell("portable_mana_storage_cell_64k"),
cell("portable_mana_storage_cell_256k"))) {
Upgrades.add(GREATER_ENERGY_CARD, portable, 2, GuiText.PortableCells.getTranslationKey());
}
}

private static Item cell(String name) {
try {
return (Item) APPBOT_ITEMS.getDeclaredField(name).get(null);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
return Registry.ITEM.get(AppliedBotanics.id(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@

import gripe._90.megacells.MEGACells;
import gripe._90.megacells.core.Addons;
import gripe._90.megacells.core.Loaders;
import gripe._90.megacells.core.Platform;
import gripe._90.megacells.definition.MEGAItems;

public final class FabricPlatform implements Platform {
@Override
public Loaders getLoader() {
return Loaders.FABRIC;
}

@Override
public CreativeModeTab getCreativeTab() {
return FabricItemGroupBuilder.build(MEGACells.makeId("tab"), () -> new ItemStack(MEGAItems.ITEM_CELL_256M));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@

import gripe._90.megacells.MEGACells;
import gripe._90.megacells.core.Addons;
import gripe._90.megacells.core.Loaders;
import gripe._90.megacells.core.Platform;
import gripe._90.megacells.definition.MEGAItems;

public final class ForgePlatform implements Platform {
@Override
public Loaders getLoader() {
return Loaders.FORGE;
}

@Override
public CreativeModeTab getCreativeTab() {
return new CreativeModeTab(MEGACells.MODID + ".tab") {
Expand Down

0 comments on commit 36e73da

Please sign in to comment.