Skip to content

Commit

Permalink
Added an option to toggle oredict subsitutions for patterns.
Browse files Browse the repository at this point in the history
It adds a backward compatibility to convert current patterns to use
oredict by default, which should be removed with rv4 stable.

Closes #1156
  • Loading branch information
yueh committed Oct 6, 2015
1 parent c14bc82 commit 70d28f3
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 86 deletions.
30 changes: 30 additions & 0 deletions src/api/java/appeng/api/config/ItemSubstitution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 AlgorithmX2
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package appeng.api.config;


public enum ItemSubstitution
{
ENABLED, DISABLED;
}
66 changes: 47 additions & 19 deletions src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.api.config.ItemSubstitution;
import appeng.api.storage.ITerminalHost;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton;
Expand All @@ -41,13 +42,20 @@
public class GuiPatternTerm extends GuiMEMonitorable
{

final ContainerPatternTerm container;
private final static String SUBSITUTION_DISABLE = "0";
private final static String SUBSITUTION_ENABLE = "1";

GuiTabButton tabCraftButton;
GuiTabButton tabProcessButton;
// GuiImgButton substitutionsBtn;
GuiImgButton encodeBtn;
GuiImgButton clearBtn;
private final static String CRAFTMODE_CRFTING = "1";
private final static String CRAFTMODE_PROCESSING = "0";

private final ContainerPatternTerm container;

private GuiTabButton tabCraftButton;
private GuiTabButton tabProcessButton;
private GuiImgButton substitutionsEnabledBtn;
private GuiImgButton substitutionsDisabledBtn;
private GuiImgButton encodeBtn;
private GuiImgButton clearBtn;

public GuiPatternTerm( final InventoryPlayer inventoryPlayer, final ITerminalHost te )
{
Expand All @@ -66,7 +74,7 @@ protected void actionPerformed( final GuiButton btn )

if( this.tabCraftButton == btn || this.tabProcessButton == btn )
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.CraftMode", this.tabProcessButton == btn ? "1" : "0" ) );
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.CraftMode", this.tabProcessButton == btn ? CRAFTMODE_CRFTING : CRAFTMODE_PROCESSING ) );
}

if( this.encodeBtn == btn )
Expand All @@ -78,34 +86,43 @@ protected void actionPerformed( final GuiButton btn )
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.Clear", "1" ) );
}

if( this.substitutionsEnabledBtn == btn || this.substitutionsDisabledBtn == btn )
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.Substitute", this.substitutionsEnabledBtn == btn ? SUBSITUTION_DISABLE : SUBSITUTION_ENABLE ) );
}
}
catch( final IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}

// if ( substitutionsBtn == btn )
// {

// }
}

@Override
public void initGui()
{
super.initGui();
this.buttonList.add( this.tabCraftButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 177, new ItemStack( Blocks.crafting_table ), GuiText.CraftingPattern.getLocal(), itemRender ) );
this.buttonList.add( this.tabProcessButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 177, new ItemStack( Blocks.furnace ), GuiText.ProcessingPattern.getLocal(), itemRender ) );
this.tabCraftButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 177, new ItemStack( Blocks.crafting_table ), GuiText.CraftingPattern.getLocal(), itemRender );
this.buttonList.add( this.tabCraftButton );

this.tabProcessButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 177, new ItemStack( Blocks.furnace ), GuiText.ProcessingPattern.getLocal(), itemRender );
this.buttonList.add( this.tabProcessButton );

// buttonList.add( substitutionsBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163,
// Settings.ACTIONS, ActionItems.SUBSTITUTION ) );
// substitutionsBtn.halfSize = true;
this.substitutionsEnabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.ENABLED );
this.substitutionsEnabledBtn.halfSize = true;
this.buttonList.add( this.substitutionsEnabledBtn );

this.buttonList.add( this.clearBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE ) );
this.substitutionsDisabledBtn = new GuiImgButton( this.guiLeft + 84, this.guiTop + this.ySize - 163, Settings.ACTIONS, ItemSubstitution.DISABLED );
this.substitutionsDisabledBtn.halfSize = true;
this.buttonList.add( this.substitutionsDisabledBtn );

this.clearBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.CLOSE );
this.clearBtn.halfSize = true;
this.buttonList.add( this.clearBtn );

this.buttonList.add( this.encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 142, Settings.ACTIONS, ActionItems.ENCODE ) );
this.encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 142, Settings.ACTIONS, ActionItems.ENCODE );
this.buttonList.add( this.encodeBtn );
}

@Override
Expand All @@ -122,6 +139,17 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
this.tabProcessButton.visible = false;
}

if( this.container.substitute )
{
this.substitutionsEnabledBtn.visible = true;
this.substitutionsDisabledBtn.visible = false;
}
else
{
this.substitutionsEnabledBtn.visible = false;
this.substitutionsDisabledBtn.visible = true;
}

super.drawFG( offsetX, offsetY, mouseX, mouseY );
this.fontRendererObj.drawString( GuiText.PatternTerminal.getLocal(), 8, this.ySize - 96 + 2 - this.reservedSpace, 4210752 );
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/appeng/client/gui/widgets/GuiImgButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.StorageFilter;
import appeng.api.config.ItemSubstitution;
import appeng.api.config.TerminalStyle;
import appeng.api.config.ViewItems;
import appeng.api.config.YesNo;
Expand Down Expand Up @@ -129,7 +130,8 @@ public GuiImgButton( final int x, final int y, final Enum idx, final Enum val )
this.registerApp( 6, Settings.ACTIONS, ActionItems.STASH, ButtonToolTips.Stash, ButtonToolTips.StashDesc );

this.registerApp( 8, Settings.ACTIONS, ActionItems.ENCODE, ButtonToolTips.Encode, ButtonToolTips.EncodeDescription );
this.registerApp( 4 + 3 * 16, Settings.ACTIONS, ActionItems.SUBSTITUTION, ButtonToolTips.Substitutions, ButtonToolTips.SubstitutionsDesc );
this.registerApp( 4 + 3 * 16, Settings.ACTIONS, ItemSubstitution.ENABLED, ButtonToolTips.Substitutions, ButtonToolTips.SubstitutionsDescEnabled );
this.registerApp( 7 + 3 * 16, Settings.ACTIONS, ItemSubstitution.DISABLED, ButtonToolTips.Substitutions, ButtonToolTips.SubstitutionsDescDisabled );

this.registerApp( 16, Settings.VIEW_MODE, ViewItems.STORED, ButtonToolTips.View, ButtonToolTips.StoredItems );
this.registerApp( 18, Settings.VIEW_MODE, ViewItems.ALL, ButtonToolTips.View, ButtonToolTips.StoredCraftable );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
{

public final PartPatternTerminal ct;
final AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 );
final IInventory crafting;
final SlotFakeCraftingMatrix[] craftingSlots = new SlotFakeCraftingMatrix[9];
final OptionalSlotFake[] outputSlots = new OptionalSlotFake[3];
final SlotPatternTerm craftSlot;
final SlotRestrictedInput patternSlotIN;
final SlotRestrictedInput patternSlotOUT;
private final AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 );
private final IInventory crafting;
private final SlotFakeCraftingMatrix[] craftingSlots = new SlotFakeCraftingMatrix[9];
private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[3];
private final SlotPatternTerm craftSlot;
private final SlotRestrictedInput patternSlotIN;
private final SlotRestrictedInput patternSlotOUT;
@GuiSync( 97 )
public boolean craftingMode = true;
@GuiSync( 96 )
public boolean substitute = false;

public ContainerPatternTerm( final InventoryPlayer ip, final ITerminalHost monitorable )
{
Expand All @@ -88,6 +90,7 @@ public ContainerPatternTerm( final InventoryPlayer ip, final ITerminalHost monit

final IInventory patternInv = this.ct.getInventoryByName( "pattern" );
final IInventory output = this.ct.getInventoryByName( "output" );

this.crafting = this.ct.getInventoryByName( "crafting" );

for( int y = 0; y < 3; y++ )
Expand Down Expand Up @@ -156,6 +159,7 @@ public void putStacksInSlots( final ItemStack[] par1ArrayOfItemStack )
public ItemStack getAndUpdateOutput()
{
final InventoryCrafting ic = new InventoryCrafting( this, 3, 3 );

for( int x = 0; x < ic.getSizeInventory(); x++ )
{
ic.setInventorySlotContents( x, this.crafting.getStackInSlot( x ) );
Expand Down Expand Up @@ -238,6 +242,7 @@ else if( output == null )
encodedValue.setTag( "in", tagIn );
encodedValue.setTag( "out", tagOut );
encodedValue.setBoolean( "crafting", this.craftingMode );
encodedValue.setBoolean( "substitute", this.substitute );

output.setTagCompound( encodedValue );
}
Expand Down Expand Up @@ -269,6 +274,7 @@ private ItemStack[] getOutputs()
if( this.craftingMode )
{
final ItemStack out = this.getAndUpdateOutput();

if( out != null && out.stackSize > 0 )
{
return new ItemStack[] { out };
Expand All @@ -282,6 +288,7 @@ private ItemStack[] getOutputs()
for( final OptionalSlotFake outputSlot : this.outputSlots )
{
final ItemStack out = outputSlot.getStack();

if( out != null && out.stackSize > 0 )
{
list.add( out );
Expand Down Expand Up @@ -347,9 +354,9 @@ public void craftOrGetItem( final PacketPatternSlot packetPatternSlot )
if( packetPatternSlot.slotItem != null && this.cellInv != null )
{
final IAEItemStack out = packetPatternSlot.slotItem.copy();

InventoryAdaptor inv = new AdaptorPlayerHand( this.getPlayerInv().player );
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( this.getPlayerInv().player, ForgeDirection.UNKNOWN );

if( packetPatternSlot.shift )
{
inv = playerInv;
Expand All @@ -376,6 +383,7 @@ public void craftOrGetItem( final PacketPatternSlot packetPatternSlot )

final InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
final InventoryCrafting real = new InventoryCrafting( new ContainerNull(), 3, 3 );

for( int x = 0; x < 9; x++ )
{
ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? null : packetPatternSlot.pattern[x].getItemStack() );
Expand Down Expand Up @@ -412,6 +420,7 @@ public void craftOrGetItem( final PacketPatternSlot packetPatternSlot )
for( int x = 0; x < real.getSizeInventory(); x++ )
{
final ItemStack failed = playerInv.addItems( real.getStackInSlot( x ) );

if( failed != null )
{
p.dropPlayerItemWithRandomChoice( failed, false );
Expand Down Expand Up @@ -450,6 +459,8 @@ public void detectAndSendChanges()
this.craftingMode = this.ct.isCraftingRecipe();
this.updateOrderOfOutputSlots();
}

this.substitute = this.ct.isSubstitution();
}
}

Expand Down Expand Up @@ -519,4 +530,12 @@ public boolean useRealItems()
{
return false;
}

public void toggleSubstitute()
{
this.substitute = !this.substitute;

this.detectAndSendChanges();
this.getAndUpdateOutput();
}
}
2 changes: 1 addition & 1 deletion src/main/java/appeng/core/localization/ButtonToolTips.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public enum ButtonToolTips

LevelType, LevelType_Energy, LevelType_Item, InventoryTweaks, TerminalStyle, TerminalStyle_Full, TerminalStyle_Tall, TerminalStyle_Small,

Stash, StashDesc, Encode, EncodeDescription, Substitutions, SubstitutionsOn, SubstitutionsOff, SubstitutionsDesc, CraftOnly, CraftEither,
Stash, StashDesc, Encode, EncodeDescription, Substitutions, SubstitutionsOn, SubstitutionsOff, SubstitutionsDescEnabled, SubstitutionsDescDisabled, CraftOnly, CraftEither,

Craft, Mod, DoesntDespawn, EmitterMode, CraftViaRedstone, EmitWhenCrafting, ReportInaccessibleItems, ReportInaccessibleItemsYes, ReportInaccessibleItemsNo,

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/appeng/core/localization/GuiText.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,20 @@ public enum GuiText
// tunnel names
METunnel, ItemTunnel, RedstoneTunnel, EUTunnel, FluidTunnel, OCTunnel, LightTunnel, RFTunnel, PressureTunnel,

StoredSize, CopyMode, CopyModeDesc, PatternTerminal, CraftingPattern,

ProcessingPattern, Crafts, Creates, And, With, MolecularAssembler,
StoredSize, CopyMode, CopyModeDesc, PatternTerminal,

// Pattern tooltips
CraftingPattern,
ProcessingPattern,
Crafts,
Creates,
And,
With,
Substitute,
Yes,
No,

MolecularAssembler,

StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting,

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/appeng/core/sync/packets/PacketValueConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
public class PacketValueConfig extends AppEngPacket
{

public final String Name;
public final String Value;
private final String Name;
private final String Value;

// automatic.
public PacketValueConfig( final ByteBuf stream ) throws IOException
Expand Down Expand Up @@ -158,6 +158,10 @@ else if( this.Name.equals( "PatternTerminal.Clear" ) )
{
cpt.clear();
}
else if( this.Name.equals( "PatternTerminal.Substitute" ) )
{
cpt.ct.setSubstitution( this.Value.equals( "1" ) );
}
}
else if( this.Name.startsWith( "StorageBus." ) && c instanceof ContainerStorageBus )
{
Expand Down
Loading

0 comments on commit 70d28f3

Please sign in to comment.