Skip to content

Commit

Permalink
Add a blank pattern refill upgrade to the pattern terminals (#305)
Browse files Browse the repository at this point in the history
* Add a blank pattern refill upgrade to the pattern terminals
GTNewHorizons/GT-New-Horizons-Modpack#10614

* fix getDrops()
call refilling at the terminal open and when adding refill upgrade

---------

Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
repo-alt and Dream-Master authored May 1, 2023
1 parent fe3f275 commit d49fa7a
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/appeng/api/config/Upgrades.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public enum Upgrades {
SUPERSPEED(1),
INVERTER(1),
PATTERN_CAPACITY(1),
ORE_FILTER(1);
ORE_FILTER(1),
PATTERN_REFILLER(0);

/**
* @deprecated use {@link Upgrades#getTier()}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/appeng/api/definitions/IMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@ public interface IMaterials {
IItemDefinition cardPatternCapacity();

IItemDefinition cardOreFilter();

IItemDefinition cardPatternRefiller();
}
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ public boolean hideItemPanelSlot(int tx, int ty, int tw, int th) {
if (this.viewCell) {
int rw = 33;
int rh = 14 + myCurrentViewCells.length * 18;
if (monitorableContainer.isAPatternTerminal()) rh += 21;

if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
Expand All @@ -46,6 +48,7 @@
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlacableItemType;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
Expand All @@ -55,6 +58,7 @@
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;

public class ContainerMEMonitorable extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack> {
Expand All @@ -74,6 +78,7 @@ public class ContainerMEMonitorable extends AEBaseContainer
private IConfigManagerHost gui;
private IConfigManager serverCM;
private IGridNode networkNode;
protected SlotRestrictedInput patternRefiller = null;

public ContainerMEMonitorable(final InventoryPlayer ip, final ITerminalHost monitorable) {
this(ip, monitorable, true);
Expand Down Expand Up @@ -141,6 +146,16 @@ protected ContainerMEMonitorable(final InventoryPlayer ip, final ITerminalHost m
this.addSlotToContainer(this.cellView[y]);
}
}
if (isAPatternTerminal()) {
patternRefiller = new SlotRestrictedInput(
PlacableItemType.UPGRADES,
((IUpgradeableHost) monitorable).getInventoryByName("upgrades"),
0,
206,
5 * 18 + 11,
this.getInventoryPlayer());
addSlotToContainer(patternRefiller);
}

if (bindInventory) {
this.bindPlayerInventory(ip, 0, 0);
Expand Down Expand Up @@ -365,4 +380,27 @@ private IConfigManagerHost getGui() {
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}

public boolean isAPatternTerminal() {
return false;
}

// to avoid duplicating this method in 2 pattern terminals
protected void refillBlankPatterns(Slot slot) {
ItemStack blanks = slot.getStack();
int blanksToRefill = 64;
if (blanks != null) blanksToRefill -= blanks.stackSize;
if (blanksToRefill <= 0) return;
final AEItemStack request = AEItemStack
.create(AEApi.instance().definitions().materials().blankPattern().maybeStack(blanksToRefill).get());
final IAEItemStack extracted = Platform
.poweredExtraction(this.getPowerSource(), this.getCellInventory(), request, this.getActionSource());
if (extracted != null) {
if (blanks != null) blanks.stackSize += extracted.getStackSize();
else {
blanks = extracted.getItemStack();
}
slot.putStack(blanks);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public ContainerPatternTerm(final InventoryPlayer ip, final ITerminalHost monito

this.bindPlayerInventory(ip, 0, 0);
this.updateOrderOfOutputSlots();
if (getPatternTerminal().hasRefillerUpgrade()) refillBlankPatterns(patternSlotIN);
}

private void updateOrderOfOutputSlots() {
Expand Down Expand Up @@ -197,6 +198,7 @@ public void encodeAndMoveToInventory(boolean encodeWholeStack) {
getPlayerInv().player.entityDropItem(output, 0);
}
this.patternSlotOUT.putStack(null);
if (getPatternTerminal().hasRefillerUpgrade()) refillBlankPatterns(patternSlotIN);
}
}

Expand Down Expand Up @@ -233,6 +235,7 @@ else if (output == null) {
output = encodedPatternStack;
this.patternSlotOUT.putStack(output);
}
if (getPatternTerminal().hasRefillerUpgrade()) refillBlankPatterns(patternSlotIN);
}

// encode the slot.
Expand Down Expand Up @@ -465,7 +468,8 @@ public void onUpdate(final String field, final Object oldValue, final Object new

@Override
public void onSlotChange(final Slot s) {
if (s == this.patternSlotOUT && Platform.isServer()) {
if (!Platform.isServer()) return;
if (s == this.patternSlotOUT) {
for (final Object crafter : this.crafters) {
final ICrafting icrafting = (ICrafting) crafter;

Expand All @@ -478,6 +482,9 @@ public void onSlotChange(final Slot s) {
((EntityPlayerMP) icrafting).isChangingQuantityOnly = false;
}
this.detectAndSendChanges();
} else if (s == patternRefiller && patternRefiller.getStack() != null) {
refillBlankPatterns(patternSlotIN);
detectAndSendChanges();
}
}

Expand Down Expand Up @@ -585,4 +592,8 @@ public void doubleStacks(boolean isShift) {
this.detectAndSendChanges();
}
}

public boolean isAPatternTerminal() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public ContainerPatternTermEx(final InventoryPlayer ip, final ITerminalHost moni
this.patternSlotOUT.setStackLimit(1);

this.bindPlayerInventory(ip, 0, 0);
if (getPatternTerminal().hasRefillerUpgrade()) refillBlankPatterns(patternSlotIN);
}

public void encodeAndMoveToInventory(boolean encodeWholeStack) {
Expand All @@ -150,6 +151,7 @@ public void encodeAndMoveToInventory(boolean encodeWholeStack) {
getPlayerInv().player.entityDropItem(output, 0);
}
this.patternSlotOUT.putStack(null);
if (getPatternTerminal().hasRefillerUpgrade()) refillBlankPatterns(patternSlotIN);
}
}

Expand Down Expand Up @@ -186,6 +188,7 @@ else if (output == null) {
output = encodedPatternStack;
this.patternSlotOUT.putStack(output);
}
if (getPatternTerminal().hasRefillerUpgrade()) refillBlankPatterns(patternSlotIN);
}

// encode the slot.
Expand Down Expand Up @@ -325,7 +328,8 @@ public void onUpdate(final String field, final Object oldValue, final Object new

@Override
public void onSlotChange(final Slot s) {
if (s == this.patternSlotOUT && Platform.isServer()) {
if (!Platform.isServer()) return;
if (s == this.patternSlotOUT) {
inverted = patternTerminal.isInverted();

for (final Object crafter : this.crafters) {
Expand All @@ -341,6 +345,9 @@ public void onSlotChange(final Slot s) {
}

this.detectAndSendChanges();
} else if (s == patternRefiller && patternRefiller.getStack() != null) {
refillBlankPatterns(patternSlotIN);
detectAndSendChanges();
}
}

Expand Down Expand Up @@ -410,4 +417,8 @@ public void doubleStacks(boolean isShift) {
this.detectAndSendChanges();
}
}

public boolean isAPatternTerminal() {
return true;
}
}
4 changes: 4 additions & 0 deletions src/main/java/appeng/core/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ void postInit(final FMLPostInitializationEvent event) {
// Inscriber
Upgrades.SPEED.registerItem(blocks.inscriber(), 3);

// Terminals
Upgrades.PATTERN_REFILLER.registerItem(parts.patternTerminal(), 1);
Upgrades.PATTERN_REFILLER.registerItem(parts.patternTerminalEx(), 1);

for (final Item wirelessTerminalItem : items.wirelessTerminal().maybeItem().asSet()) {
registries.wireless().registerWirelessHandler((IWirelessTermHandler) wirelessTerminalItem);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/appeng/core/api/definitions/ApiMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public final class ApiMaterials implements IMaterials {
private final IItemDefinition cardInverter;
private final IItemDefinition cardCrafting;
private final IItemDefinition cardOreFilter;
private final IItemDefinition cardPatternRefiller;
private final IItemDefinition enderDust;
private final IItemDefinition flour;
private final IItemDefinition goldDust;
Expand Down Expand Up @@ -170,6 +171,8 @@ public ApiMaterials(final DefinitionConstructor constructor) {
this.cardInverter = new DamagedItemDefinition(itemMultiMaterial.createMaterial(MaterialType.CardInverter));
this.cardCrafting = new DamagedItemDefinition(itemMultiMaterial.createMaterial(MaterialType.CardCrafting));
this.cardOreFilter = new DamagedItemDefinition(itemMultiMaterial.createMaterial(MaterialType.CardOreFilter));
this.cardPatternRefiller = new DamagedItemDefinition(
itemMultiMaterial.createMaterial(MaterialType.CardPatternRefiller));

this.enderDust = new DamagedItemDefinition(itemMultiMaterial.createMaterial(MaterialType.EnderDust));
this.flour = new DamagedItemDefinition(itemMultiMaterial.createMaterial(MaterialType.Flour));
Expand Down Expand Up @@ -515,4 +518,9 @@ public IItemDefinition qESingularity() {
public IItemDefinition blankPattern() {
return this.blankPattern;
}

@Override
public IItemDefinition cardPatternRefiller() {
return this.cardPatternRefiller;
}
}
2 changes: 2 additions & 0 deletions src/main/java/appeng/items/materials/ItemMultiMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public Upgrades getType(final ItemStack itemstack) {
return Upgrades.INVERTER;
case CardCrafting:
return Upgrades.CRAFTING;
case CardPatternRefiller:
return Upgrades.PATTERN_REFILLER;
default:
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/items/materials/MaterialType.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public enum MaterialType {
Cell1024kPart(58, AEFeature.StorageCells),
Cell4096kPart(59, AEFeature.StorageCells),
Cell16384kPart(60, AEFeature.StorageCells),
EmptyAdvancedStorageCell(61, AEFeature.StorageCells);
EmptyAdvancedStorageCell(61, AEFeature.StorageCells),
CardPatternRefiller(62);

private final EnumSet<AEFeature> features;
// IIcon for the material.
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/appeng/parts/reporting/AbstractPartTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;

import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.storage.IMEMonitor;
Expand Down Expand Up @@ -50,6 +51,7 @@ public abstract class AbstractPartTerminal extends AbstractPartDisplay

private final IConfigManager cm = new ConfigManager(this);
private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5);
private final AppEngInternalInventory upgrades = new RefillerInventory(this);

public AbstractPartTerminal(final ItemStack is) {
super(is);
Expand All @@ -69,6 +71,8 @@ public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
drops.add(is);
}
}
ItemStack u = upgrades.getStackInSlot(0);
if (u != null) drops.add(u);
}

@Override
Expand All @@ -81,13 +85,15 @@ public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.cm.readFromNBT(data);
this.viewCell.readFromNBT(data, "viewCell");
upgrades.readFromNBT(data, "upgrades");
}

@Override
public void writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.cm.writeToNBT(data);
this.viewCell.writeToNBT(data, "viewCell");
upgrades.writeToNBT(data, "upgrades");
}

@Override
Expand Down Expand Up @@ -143,4 +149,29 @@ public void onChangeInventory(final IInventory inv, final int slot, final InvOpe
final ItemStack removedStack, final ItemStack newStack) {
this.getHost().markForSave();
}

@Override
public IInventory getInventoryByName(final String name) {
if (name.equals("upgrades")) {
return this.upgrades;
}
return super.getInventoryByName(name);
}

public boolean hasRefillerUpgrade() {
return upgrades.getStackInSlot(0) != null;
}

static class RefillerInventory extends AppEngInternalInventory {

public RefillerInventory(final IAEAppEngInventory parent) {
super(parent, 1, 1);
setTileEntity(parent);
}

public boolean isItemValidForSlot(final int i, final ItemStack itemstack) {
return i == 0 && getStackInSlot(0) == null
&& AEApi.instance().definitions().materials().cardPatternRefiller().isSameAs(itemstack);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/appeng/parts/reporting/PartPatternTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public PartPatternTerminal(final ItemStack is) {

@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
super.getDrops(drops, wrenched);

for (final ItemStack is : this.pattern) {
if (is != null) {
drops.add(is);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public PartPatternTerminalEx(final ItemStack is) {

@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
super.getDrops(drops, wrenched);

for (final ItemStack is : this.pattern) {
if (is != null) {
drops.add(is);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ item.appliedenergistics2.ItemMaterial.CardRedstone.name=Redstone Card
item.appliedenergistics2.ItemMaterial.CardSpeed.name=Acceleration Card
item.appliedenergistics2.ItemMaterial.CardSuperSpeed.name=Hyper-Acceleration Card
item.appliedenergistics2.ItemMaterial.CardOreFilter.name=Oredictionary Filter Card
item.appliedenergistics2.ItemMaterial.CardPatternRefiller.name=Pattern Refiller Card

item.appliedenergistics2.ItemMaterial.Cell2SpatialPart.name=2³ Spatial Component
item.appliedenergistics2.ItemMaterial.Cell16SpatialPart.name=16³ Spatial Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ shaped=
ae2:ItemMaterial.Cell16kPart ae2:BlockInterface _,
_ _ _
-> ae2:ItemMaterial.CardPatternCapacity

shapeless=
ae2:ItemMaterial.BasicCard ae2:ItemPart.ImportBus ae2:ItemMaterial.BlankPattern
-> ae2:ItemMaterial.CardPatternRefiller
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d49fa7a

Please sign in to comment.