Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for extended versions of ME Interfaces #7354

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/main/java/appeng/blockentity/misc/InterfaceBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

Expand Down Expand Up @@ -57,13 +56,16 @@ public void onGridChanged(InterfaceBlockEntity nodeOwner, IGridNode node) {
}
};

private final InterfaceLogic logic = new InterfaceLogic(this.getMainNode(), this,
getItemFromBlockEntity().asItem());
private final InterfaceLogic logic = createLogic();

public InterfaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState blockState) {
super(blockEntityType, pos, blockState);
}

protected InterfaceLogic createLogic() {
return new InterfaceLogic(getMainNode(), this, getItemFromBlockEntity().asItem());
}

@Override
protected IManagedGridNode createMainNode() {
return GridHelper.createManagedNode(this, NODE_LISTENER);
Expand Down Expand Up @@ -110,11 +112,6 @@ public InterfaceLogic getInterfaceLogic() {
return this.logic;
}

@Override
public BlockEntity getBlockEntity() {
return this;
}

@Override
public ItemStack getMainMenuIcon() {
return AEBlocks.INTERFACE.stack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import appeng.menu.SlotSemantics;
import appeng.menu.implementations.InterfaceMenu;

public class InterfaceScreen extends UpgradeableScreen<InterfaceMenu> {
public class InterfaceScreen<C extends InterfaceMenu> extends UpgradeableScreen<C> {

private final SettingToggleButton<FuzzyMode> fuzzyMode;
private final List<Button> amountButtons = new ArrayList<>();

public InterfaceScreen(InterfaceMenu menu, Inventory playerInventory, Component title,
public InterfaceScreen(C menu, Inventory playerInventory, Component title,
ScreenStyle style) {
super(menu, playerInventory, title, style);

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/appeng/helpers/InterfaceLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@
* Contains behavior for interface blocks and parts, which is independent of the storage channel.
*/
public class InterfaceLogic implements ICraftingRequester, IUpgradeableObject, IConfigurableObject {

public static final int NUMBER_OF_SLOTS = 9;
@Nullable
private InterfaceInventory localInvHandler;
@Nullable
Expand All @@ -88,7 +86,7 @@ public class InterfaceLogic implements ICraftingRequester, IUpgradeableObject, I
* Work planned by {@link #updatePlan()} to be performed by {@link #usePlan}. Positive amounts mean restocking from
* the network is required while negative amounts mean moving to the network is required.
*/
private final GenericStack[] plannedWork = new GenericStack[NUMBER_OF_SLOTS];
private final GenericStack[] plannedWork;
private int priority;
/**
* Configures what and how much to stock in this inventory.
Expand All @@ -101,9 +99,13 @@ public class InterfaceLogic implements ICraftingRequester, IUpgradeableObject, I
private final ConfigInventory storage;

public InterfaceLogic(IManagedGridNode gridNode, InterfaceLogicHost host, Item is) {
this(gridNode, host, is, 9);
}

public InterfaceLogic(IManagedGridNode gridNode, InterfaceLogicHost host, Item is, int slots) {
this.host = host;
this.config = ConfigInventory.configStacks(null, NUMBER_OF_SLOTS, this::onConfigRowChanged, false);
this.storage = ConfigInventory.storage(NUMBER_OF_SLOTS, this::onStorageChanged);
this.config = ConfigInventory.configStacks(null, slots, this::onConfigRowChanged, false);
this.storage = ConfigInventory.storage(slots, this::onStorageChanged);
this.mainNode = gridNode
.setFlags(GridFlags.REQUIRE_CHANNEL)
.addService(IGridTickable.class, new Ticker());
Expand All @@ -113,8 +115,9 @@ public InterfaceLogic(IManagedGridNode gridNode, InterfaceLogicHost host, Item i

gridNode.addService(ICraftingRequester.class, this);
this.upgrades = UpgradeInventories.forMachine(is, 1, this::onUpgradesChanged);
this.craftingTracker = new MultiCraftingTracker(this, 9);
this.craftingTracker = new MultiCraftingTracker(this, slots);
this.cm.registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.plannedWork = new GenericStack[slots];

getConfig().useRegisteredCapacities();
getStorage().useRegisteredCapacities();
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/appeng/init/client/InitScreens.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,20 @@ private InitScreens() {
}

public static void init() {
// spotless:off
register(QNBMenu.TYPE, QNBScreen::new, "/screens/qnb.json");
register(SkyChestMenu.TYPE, SkyChestScreen::new, "/screens/sky_chest.json");
register(ChestMenu.TYPE, ChestScreen::new, "/screens/chest.json");
register(WirelessAccessPointMenu.TYPE, WirelessAccessPointScreen::new, "/screens/wireless_access_point.json");
register(NetworkStatusMenu.NETWORK_TOOL_TYPE, NetworkStatusScreen::new, "/screens/network_status.json");
register(NetworkStatusMenu.CONTROLLER_TYPE, NetworkStatusScreen::new, "/screens/network_status.json");
InitScreens.<CraftingCPUMenu, CraftingCPUScreen<CraftingCPUMenu>>register(
CraftingCPUMenu.TYPE,
CraftingCPUScreen::new,
"/screens/crafting_cpu.json");
register(CraftingCPUMenu.TYPE, CraftingCPUScreen<CraftingCPUMenu>::new, "/screens/crafting_cpu.json");
register(NetworkToolMenu.TYPE, NetworkToolScreen::new, "/screens/network_tool.json");
register(QuartzKnifeMenu.TYPE, QuartzKnifeScreen::new, "/screens/quartz_knife.json");
register(DriveMenu.TYPE, DriveScreen::new, "/screens/drive.json");
register(VibrationChamberMenu.TYPE, VibrationChamberScreen::new, "/screens/vibration_chamber.json");
register(CondenserMenu.TYPE, CondenserScreen::new, "/screens/condenser.json");
register(InterfaceMenu.TYPE, InterfaceScreen::new, "/screens/interface.json");
register(InterfaceMenu.TYPE, InterfaceScreen<InterfaceMenu>::new, "/screens/interface.json");
register(IOBusMenu.EXPORT_TYPE, IOBusScreen::new, "/screens/export_bus.json");
register(IOBusMenu.IMPORT_TYPE, IOBusScreen::new, "/screens/import_bus.json");
register(IOPortMenu.TYPE, IOPortScreen::new, "/screens/io_port.json");
Expand All @@ -145,10 +143,7 @@ public static void init() {
register(SpatialIOPortMenu.TYPE, SpatialIOPortScreen::new, "/screens/spatial_io_port.json");
register(InscriberMenu.TYPE, InscriberScreen::new, "/screens/inscriber.json");
register(CellWorkbenchMenu.TYPE, CellWorkbenchScreen::new, "/screens/cell_workbench.json");
InitScreens.<PatternProviderMenu, PatternProviderScreen<PatternProviderMenu>>register(
PatternProviderMenu.TYPE,
PatternProviderScreen::new,
"/screens/pattern_provider.json");
register(PatternProviderMenu.TYPE, PatternProviderScreen<PatternProviderMenu>::new, "/screens/pattern_provider.json");
register(MolecularAssemblerMenu.TYPE, MolecularAssemblerScreen::new, "/screens/molecular_assembler.json");
register(CraftAmountMenu.TYPE, CraftAmountScreen::new, "/screens/craft_amount.json");
register(CraftConfirmMenu.TYPE, CraftConfirmScreen::new, "/screens/craft_confirm.json");
Expand Down Expand Up @@ -187,6 +182,7 @@ public static void init() {
InitScreens.<PatternAccessTermMenu, PatternAccessTermScreen<PatternAccessTermMenu>>register(
PatternAccessTermMenu.TYPE, PatternAccessTermScreen::new,
"/screens/terminals/pattern_access_terminal.json");
// spotless:on
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class InterfaceMenu extends UpgradeableMenu<InterfaceLogicHost> {
.create(InterfaceMenu::new, InterfaceLogicHost.class)
.build("interface");

public InterfaceMenu(MenuType<InterfaceMenu> menuType, int id, Inventory ip, InterfaceLogicHost host) {
public InterfaceMenu(MenuType<? extends InterfaceMenu> menuType, int id, Inventory ip, InterfaceLogicHost host) {
super(menuType, id, ip, host);

registerClientAction(ACTION_OPEN_SET_AMOUNT, Integer.class, this::openSetAmountMenu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public PatternProviderMenu(int id, Inventory playerInventory, PatternProviderLog
this(TYPE, id, playerInventory, host);
}

protected PatternProviderMenu(MenuType<?> menuType, int id, Inventory playerInventory,
protected PatternProviderMenu(MenuType<? extends PatternProviderMenu> menuType, int id, Inventory playerInventory,
PatternProviderLogicHost host) {
super(menuType, id, playerInventory, host);
this.createPlayerInventorySlots(playerInventory);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/appeng/parts/misc/InterfacePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ public void onGridChanged(InterfacePart nodeOwner, IGridNode node) {
public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
new ResourceLocation(AppEng.MOD_ID, "part/interface_has_channel"));

private final InterfaceLogic logic;
private final InterfaceLogic logic = createLogic();

public InterfacePart(IPartItem<?> partItem) {
super(partItem);
this.logic = new InterfaceLogic(this.getMainNode(), this, partItem.asItem());
}

protected InterfaceLogic createLogic() {
return new InterfaceLogic(getMainNode(), this, getPartItem().asItem());
}

@Override
Expand Down