Skip to content

Commit

Permalink
Refactor pattern provider menu
Browse files Browse the repository at this point in the history
Fixes a bug in which MEGA pattern providers could occasionally accept crafting patterns.
  • Loading branch information
62832 committed May 31, 2023
1 parent 09d13a4 commit 7e055d0
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
Expand All @@ -19,23 +21,43 @@
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.BlockHitResult;

import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IManagedGridNode;
import appeng.api.util.IOrientable;
import appeng.block.AEBaseBlockItem;
import appeng.block.AEBaseEntityBlock;
import appeng.core.definitions.AEItems;
import appeng.helpers.iface.PatternProviderLogic;
import appeng.helpers.iface.PatternProviderLogicHost;
import appeng.menu.implementations.MenuTypeBuilder;
import appeng.menu.implementations.PatternProviderMenu;
import appeng.menu.locator.MenuLocators;
import appeng.util.InteractionUtil;
import appeng.util.inv.AppEngInternalInventory;
import appeng.util.inv.filter.AEItemDefinitionFilter;

import gripe._90.megacells.block.entity.MEGAPatternProviderBlockEntity;
import gripe._90.megacells.definition.MEGATranslations;

public class MEGAPatternProviderBlock extends AEBaseEntityBlock<MEGAPatternProviderBlockEntity> {
public static final BooleanProperty OMNIDIRECTIONAL = BooleanProperty.create("omnidirectional");
public static final MenuType<Menu> MENU = MenuTypeBuilder
.create(Menu::new, PatternProviderLogicHost.class)
.requirePermission(SecurityPermissions.BUILD)
.build("mega_pattern_provider");

public MEGAPatternProviderBlock(Properties props) {
super(props);
registerDefaultState(defaultBlockState().setValue(OMNIDIRECTIONAL, true));
}

public static PatternProviderLogic createLogic(IManagedGridNode mainNode, PatternProviderLogicHost host) {
var logic = new PatternProviderLogic(mainNode, host, 18);
((AppEngInternalInventory) logic.getPatternInv())
.setFilter(new AEItemDefinitionFilter(AEItems.PROCESSING_PATTERN));
return logic;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
Expand Down Expand Up @@ -99,4 +121,10 @@ public void addCheckedInformation(ItemStack stack, Level level, List<Component>
tooltip.add(MEGATranslations.ProcessingOnly.text());
}
}

public static class Menu extends PatternProviderMenu {
public Menu(int id, Inventory playerInventory, PatternProviderLogicHost host) {
super(MENU, id, playerInventory, host);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import appeng.menu.MenuOpener;
import appeng.menu.locator.MenuLocator;

import gripe._90.megacells.block.MEGAPatternProviderBlock;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.menu.MEGAPatternProviderMenu;

public class MEGAPatternProviderBlockEntity extends PatternProviderBlockEntity {

Expand All @@ -24,17 +24,17 @@ public MEGAPatternProviderBlockEntity(BlockEntityType<?> blockEntityType, BlockP

@Override
public PatternProviderLogic createLogic() {
return new PatternProviderLogic(this.getMainNode(), this, 18);
return MEGAPatternProviderBlock.createLogic(this.getMainNode(), this);
}

@Override
public void openMenu(Player player, MenuLocator locator) {
MenuOpener.open(MEGAPatternProviderMenu.TYPE, player, locator);
MenuOpener.open(MEGAPatternProviderBlock.MENU, player, locator);
}

@Override
public void returnToMainMenu(Player player, ISubMenu subMenu) {
MenuOpener.returnTo(MEGAPatternProviderMenu.TYPE, player, subMenu.getLocator());
MenuOpener.returnTo(MEGAPatternProviderBlock.MENU, player, subMenu.getLocator());
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import appeng.parts.PartModel;
import appeng.parts.crafting.PatternProviderPart;

import gripe._90.megacells.block.MEGAPatternProviderBlock;
import gripe._90.megacells.definition.MEGAParts;
import gripe._90.megacells.menu.MEGAPatternProviderMenu;
import gripe._90.megacells.util.Utils;

public class MEGAPatternProviderPart extends PatternProviderPart {
Expand All @@ -46,17 +46,17 @@ public MEGAPatternProviderPart(IPartItem<?> partItem) {

@Override
public PatternProviderLogic createLogic() {
return new PatternProviderLogic(this.getMainNode(), this, 18);
return MEGAPatternProviderBlock.createLogic(this.getMainNode(), this);
}

@Override
public void openMenu(Player player, MenuLocator locator) {
MenuOpener.open(MEGAPatternProviderMenu.TYPE, player, locator);
MenuOpener.open(MEGAPatternProviderBlock.MENU, player, locator);
}

@Override
public void returnToMainMenu(Player player, ISubMenu subMenu) {
MenuOpener.returnTo(MEGAPatternProviderMenu.TYPE, player, subMenu.getLocator());
MenuOpener.returnTo(MEGAPatternProviderBlock.MENU, player, subMenu.getLocator());
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions fabric/src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import appeng.api.IAEAddonEntrypoint;
import appeng.core.AppEng;

import gripe._90.megacells.block.MEGAPatternProviderBlock;
import gripe._90.megacells.definition.MEGABlockEntities;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.definition.MEGAParts;
import gripe._90.megacells.init.InitStorageCells;
import gripe._90.megacells.init.InitUpgrades;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.menu.MEGAPatternProviderMenu;
import gripe._90.megacells.service.CompressionService;
import gripe._90.megacells.util.Utils;

Expand Down Expand Up @@ -54,7 +54,7 @@ private void registerAll() {
Registry.register(Registry.BLOCK_ENTITY_TYPE, blockEntity.getKey(), blockEntity.getValue());
}

Registry.register(Registry.MENU, AppEng.makeId("mega_pattern_provider"), MEGAPatternProviderMenu.TYPE);
Registry.register(Registry.MENU, AppEng.makeId("mega_pattern_provider"), MEGAPatternProviderBlock.MENU);
}

private void initCompression() {
Expand Down
5 changes: 3 additions & 2 deletions fabric/src/main/java/gripe/_90/megacells/MEGACellsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import appeng.items.tools.powered.PortableCellItem;

import gripe._90.megacells.block.MEGACraftingUnitType;
import gripe._90.megacells.block.MEGAPatternProviderBlock;
import gripe._90.megacells.client.render.MEGACraftingUnitModelProvider;
import gripe._90.megacells.definition.MEGABlockEntities;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.menu.MEGAPatternProviderMenu;
import gripe._90.megacells.util.Utils;

@Environment(EnvType.CLIENT)
Expand All @@ -52,7 +52,8 @@ public void onAe2Initialized() {

private void initScreens() {
ClientLifecycleEvents.CLIENT_STARTED.register(client -> {
InitScreens.register(MEGAPatternProviderMenu.TYPE, PatternProviderScreen<MEGAPatternProviderMenu>::new,
InitScreens.register(MEGAPatternProviderBlock.MENU,
PatternProviderScreen<MEGAPatternProviderBlock.Menu>::new,
"/screens/megacells/mega_pattern_provider.json");
});
}
Expand Down
4 changes: 2 additions & 2 deletions forge/src/main/java/gripe/_90/megacells/forge/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import appeng.core.AppEng;

import gripe._90.megacells.block.MEGAPatternProviderBlock;
import gripe._90.megacells.definition.MEGABlockEntities;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
Expand All @@ -23,7 +24,6 @@
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.integration.appmek.AppMekIntegration;
import gripe._90.megacells.integration.appmek.AppMekItems;
import gripe._90.megacells.menu.MEGAPatternProviderMenu;
import gripe._90.megacells.service.CompressionService;
import gripe._90.megacells.util.Utils;

Expand Down Expand Up @@ -74,7 +74,7 @@ private void registerAll(RegisterEvent event) {

if (event.getRegistryKey().equals(Registry.MENU_REGISTRY)) {
ForgeRegistries.MENU_TYPES.register(AppEng.makeId("mega_pattern_provider"),
MEGAPatternProviderMenu.TYPE);
MEGAPatternProviderBlock.MENU);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
import appeng.items.tools.powered.PortableCellItem;

import gripe._90.megacells.block.MEGACraftingUnitType;
import gripe._90.megacells.block.MEGAPatternProviderBlock;
import gripe._90.megacells.client.render.MEGACraftingUnitModelProvider;
import gripe._90.megacells.definition.MEGABlockEntities;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.integration.appmek.AppMekItems;
import gripe._90.megacells.menu.MEGAPatternProviderMenu;
import gripe._90.megacells.util.Utils;

public class MEGACellsClient {
Expand All @@ -49,7 +49,7 @@ public MEGACellsClient() {
}

private void initScreens(FMLClientSetupEvent ignoredEvent) {
InitScreens.register(MEGAPatternProviderMenu.TYPE, PatternProviderScreen<MEGAPatternProviderMenu>::new,
InitScreens.register(MEGAPatternProviderBlock.MENU, PatternProviderScreen<MEGAPatternProviderBlock.Menu>::new,
"/screens/megacells/mega_pattern_provider.json");
}

Expand Down

0 comments on commit 7e055d0

Please sign in to comment.