Skip to content

Commit

Permalink
Begin work on adding a Portable Cell Workbench
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Nov 16, 2024
1 parent 2c32ea2 commit 20adbd0
Show file tree
Hide file tree
Showing 15 changed files with 610 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.data.models.blockstates.PropertyDispatch;
import net.minecraft.data.models.blockstates.Variant;
import net.minecraft.data.models.blockstates.VariantProperties;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.neoforged.neoforge.client.model.generators.ConfiguredModel;
import net.neoforged.neoforge.client.model.generators.ModelFile;
Expand Down Expand Up @@ -58,6 +59,7 @@ protected void registerStatesAndModels() {

basicItem(MEGAItems.GREATER_ENERGY_CARD);
basicItem(MEGAItems.COMPRESSION_CARD);
basicItem(MEGAItems.PORTABLE_CELL_WORKBENCH);

for (var cell : MEGAItems.getTieredCells()) {
if (cell.portable()) {
Expand Down Expand Up @@ -182,7 +184,7 @@ protected void registerStatesAndModels() {
}));
}

private void basicItem(ItemDefinition<?> item) {
private void basicItem(ItemLike item) {
itemModels().basicItem(item.asItem());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.1 2024-11-15T19:31:29.757213749 Language
01c5e0e544a51a97c1494a283b0c34a0e73b3f14 assets/megacells/lang/en_us.json
// 1.21.1 2024-11-15T20:14:53.378044013 Language
a77898c0ee75796bccabca2cf157f495702102d1 assets/megacells/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21.1 2024-11-15T19:31:29.758210643 Block States / Models
// 1.21.1 2024-11-15T20:14:53.378945918 Block States / Models
8d69a3c391bcb75b5aac370510d15fa9c367b200 assets/megacells/blockstates/16m_crafting_storage.json
6b8ebbdecbd556e59c1c0d9abb4222d5de046e9a assets/megacells/blockstates/1m_crafting_storage.json
c716f5bd44bda4274f6e5f2c2f2b09f6223a8de7 assets/megacells/blockstates/256m_crafting_storage.json
Expand Down Expand Up @@ -105,6 +105,7 @@ a31fadf8962f679c8fc76b36b705c49d64a494e4 assets/megacells/models/item/mega_inter
43bb96e2391a03b8d1782ce0765563c8cc722cad assets/megacells/models/item/mega_item_cell_housing.json
a4708e37ca1954b67e57a24d60c5955a437b0ef5 assets/megacells/models/item/mega_pattern_provider.json
6762bae761c01dfae6e5a358e1da5ec25b4b3c93 assets/megacells/models/item/mega_source_cell_housing.json
f9f81f7f70a276807ae69104dca94146e9f709b6 assets/megacells/models/item/portable_cell_workbench.json
05c359b2007ed45af3da1911571f48b6f2b84182 assets/megacells/models/item/portable_chemical_cell_16m.json
a5430292a6845f49fb8fc6e60611815b617323f8 assets/megacells/models/item/portable_chemical_cell_1m.json
3c2fd4a6757406e90eb49b972618a50255fa1e67 assets/megacells/models/item/portable_chemical_cell_256m.json
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/megacells/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"item.megacells.mega_fluid_cell_housing": "MEGA Fluid Cell Housing",
"item.megacells.mega_item_cell_housing": "MEGA Item Cell Housing",
"item.megacells.mega_source_cell_housing": "MEGA Source Cell Housing",
"item.megacells.portable_cell_workbench": "Portable Cell Workbench",
"item.megacells.portable_chemical_cell_16m": "16M Portable Chemical Cell",
"item.megacells.portable_chemical_cell_1m": "1M Portable Chemical Cell",
"item.megacells.portable_chemical_cell_256m": "256M Portable Chemical Cell",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "megacells:item/portable_cell_workbench"
}
}
6 changes: 6 additions & 0 deletions src/main/java/gripe/_90/megacells/client/MEGACellsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import gripe._90.megacells.block.MEGACraftingUnitType;
import gripe._90.megacells.client.render.MEGACraftingUnitModelProvider;
import gripe._90.megacells.client.screen.CellDockScreen;
import gripe._90.megacells.client.screen.PortableCellWorkbenchScreen;
import gripe._90.megacells.definition.MEGABlockEntities;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
Expand Down Expand Up @@ -58,6 +59,11 @@ private static void initScreens(RegisterMenuScreensEvent event) {
PatternProviderScreen<MEGAPatternProviderMenu>::new,
"/screens/megacells/mega_pattern_provider.json");
InitScreens.register(event, MEGAMenus.CELL_DOCK, CellDockScreen::new, "/screens/megacells/cell_dock.json");
InitScreens.register(
event,
MEGAMenus.PORTABLE_CELL_WORKBENCH,
PortableCellWorkbenchScreen::new,
"/screens/megacells/portable_cell_workbench.json");
}

private static void initCraftingUnitModels(FMLClientSetupEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package gripe._90.megacells.client.screen;

import java.util.ArrayList;
import java.util.List;

import org.jetbrains.annotations.NotNull;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;

import appeng.api.config.ActionItems;
import appeng.api.config.CopyMode;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.stacks.AEItemKey;
import appeng.api.stacks.GenericStack;
import appeng.client.gui.Icon;
import appeng.client.gui.implementations.UpgradeableScreen;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.ActionButton;
import appeng.client.gui.widgets.SettingToggleButton;
import appeng.client.gui.widgets.ToggleButton;
import appeng.core.definitions.AEItems;
import appeng.core.localization.GuiText;

import gripe._90.megacells.menu.PortableCellWorkbenchMenu;

/**
* See {@link appeng.client.gui.implementations.CellWorkbenchScreen}
*/
public class PortableCellWorkbenchScreen extends UpgradeableScreen<PortableCellWorkbenchMenu> {
private final ToggleButton copyMode;
private final SettingToggleButton<FuzzyMode> fuzzyMode;

public PortableCellWorkbenchScreen(
PortableCellWorkbenchMenu menu, Inventory playerInventory, Component title, ScreenStyle style) {
super(menu, playerInventory, title, style);
fuzzyMode = addToLeftToolbar(new SettingToggleButton<>(
Settings.FUZZY_MODE,
FuzzyMode.IGNORE_ALL,
(button, backwards) -> menu.setCellFuzzyMode(button.getNextValue(backwards))));
addToLeftToolbar(new ActionButton(ActionItems.COG, act -> menu.partition()));
addToLeftToolbar(new ActionButton(ActionItems.CLOSE, act -> menu.clear()));
copyMode = addToLeftToolbar(new ToggleButton(
Icon.COPY_MODE_ON,
Icon.COPY_MODE_OFF,
GuiText.CopyMode.text(),
GuiText.CopyModeDesc.text(),
act -> menu.nextWorkBenchCopyMode()));
}

@Override
protected void updateBeforeRender() {
super.updateBeforeRender();
copyMode.setState(menu.getCopyMode() == CopyMode.CLEAR_ON_REMOVE);
fuzzyMode.set(menu.getFuzzyMode());
fuzzyMode.setVisibility(menu.getUpgrades().isInstalled(AEItems.FUZZY_CARD));
}

@NotNull
@Override
protected List<Component> getTooltipFromContainerItem(@NotNull ItemStack stack) {
var cell = getMenu().getWorkbenchItem();

if (cell.isEmpty()) {
return super.getTooltipFromContainerItem(stack);
}

if (cell == stack) {
return super.getTooltipFromContainerItem(stack);
}

var genericStack = GenericStack.unwrapItemStack(stack);
var what = genericStack != null ? genericStack.what() : AEItemKey.of(stack);

if (what == null) {
return super.getTooltipFromContainerItem(stack);
}

var configInventory = getMenu().getHost().getCell().getConfigInventory(cell);

if (!configInventory.isSupportedType(what.getType())) {
var lines = new ArrayList<>(super.getTooltipFromContainerItem(stack));
lines.add(GuiText.IncompatibleWithCell.text().withStyle(ChatFormatting.RED));
return lines;
}

var filter = configInventory.getFilter();

if (filter != null) {
var anySlotMatches = false;

for (var i = 0; i < configInventory.size(); i++) {
if (configInventory.isAllowedIn(i, what)) {
anySlotMatches = true;
break;
}
}

if (!anySlotMatches) {
var lines = new ArrayList<>(super.getTooltipFromContainerItem(stack));
lines.add(GuiText.IncompatibleWithCell.text().withStyle(ChatFormatting.RED));
return lines;
}
}

return super.getTooltipFromContainerItem(stack);
}
}
4 changes: 4 additions & 0 deletions src/main/java/gripe/_90/megacells/definition/MEGAItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import gripe._90.megacells.integration.appmek.RadioactiveCellItem;
import gripe._90.megacells.item.cell.BulkCellItem;
import gripe._90.megacells.item.cell.MEGAPortableCell;
import gripe._90.megacells.item.cell.PortableCellWorkbenchItem;
import gripe._90.megacells.item.part.CellDockPart;
import gripe._90.megacells.item.part.DecompressionModulePart;
import gripe._90.megacells.item.part.MEGAInterfacePart;
Expand Down Expand Up @@ -125,8 +126,11 @@ public static List<CellDefinition> getTieredCells() {
PartModels.registerModels(PartModelsHelper.createModels(MEGAPatternProviderPart.class));
return item("MEGA Pattern Provider", "cable_mega_pattern_provider", MEGAPatternProviderPartItem::new);
});

public static final ItemDefinition<PartItem<CellDockPart>> CELL_DOCK =
part("ME Cell Dock", "cell_dock", CellDockPart.class, CellDockPart::new);
public static final ItemDefinition<PortableCellWorkbenchItem> PORTABLE_CELL_WORKBENCH =
item("Portable Cell Workbench", "portable_cell_workbench", PortableCellWorkbenchItem::new);

public static final ItemDefinition<?> SKY_OSMIUM_INGOT = integrationItem(
"Sky Osmium Ingot",
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gripe/_90/megacells/definition/MEGAMenus.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import appeng.menu.implementations.MenuTypeBuilder;

import gripe._90.megacells.MEGACells;
import gripe._90.megacells.item.cell.PortableCellWorkbenchMenuHost;
import gripe._90.megacells.item.part.CellDockPart;
import gripe._90.megacells.menu.CellDockMenu;
import gripe._90.megacells.menu.MEGAInterfaceMenu;
import gripe._90.megacells.menu.MEGAPatternProviderMenu;
import gripe._90.megacells.menu.PortableCellWorkbenchMenu;

public final class MEGAMenus {
public static final DeferredRegister<MenuType<?>> DR = DeferredRegister.create(Registries.MENU, MEGACells.MODID);
Expand All @@ -24,6 +26,8 @@ public final class MEGAMenus {
create("mega_pattern_provider", MEGAPatternProviderMenu::new, PatternProviderLogicHost.class);

public static final MenuType<CellDockMenu> CELL_DOCK = create("cell_dock", CellDockMenu::new, CellDockPart.class);
public static final MenuType<PortableCellWorkbenchMenu> PORTABLE_CELL_WORKBENCH =
create("portable_cell_workbench", PortableCellWorkbenchMenu::new, PortableCellWorkbenchMenuHost.class);

private static <M extends AEBaseMenu, H> MenuType<M> create(
String id, MenuTypeBuilder.MenuFactory<M, H> factory, Class<H> host) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package gripe._90.megacells.item.cell;

import javax.annotation.ParametersAreNonnullByDefault;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;

import appeng.api.implementations.menuobjects.IMenuItem;
import appeng.api.implementations.menuobjects.ItemMenuHost;
import appeng.items.AEBaseItem;
import appeng.menu.MenuOpener;
import appeng.menu.locator.ItemMenuHostLocator;
import appeng.menu.locator.MenuLocators;

import gripe._90.megacells.definition.MEGAMenus;

public class PortableCellWorkbenchItem extends AEBaseItem implements IMenuItem {
public PortableCellWorkbenchItem(Properties properties) {
super(properties.stacksTo(1));
}

@Nullable
@Override
public ItemMenuHost<?> getMenuHost(Player player, ItemMenuHostLocator locator, @Nullable BlockHitResult hitResult) {
return new PortableCellWorkbenchMenuHost(this, player, locator);
}

@ParametersAreNonnullByDefault
@NotNull
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
if (!level.isClientSide()) {
MenuOpener.open(MEGAMenus.PORTABLE_CELL_WORKBENCH, player, MenuLocators.forHand(player, hand));
}

return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), level.isClientSide());
}
}
Loading

0 comments on commit 20adbd0

Please sign in to comment.