Skip to content

Commit

Permalink
refactor registry
Browse files Browse the repository at this point in the history
introduce portable DISK cells
introduce higher capacities of item and fluid cells and their portable counterparts
fix advanced inscriber filling all slots with same item closes #8
bump to 1.1.0
  • Loading branch information
ProjectET committed Apr 24, 2022
1 parent 5e82102 commit 8dd3fce
Show file tree
Hide file tree
Showing 13 changed files with 534 additions and 205 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3
# Mod Properties
mod_version=1.0.2-beta.3
mod_version=1.1.0-beta.1
maven_group=io.github.projectet
archives_base_name=AE2Things
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.47.8+1.18.2
ae2_version=11.0.0-alpha.1
ae2_version=11.0.0-alpha.3
cloth_config_version=6.0.42
rei_version=8.0.438
wthit_version=4.8.0
7 changes: 2 additions & 5 deletions src/main/java/io/github/projectet/ae2things/AE2Things.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import appeng.api.IAEAddonEntrypoint;
import appeng.api.storage.StorageCells;
import appeng.api.upgrades.Upgrades;
import appeng.block.AEBaseEntityBlock;
import appeng.block.AEBaseBlockItem;
import appeng.core.definitions.AEItems;
import io.github.projectet.ae2things.block.BlockAdvancedInscriber;
import io.github.projectet.ae2things.block.BlockCrystalGrowth;
Expand All @@ -21,7 +21,6 @@
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -49,7 +48,7 @@ public static Identifier id(String path) {

private void registerBlockwithItem(String path, Block block) {
Registry.register(Registry.BLOCK, id(path), block);
Registry.register(Registry.ITEM, id(path), new BlockItem(block, new Item.Settings().group(ITEM_GROUP)));
Registry.register(Registry.ITEM, id(path), new AEBaseBlockItem(block, new Item.Settings().group(ITEM_GROUP)));
}

@Override
Expand All @@ -61,10 +60,8 @@ public void onAe2Initialized() {
StorageCells.addCellGuiHandler(new DISKItemCellGuiHandler());

registerBlockwithItem("advanced_inscriber", ADVANCED_INSCRIBER);
((AEBaseEntityBlock<BEAdvancedInscriber>) ADVANCED_INSCRIBER).setBlockEntity(BEAdvancedInscriber.class, ADVANCED_INSCRIBER_BE, null, null);

registerBlockwithItem("crystal_growth", CRYSTAL_GROWTH);
((AEBaseEntityBlock<BECrystalGrowth>) CRYSTAL_GROWTH).setBlockEntity(BECrystalGrowth.class, CRYSTAL_GROWTH_BE, null, null);

Upgrades.add(AEItems.SPEED_CARD, ADVANCED_INSCRIBER, 5);
Upgrades.add(AEItems.SPEED_CARD, CRYSTAL_GROWTH, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public BlockAdvancedInscriber(Settings settings) {
super(settings);
settings.requiresTool();
this.setDefaultState(this.getDefaultState().with(SMASHING, false));
setBlockEntity(BEAdvancedInscriber.class, AE2Things.ADVANCED_INSCRIBER_BE, null, null);
}

public static final BooleanProperty SMASHING = BooleanProperty.of("smashing");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public BlockCrystalGrowth(Settings settings) {
super(settings);
settings.requiresTool();
this.setDefaultState(this.getDefaultState().with(WORKING, false));
setBlockEntity(BECrystalGrowth.class, AE2Things.CRYSTAL_GROWTH_BE, null, null);
}

public static final BooleanProperty WORKING = BooleanProperty.of("working");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import appeng.blockentity.grid.AENetworkPowerBlockEntity;
import appeng.blockentity.misc.InscriberRecipes;
import appeng.core.definitions.AEItems;
import appeng.core.definitions.ItemDefinition;
import appeng.core.settings.TickRates;
import appeng.me.helpers.MachineSource;
import appeng.recipes.handlers.InscriberProcessType;
Expand Down Expand Up @@ -113,22 +114,11 @@ public void onChangeInventory(InternalInventory inv, int slot) {
getMainNode().ifPresent((grid, node) -> grid.getTickManager().wakeDevice(node));
}

@Override
public void setOrientation(final Direction inForward, final Direction inUp) {
setPowerSides(EnumSet.allOf(Direction.class));
}

@Override
public IUpgradeInventory getUpgrades() {
return upgrades;
}

@Override
public void onReady() {
this.getMainNode().setExposedOnSides(EnumSet.allOf(Direction.class));
super.onReady();
}

private void setClientStart(long clientStart) {
this.clientStart = clientStart;
}
Expand Down Expand Up @@ -251,7 +241,7 @@ public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall)
this.sideItemHandler.extractItem(0, 1, false);
}

if(sideItemHandler.getStackInSlot(1).getItem() != Items.AIR) {
if (sideItemHandler.getStackInSlot(1).getItem() != Items.AIR) {
ItemStack outStack = sideItemHandler.getStackInSlot(1);
AEKey itemKey = AEItemKey.of(outStack);
long inserted = getMainNode().getGrid().getStorageService().getInventory().insert(itemKey, outStack.getCount(), Actionable.MODULATE, new MachineSource(this));
Expand Down Expand Up @@ -343,10 +333,26 @@ public boolean allowInsert(InternalInventory inv, int slot, ItemStack stack) {
}

if (inv == BEAdvancedInscriber.this.topItemHandler || inv == BEAdvancedInscriber.this.botItemHandler) {
ItemStack bot = BEAdvancedInscriber.this.botItemHandler.getStackInSlot(0);
ItemStack top = BEAdvancedInscriber.this.topItemHandler.getStackInSlot(0);

if (AEItems.NAME_PRESS.isSameAs(stack)) {
return true;
}
return InscriberRecipes.isValidOptionalIngredient(getWorld(), stack);

if (inv == BEAdvancedInscriber.this.topItemHandler) {
if (bot == ItemStack.EMPTY || bot == null) {
return InscriberRecipes.isValidOptionalIngredient(getWorld(), stack);
}
return InscriberRecipes.isValidOptionalIngredientCombination(getWorld(), stack, bot);
}
else {
if (top == ItemStack.EMPTY || top == null) {
return InscriberRecipes.isValidOptionalIngredient(getWorld(), stack);
}
return InscriberRecipes.isValidOptionalIngredientCombination(getWorld(), stack, top);
}
//return InscriberRecipes.isValidOptionalIngredient(getWorld(), stack);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public BECrystalGrowth(BlockPos pos, BlockState state) {

@Override
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(TickRates.Inscriber, !this.hasWork(), true);
return new TickingRequest(1, 20, !this.hasWork() && inventory.isEmpty(), true);
}

public boolean isWorking() {
Expand All @@ -82,28 +82,24 @@ public boolean hasWork() {
}

private boolean hasFluixIngredients() {
Storage<ItemVariant> inv = inventory.toStorage();
try(Transaction transaction = Transaction.openOuter()) {
boolean hasRedstone = inv.simulateExtract(ItemVariant.of(Items.REDSTONE), 1, transaction) == 1;
boolean hasChargedCertus = inv.simulateExtract(ItemVariant.of(AEItems.CERTUS_QUARTZ_CRYSTAL_CHARGED.asItem()), 1, transaction) == 1;;
boolean hasQuartz = inv.simulateExtract(ItemVariant.of(Items.QUARTZ), 1, transaction) == 1;
transaction.commit();
boolean hasRedstone = inventory.simulateRemove(1, new ItemStack(Items.REDSTONE), null).getCount() == 1;
boolean hasChargedCertus = inventory.simulateRemove(1, new ItemStack(AEItems.CERTUS_QUARTZ_CRYSTAL_CHARGED.asItem()), null).getCount() == 1;
boolean hasQuartz = inventory.simulateRemove(1, new ItemStack(Items.QUARTZ), null).getCount() == 1;

return hasRedstone && hasChargedCertus && hasQuartz;
}

}

@Override
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
if(hasWork()) {
if (hasWork()) {
final int speedFactor = 1 + this.upgrades.getInstalledUpgrades(AEItems.SPEED_CARD);
final IEnergyService[] eg = new IEnergyService[1];
IEnergySource src = this;
getMainNode().ifPresent(iGrid -> {
eg[0] = iGrid.getEnergyService();
});
if(eg[0] == null) {
if (eg[0] == null) {
return TickRateModulation.IDLE;
}
final int powerConsumption = 10 * speedFactor;
Expand All @@ -115,13 +111,13 @@ public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall)
}

if (powerReq > powerThreshold) {
if(!isWorking()) {
if (!isWorking()) {
isWorking = true;
markForUpdate();
}
src.extractAEPower(powerConsumption, Actionable.MODULATE, PowerMultiplier.CONFIG);
} else {
if(isWorking()) {
if (isWorking()) {
isWorking = false;
this.markForUpdate();
}
Expand All @@ -130,44 +126,38 @@ public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall)

for (Integer slot : cachedGrowable.stream().toList()) {
ItemStack crystal = inventory.getStackInSlot(slot);
if(!(crystal.getItem() instanceof IGrowableCrystal)) {
if (!(crystal.getItem() instanceof IGrowableCrystal)) {
cachedGrowable.remove(slot);
continue;
}
inventory.setItemDirect(slot, triggerGrowth(crystal, 20, speedFactor));
this.saveChanges();
}
if(hasFluixIngredients()) {
try(Transaction context = Transaction.openOuter()) {
int redstone = inventory.removeItems(1, new ItemStack(Items.REDSTONE), null).getCount();
int chargedCertus = inventory.removeItems(1, new ItemStack(AEItems.CERTUS_QUARTZ_CRYSTAL_CHARGED.asItem()), null).getCount();
int quartz = inventory.removeItems(1, new ItemStack(Items.QUARTZ), null).getCount();

inventory.addItems(new ItemStack(AEItems.FLUIX_DUST, 2));
if (redstone == 1 && chargedCertus == 1 && quartz == 1) {
context.commit();
this.saveChanges();
}
}
if (hasFluixIngredients()) {
inventory.removeItems(1, new ItemStack(Items.REDSTONE), null);
inventory.removeItems(1, new ItemStack(AEItems.CERTUS_QUARTZ_CRYSTAL_CHARGED.asItem()), null);
inventory.removeItems(1, new ItemStack(Items.QUARTZ), null);
inventory.addItems(new ItemStack(AEItems.FLUIX_DUST, 2));
this.saveChanges();
}
if(cachedGrowable.isEmpty() && !hasFluixIngredients()) {
if (cachedGrowable.isEmpty() && !hasFluixIngredients()) {
isWorking = false;
markForUpdate();
}
}
if(!inventory.isEmpty()) {
if (!inventory.isEmpty()) {
MEStorage gridStorage = getMainNode().getGrid().getStorageService().getInventory();
for(ItemStack stack: inventory) {
if(stack.equals(ItemStack.EMPTY) || stack.getItem().equals(Items.AIR))
for (ItemStack stack: inventory) {
if (stack.equals(ItemStack.EMPTY) || stack.getItem().equals(Items.AIR))
continue;
if(!FilteredInventory.canTransfer(stack.getItem())) {
if (!FilteredInventory.canTransfer(stack.getItem())) {
AEItemKey item = AEItemKey.of(stack);
long inserted = gridStorage.insert(item, stack.getCount(), Actionable.MODULATE, new MachineSource(this));
stack.decrement((int) inserted);
}
}
}
return hasWork() ? TickRateModulation.URGENT : TickRateModulation.SLEEP;
return hasWork() ? TickRateModulation.URGENT : !inventory.isEmpty() ? TickRateModulation.SLOWER : TickRateModulation.SLEEP;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
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;
import io.github.projectet.ae2things.gui.crystalGrowth.CrystalGrowthRootPanel;
import io.github.projectet.ae2things.item.AETItems;
import io.github.projectet.ae2things.item.DISKDrive;
import io.github.projectet.ae2things.item.PortableDISKItem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;

import java.io.FileNotFoundException;

@Environment(EnvType.CLIENT)
public class AE2ThingsClient implements IAEAddonEntrypoint {
Expand Down Expand Up @@ -49,5 +47,8 @@ public void onAe2Initialized() {
});

ColorProviderRegistry.ITEM.register(DISKDrive::getColor, AETItems.DISK_DRIVE_1K, AETItems.DISK_DRIVE_4K, AETItems.DISK_DRIVE_16K, AETItems.DISK_DRIVE_64K);
ColorProviderRegistry.ITEM.register(BasicStorageCell::getColor, AETItems.FLUID_CELL_256K, AETItems.FLUID_CELL_1024K, AETItems.FLUID_CELL_4096K, AETItems.ITEM_CELL_256K, AETItems.ITEM_CELL_1024K, AETItems.ITEM_CELL_4096K);
ColorProviderRegistry.ITEM.register(PortableDISKItem::getColor, AETItems.PORTABLE_DISK_1K, AETItems.PORTABLE_DISK_4K, AETItems.PORTABLE_DISK_16K, AETItems.PORTABLE_DISK_64K);
ColorProviderRegistry.ITEM.register(PortableCellItem::getColor, AETItems.PORTABLE_ITEM_256K, AETItems.PORTABLE_ITEM_1024K, AETItems.PORTABLE_ITEM_4096K, AETItems.PORTABLE_FLUID_256K, AETItems.PORTABLE_FLUID_1024K, AETItems.PORTABLE_FLUID_4096K);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.github.projectet.ae2things.gui.cell;

import appeng.api.config.*;
import appeng.api.implementations.menuobjects.IPortableTerminal;
import appeng.api.implementations.menuobjects.ItemMenuHost;
import appeng.api.storage.MEStorage;
import appeng.api.util.IConfigManager;
import appeng.menu.ISubMenu;
import appeng.util.ConfigManager;
import com.google.common.base.Preconditions;
import io.github.projectet.ae2things.item.PortableDISKItem;
import io.github.projectet.ae2things.storage.DISKCellHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.function.BiConsumer;

public class PortableDISKMenuHost extends ItemMenuHost implements IPortableTerminal {

private final BiConsumer<PlayerEntity, ISubMenu> returnMainMenu;
private final MEStorage cellStorage;
private final PortableDISKItem item;

public PortableDISKMenuHost(PlayerEntity player, @Nullable Integer slot, PortableDISKItem diskItem, ItemStack itemStack, BiConsumer<PlayerEntity, ISubMenu> returnMainMenu) {
super(player, slot, itemStack);
Preconditions.checkArgument(itemStack.getItem() == diskItem, "Stack doesn't match item");
this.returnMainMenu = returnMainMenu;
this.cellStorage = DISKCellHandler.INSTANCE.getCellInventory(itemStack, null);
Objects.requireNonNull(cellStorage, "Portable cell doesn't expose a cell inventory.");
this.item = diskItem;
}

@Override
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) {
amt = usePowerMultiplier.multiply(amt);

if (mode == Actionable.SIMULATE) {
return usePowerMultiplier.divide(Math.min(amt, this.item.getAECurrentPower(getItemStack())));
}

return usePowerMultiplier.divide(this.item.extractAEPower(getItemStack(), amt, Actionable.MODULATE));
}

@Override
public boolean onBroadcastChanges(ScreenHandler menu) {
return ensureItemStillInSlot() && drainPower();
}

@Nullable
@Override
public MEStorage getInventory() {
return cellStorage;
}

@Override
public void returnToMainMenu(PlayerEntity player, ISubMenu subMenu) {
returnMainMenu.accept(player, subMenu);
}

@Override
public ItemStack getMainMenuIcon() {
return getItemStack();
}

@Override
public IConfigManager getConfigManager() {
var out = new ConfigManager((manager, settingName) -> {
manager.writeToNBT(getItemStack().getOrCreateNbt());
});

out.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);

out.readFromNBT(getItemStack().getOrCreateNbt().copy());
return out;
}
}

0 comments on commit 8dd3fce

Please sign in to comment.