Skip to content

Commit

Permalink
Update Advanced inscriber to include new base inscriber settings such…
Browse files Browse the repository at this point in the history
… as buffer size and autoexport

Remove equal distribution card from disk and portable disk
void card additions to disk
  • Loading branch information
ProjectET committed Aug 11, 2024
1 parent cc57f01 commit b9f3812
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ processResources {
}
}

def targetJavaVersion = 21
def targetJavaVersion = 17
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/io/github/projectet/ae2things/AE2Things.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import appeng.api.storage.StorageCells;
import appeng.api.upgrades.Upgrades;
import appeng.block.AEBaseBlockItem;
import appeng.blockentity.AEBaseBlockEntity;
import appeng.core.AppEng;
import appeng.core.definitions.AEItems;
import appeng.menu.SlotSemantic;
Expand Down Expand Up @@ -57,9 +58,9 @@ public static ResourceLocation id(String path) {
return new ResourceLocation(MOD_ID , path);
}

private void registerBlockwithItem(String path, Block block) {
AETItems.item(new AEBaseBlockItem(block, new Item.Properties()), path);
private Item registerBlockwithItem(String path, Block block) {
Registry.register(BuiltInRegistries.BLOCK, id(path), block);
return AETItems.item(new AEBaseBlockItem(block, new Item.Properties()), path);
}

@Override
Expand All @@ -71,11 +72,8 @@ public void onAe2Initialized() {
StorageCells.addCellHandler(DISKCellHandler.INSTANCE);
StorageCells.addCellGuiHandler(new DISKItemCellGuiHandler());



registerBlockwithItem("advanced_inscriber", ADVANCED_INSCRIBER);

registerBlockwithItem("crystal_growth", CRYSTAL_GROWTH);
AEBaseBlockEntity.registerBlockEntityItem(ADVANCED_INSCRIBER_BE, registerBlockwithItem("advanced_inscriber", ADVANCED_INSCRIBER));
AEBaseBlockEntity.registerBlockEntityItem(CRYSTAL_GROWTH_BE, registerBlockwithItem("crystal_growth", CRYSTAL_GROWTH));

AETItems.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import appeng.api.upgrades.IUpgradeInventory;
import appeng.api.upgrades.IUpgradeableObject;
import appeng.api.upgrades.UpgradeInventories;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.blockentity.grid.AENetworkPowerBlockEntity;
import appeng.blockentity.misc.InscriberRecipes;
import appeng.core.definitions.AEItems;
Expand Down Expand Up @@ -45,7 +47,7 @@
import java.util.List;
import java.util.Map;

public class BEAdvancedInscriber extends AENetworkPowerBlockEntity implements IGridTickable, IUpgradeableObject {
public class BEAdvancedInscriber extends AENetworkPowerBlockEntity implements IGridTickable, IUpgradeableObject, IConfigurableObject {

// cycles from 0 - 16, at 8 it preforms the action, at 16 it re-enables the
// normal routine.
Expand All @@ -58,6 +60,8 @@ public class BEAdvancedInscriber extends AENetworkPowerBlockEntity implements IG
private final InternalInventory botItemHandlerExtern;
private final InternalInventory sideItemHandlerExtern;

private final ConfigManager configManager;

private final InternalInventory combinedExtInventory;

private final InternalInventory inv = new CombinedInternalInventory(this.topItemHandler, this.botItemHandler, this.sideItemHandler);
Expand Down Expand Up @@ -85,12 +89,17 @@ public BEAdvancedInscriber(BlockPos pos, BlockState state) {

this.sideItemHandler.setMaxStackSize(1, 64);

this.configManager = new ConfigManager(this::onConfigChanged);

this.getMainNode()
.setExposedOnSides(EnumSet.allOf(Direction.class))
.setIdlePowerUsage(0)
.addService(IGridTickable.class, this);
this.setInternalMaxPower(1600);

this.configManager.registerSetting(Settings.AUTO_EXPORT, YesNo.NO);
this.configManager.registerSetting(Settings.INSCRIBER_BUFFER_SIZE, YesNo.YES);

var filter = new FilteredInventory();
this.topItemHandlerExtern = new FilteredInternalInventory(this.topItemHandler, filter);
this.botItemHandlerExtern = new FilteredInternalInventory(this.botItemHandler, filter);
Expand All @@ -102,6 +111,40 @@ public BEAdvancedInscriber(BlockPos pos, BlockState state) {
botLock = true;
}

private void onConfigChanged(IConfigManager manager, Setting<?> setting) {
if (setting == Settings.AUTO_EXPORT) {
getMainNode().ifPresent((grid, node) -> grid.getTickManager().wakeDevice(node));
}

if (setting == Settings.INSCRIBER_BUFFER_SIZE) {
if (configManager.getSetting(Settings.INSCRIBER_BUFFER_SIZE) == YesNo.YES) {
topItemHandler.setMaxStackSize(0, 64);
sideItemHandler.setMaxStackSize(0, 64);
botItemHandler.setMaxStackSize(0, 64);
} else {
topItemHandler.setMaxStackSize(0, 4);
sideItemHandler.setMaxStackSize(0, 4);
botItemHandler.setMaxStackSize(0, 4);
}
}

saveChanges();
}

@Override
protected void saveVisualState(CompoundTag data) {
super.saveVisualState(data);

data.putBoolean("working", isWorking());
}

@Override
protected void loadVisualState(CompoundTag data) {
super.loadVisualState(data);

working = (data.getBoolean("working"));
}

@Override
public InternalInventory getInternalInventory() {
return inv;
Expand Down Expand Up @@ -173,6 +216,11 @@ protected void writeToStream(FriendlyByteBuf data) {
}
}

private boolean hasAutoExportWork() {
return !this.sideItemHandler.getStackInSlot(1).isEmpty()
&& configManager.getSetting(Settings.AUTO_EXPORT) == YesNo.YES;
}

@Nullable
@Override
public InternalInventory getSubInventory(ResourceLocation id) {
Expand Down Expand Up @@ -246,7 +294,7 @@ private void setProcessingTime(int processingTime) {

@Override
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(TickRates.Inscriber, !this.hasWork(), false);
return new TickingRequest(TickRates.Inscriber, !this.hasWork() && !hasAutoExportWork(), true);
}

@Override
Expand Down Expand Up @@ -303,8 +351,37 @@ public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall)
}

}
if (this.pushOutResult()) {
return TickRateModulation.URGENT;
}

matchWork();
return this.hasWork() ? TickRateModulation.URGENT : TickRateModulation.SLEEP;
return this.hasWork() ? TickRateModulation.URGENT : this.hasAutoExportWork() ? TickRateModulation.SLOWER : TickRateModulation.SLEEP;
}

private boolean pushOutResult() {
if (!this.hasAutoExportWork()) {
return false;
}

var pushSides = EnumSet.allOf(Direction.class);

for (var dir : pushSides) {
var target = InternalInventory.wrapExternal(level, getBlockPos().relative(dir), dir.getOpposite());

if (target != null) {
int startItems = this.sideItemHandler.getStackInSlot(1).getCount();
this.sideItemHandler.insertItem(1, target.addItems(this.sideItemHandler.extractItem(1, 64, false)),
false);
int endItems = this.sideItemHandler.getStackInSlot(1).getCount();

if (startItems != endItems) {
return true;
}
}
}

return false;
}

public int getMaxProcessingTime() {
Expand All @@ -315,6 +392,11 @@ public int getProcessingTime() {
return this.processingTime;
}

@Override
public IConfigManager getConfigManager() {
return configManager;
}

public class FilteredInventory implements IAEItemFilter {
@Override
public boolean allowExtract(InternalInventory inv, int slot, int amount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import appeng.api.IAEAddonEntrypoint;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.style.StyleManager;
import appeng.items.storage.BasicStorageCell;
import appeng.items.tools.powered.PortableCellItem;
import io.github.projectet.ae2things.gui.advancedInscriber.AdvancedInscriberMenu;
import io.github.projectet.ae2things.gui.advancedInscriber.AdvancedInscriberRootPanel;
import io.github.projectet.ae2things.gui.crystalGrowth.CrystalGrowthMenu;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.github.projectet.ae2things.gui.advancedInscriber;

import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.inventories.InternalInventory;
import appeng.api.upgrades.IUpgradeableObject;
import appeng.api.util.IConfigManager;
import appeng.blockentity.misc.InscriberRecipes;
import appeng.core.definitions.AEItems;
import appeng.core.definitions.ItemDefinition;
Expand Down Expand Up @@ -41,6 +44,10 @@ public class AdvancedInscriberMenu extends UpgradeableMenu<BEAdvancedInscriber>
public boolean topLock;
@GuiSync(8)
public boolean botLock;
@GuiSync(9)
public YesNo autoExport = YesNo.NO;
@GuiSync(10)
public YesNo bufferSize = YesNo.YES;

public AdvancedInscriberMenu(int syncId, Inventory playerInventory, BEAdvancedInscriber advancedInscriber) {
super(ADVANCED_INSCRIBER_SHT, syncId, playerInventory, advancedInscriber);
Expand Down Expand Up @@ -76,6 +83,12 @@ protected void standardDetectAndSendChanges() {
super.standardDetectAndSendChanges();
}

@Override
protected void loadSettingsFromHost(IConfigManager cm) {
this.autoExport = getHost().getConfigManager().getSetting(Settings.AUTO_EXPORT);
this.bufferSize = getHost().getConfigManager().getSetting(Settings.INSCRIBER_BUFFER_SIZE);
}

@Override
public boolean isValidForSlot(Slot s, ItemStack is) {
final ItemStack top = inventory.getStackInSlot(0);
Expand Down Expand Up @@ -124,6 +137,14 @@ public boolean stillValid(Player player) {
return true;
}

public YesNo getAutoExport() {
return autoExport;
}

public YesNo getBufferSize() {
return bufferSize;
}

public void toggleBotLock() {
if (isClientSide()) {
sendClientAction("toggleBotLock");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.github.projectet.ae2things.gui.advancedInscriber;

import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.client.gui.Icon;
import appeng.client.gui.implementations.UpgradeableScreen;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.ProgressBar;
import appeng.client.gui.widgets.ServerSettingToggleButton;
import appeng.client.gui.widgets.SettingToggleButton;
import appeng.client.gui.widgets.ToggleButton;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -16,6 +20,8 @@ public class AdvancedInscriberRootPanel extends UpgradeableScreen<AdvancedInscri

private final ToggleButton botLock;

private final SettingToggleButton<YesNo> autoExportBtn;
private final SettingToggleButton<YesNo> bufferSizeBtn;

public AdvancedInscriberRootPanel(AdvancedInscriberMenu menu, Inventory playerInventory, Component title, ScreenStyle style) {
super(menu, playerInventory, title, style);
Expand All @@ -25,6 +31,12 @@ public AdvancedInscriberRootPanel(AdvancedInscriberMenu menu, Inventory playerIn
this.botLock = new ToggleButton(Icon.LOCKED, Icon.UNLOCKED, a -> menu.toggleBotLock());
widgets.add("topLock", topLock);
widgets.add("botLock", botLock);

this.autoExportBtn = new ServerSettingToggleButton<>(Settings.AUTO_EXPORT, YesNo.NO);
this.addToLeftToolbar(autoExportBtn);

this.bufferSizeBtn = new ServerSettingToggleButton<>(Settings.INSCRIBER_BUFFER_SIZE, YesNo.YES);
this.addToLeftToolbar(bufferSizeBtn);
}

@Override
Expand All @@ -36,5 +48,8 @@ protected void updateBeforeRender() {

int progress = this.menu.getCurrentProgress() * 100 / this.menu.getMaxProgress();
this.pb.setFullMsg(Component.literal(progress + "%"));

this.autoExportBtn.set(getMenu().getAutoExport());
this.bufferSizeBtn.set(getMenu().getBufferSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ private static <T extends Item> T registerCell(ResourceLocation model, T item, S
Upgrades.add(AEItems.FUZZY_CARD, item, 1, "gui.ae2things.upgrade.disk");
Upgrades.add(AEItems.VOID_CARD, item, 1, "gui.ae2things.upgrade.disk");
Upgrades.add(AEItems.INVERTER_CARD, item, 1, "gui.ae2things.upgrade.disk");
Upgrades.add(AEItems.EQUAL_DISTRIBUTION_CARD, item, 1, "gui.ae2things.upgrade.disk");
StorageCellModels.registerModel(item, model);

return item(item, id);
Expand All @@ -70,7 +69,6 @@ private static Item registerPortableDISK(ResourceLocation model, String id, Stor
Upgrades.add(AEItems.FUZZY_CARD, diskItem, 1, "gui.ae2things.upgrade.portabledisk");
Upgrades.add(AEItems.VOID_CARD, diskItem, 1, "gui.ae2things.upgrade.portabledisk");
Upgrades.add(AEItems.INVERTER_CARD, diskItem, 1, "gui.ae2things.upgrade.portabledisk");
Upgrades.add(AEItems.EQUAL_DISTRIBUTION_CARD, diskItem, 1, "gui.ae2things.upgrade.portabledisk");
Upgrades.add(AEItems.ENERGY_CARD, diskItem, 2, "gui.ae2things.upgrade.portabledisk");
StorageCellModels.registerModel(diskItem, model);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class DISKCellInventory implements StorageCell {
private Object2LongMap<AEKey> storedAmounts;
private final ItemStack i;
private boolean isPersisted = true;
private boolean hasVoidUpgrade;

public DISKCellInventory(IDISKCellItem cellType, ItemStack stack, ISaveProvider saveProvider) {
this.cellType = cellType;
Expand Down Expand Up @@ -77,6 +78,8 @@ private void updateFilter() {

partitionListMode = (hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
partitionList = builder.build();

this.hasVoidUpgrade = upgrades.isInstalled(AEItems.VOID_CARD);
}

private DataStorage getDiskStorage() {
Expand Down

0 comments on commit b9f3812

Please sign in to comment.