Added an option to toggle oredict substitutions for patterns. #1891

Merged
merged 1 commit into from Oct 10, 2015

Projects

None yet

3 participants

@yueh
Member
yueh commented Sep 21, 2015

It adds a backward compatibility to convert current patterns to use
oredict by default, which should be removed with rv4 stable.

Closes #1156

@yueh yueh changed the title from Added an option to toggle oredict subsitutions for patterns. to Added an option to toggle oredict substitutions for patterns. Sep 21, 2015
@orod-org orod-org commented on the diff Sep 21, 2015
.../java/appeng/core/sync/packets/PacketValueConfig.java
@@ -158,6 +158,10 @@ else if( this.Name.equals( "PatternTerminal.Clear" ) )
{
cpt.clear();
}
+ else if( this.Name.equals( "PatternTerminal.Substitute" ) )
@orod-org
orod-org Sep 21, 2015

MAJOR Move the "PatternTerminal.Substitute" string literal on the left side of this string comparison. rule

@orod-org orod-org commented on the diff Sep 21, 2015
.../java/appeng/core/sync/packets/PacketValueConfig.java
@@ -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" ) );
@orod-org
orod-org Sep 21, 2015

MAJOR Move the "1" string literal on the left side of this string comparison. rule

@orod-org orod-org commented on the diff Sep 21, 2015
src/main/java/appeng/crafting/CraftingTreeNode.java
@@ -50,14 +53,13 @@
private final IAEItemStack what;
// what are the crafting patterns for this?
private final ArrayList<CraftingTreeProcess> nodes = new ArrayList<CraftingTreeProcess>();
- int bytes = 0;
- boolean canEmit = false;
- boolean cannotUse = false;
- long missing = 0;
- long howManyEmitted = 0;
- boolean exhausted = false;
-
- boolean sim;
+ private int bytes = 0;
+ private boolean canEmit = false;
+ private boolean cannotUse = false;
@orod-org
orod-org Sep 21, 2015

MAJOR Remove this unused "cannotUse" private field. rule

@orod-org orod-org commented on the diff Sep 21, 2015
...ain/java/appeng/core/localization/ButtonToolTips.java
@@ -54,7 +54,7 @@
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,
@orod-org
orod-org Sep 21, 2015

MINOR Rename this constant name to match the regular expression '^[A-Z][A-Z0-9]([A-Z0-9]+)_$'. rule

@orod-org orod-org commented on the diff Sep 21, 2015
src/main/java/appeng/core/localization/GuiText.java
@@ -47,9 +47,20 @@
// 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,
@orod-org
orod-org Sep 21, 2015

MINOR Rename this constant name to match the regular expression '^[A-Z][A-Z0-9]([A-Z0-9]+)_$'. rule

@orod-org orod-org commented on the diff Sep 21, 2015
src/main/java/appeng/core/localization/GuiText.java
@@ -47,9 +47,20 @@
// 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,
@orod-org
orod-org Sep 21, 2015

MINOR Rename this constant name to match the regular expression '^[A-Z][A-Z0-9]([A-Z0-9]+)_$'. rule

@orod-org orod-org commented on the diff Sep 21, 2015
src/main/java/appeng/core/localization/GuiText.java
-
- ProcessingPattern, Crafts, Creates, And, With, MolecularAssembler,
+ StoredSize, CopyMode, CopyModeDesc, PatternTerminal,
+
+ // Pattern tooltips
+ CraftingPattern,
+ ProcessingPattern,
+ Crafts,
+ Creates,
+ And,
+ With,
+ Substitute,
+ Yes,
+ No,
+
+ MolecularAssembler,
@orod-org
orod-org Sep 21, 2015

MINOR Rename this constant name to match the regular expression '^[A-Z][A-Z0-9]([A-Z0-9]+)_$'. rule

@yueh yueh added this to the rv3 - 1.7.10 milestone Sep 22, 2015
@yueh
Member
yueh commented Sep 23, 2015

I am also not fully convinced about how to handle the backward compatibility.
Should we consider any "old" pattern as oredict enabled or not. According to the existing code in PatternHelper.canSubstitute(), they were actually not intended to use any substitute.

@thatsIch
Member

I think oredict should be off by default.

@yueh
Member
yueh commented Sep 23, 2015

I also tend to this option, but will potentially cause more issues to players when upgrading and their tendency to ignore changelogs.

@thatsIch
Member

ah, the old pattern did support oredict right,
then 1.7 on by default with a //TODO marker?

@yueh
Member
yueh commented Sep 23, 2015

Old patterns are supporting oredict as it was the only option. But codewise it seems they should not.

New patterns will now have a new nbttag, but nonexistant nbttags will by default fallback to false, so it currently checks if the tag exists and if not will fallback to true instead.
It would be possible to simply negate it at one point, but this is really clunky, if the code works with "can", but stored as "cannot".

Also there is already a TODO for the pattern helper to remove it at one point.
If completely new patterns then use oredict or not by default is not really important. I honestly have currently even no idea what the default option is.

@thatsIch
Member

I think new patterns should have ore dict off per default.
You could also add a transition item with a text like "put into bench to convert to new" or so like the old TE pipes in 1.6

Might be the cleanest solution from player perspective

@yueh
Member
yueh commented Sep 23, 2015

A transition item would be extremely intrusive to existing builds as this would mean update every single pattern.

Disabling it would mean only recreate needed ones, but still will require some player interaction.

Enabling will keep the current behaviour, but need like 5 lines of code extra to handle it.

@yueh
Member
yueh commented Sep 26, 2015

I slowly tend towards disabling it even for old patterns. The crafting system is already designed around precise items when calculating the crafting tree and most requests are about disabling this feature in general.

I really cannot remember any real feedback regarding it is an actually used very frequently, But the positive feedback is way more rare then negative ones.
Also the amount of patterns requiring oredict enable is probably way less then these requiring it disabled, so I would assume it will be less work for the players actually and I have no issue about closing a couple of issues and linking the changelogs.

@thatsIch
Member

sounds about right

@thatsIch thatsIch commented on an outdated diff Oct 6, 2015
src/api/java/appeng/api/config/Substitution.java
+ *
+ * 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 Substitution
@thatsIch
thatsIch Oct 6, 2015 Member

should probably state for what usage this is supposed to be used. Sometimes there are duplicate classes which do nearly the same but are used in different contextes and to obtain type-safety they use different ones.

@thatsIch thatsIch and 1 other commented on an outdated diff Oct 6, 2015
...appeng/client/gui/implementations/GuiPatternTerm.java
@@ -78,34 +80,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 ? "0" : "1" ) );
@thatsIch
thatsIch Oct 6, 2015 Member

should probably const the 0 and the 1 out to clarify meaning

@yueh
yueh Oct 6, 2015 Member

Might be even an idea to refactor PacketValueConfig to also accept an enum instead of just a random string. Serialization probably still has to fall back to .ordinal() or similar.

@thatsIch thatsIch commented on the diff Oct 6, 2015
...appeng/client/gui/implementations/GuiPatternTerm.java
@@ -122,6 +133,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;
+ }
+
@thatsIch
thatsIch Oct 6, 2015 Member

just thinking as enhancement:

A class ToggleGroup or so, and if you make 1 button visible, all others are disabled via listener. Would be probably interessting in other button groups, so adding a new state is far easier than hard-coding the state.

@yueh
yueh Oct 6, 2015 Member

Good idea. The whole gui could see some improvments. But simply not enough time currently to also refactor this.

@thatsIch thatsIch and 1 other commented on an outdated diff Oct 6, 2015
...g/container/implementations/ContainerPatternTerm.java
@@ -450,6 +459,11 @@ public void detectAndSendChanges()
this.craftingMode = this.ct.isCraftingRecipe();
this.updateOrderOfOutputSlots();
}
+
+ if( this.substitute != this.ct.isSubstitution() )
+ {
+ this.substitute = this.ct.isSubstitution();
+ }
@thatsIch
thatsIch Oct 6, 2015 Member

so its always this.substitute = this.ct.isSubstitution();? any performance implications why the ifis used?

@yueh
yueh Oct 6, 2015 Member

Hm yeah. Mostly pointless. I think I left it intentionally there in case it needed something similar to the crafting mode and updateOrderOfOutputSlots().

@thatsIch thatsIch commented on an outdated diff Oct 6, 2015
src/main/java/appeng/crafting/CraftingTreeNode.java
@@ -121,12 +126,30 @@ public IAEItemStack request( final MECraftingInventory inv, long l, final BaseAc
this.what.setStackSize( l );
if( this.slot >= 0 && this.parent != null && this.parent.details.isCraftable() )
{
- for( IAEItemStack fuzz : inv.getItemList().findFuzzy( this.what, FuzzyMode.IGNORE_ALL ) )
+ final Collection<IAEItemStack> itemList;
+
+ if( this.parent.details.canSubstitute() )
+ {
+ itemList = inv.getItemList().findFuzzy( this.what, FuzzyMode.IGNORE_ALL );
@thatsIch
thatsIch Oct 6, 2015 Member

inv.getItemList() used in both branches

@thatsIch thatsIch commented on an outdated diff Oct 6, 2015
src/main/java/appeng/helpers/PatternHelper.java
{
ACCEPT, DECLINE, TEST
}
- static class TestLookup
+ private static class TestLookup
@yueh yueh Added an option to toggle oredict subsitutions for patterns.
It adds a backward compatibility to convert current patterns to use
oredict by default, which should be removed with rv4 stable.

Closes #1156
24224a4
@orod-org
orod-org commented Oct 6, 2015

SonarQube analysis reported 9 issues:

  • MAJOR 4 major
  • MINOR 5 minor

Watch the comments in this conversation to review them.
Note: the following issues could not be reported as comments because they are located on lines that are not displayed in this pull request:

@thatsIch thatsIch commented on the diff Oct 8, 2015
.../java/appeng/core/sync/packets/PacketValueConfig.java
@@ -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;
@thatsIch
thatsIch Oct 8, 2015 Member

vars should start lower case and not like classes

@yueh
yueh Oct 8, 2015 Member

I know.. There are a bunch of them. Probably something I will tackle should the PR for private fields be merged. Also the whole PacketValueConfig is a bit cheesy. Something I want to address with the network refactoring.

@thatsIch
Member
thatsIch commented Oct 8, 2015

Looks fine, I will live test it tomorrow

@thatsIch thatsIch self-assigned this Oct 8, 2015
@thatsIch
Member

A nice thing would be if you could see a difference in oredict vs not. This can be another FR though

@thatsIch
Member

Upon crafting my client crashes

@thatsIch
Member

Tried several times already, still failing

@thatsIch
Member

This still crashes without NEI and CC

@thatsIch
Member

Another thing is the place of the substitution button, not sure if this should be there, but maybe below the crafting/processing switch?

@yueh
Member
yueh commented Oct 10, 2015

The button was already there. Just hidden, so I simply kept it.

Different icon? As the tooltip already shows if enabled or not and this is also visible inside an interface terminal.

Regarding the crash see: https://bugs.mojang.com/browse/MC-32606

@thatsIch
Member
@thatsIch
Member

Using the super latest driver fixes this issue or force not to use your 2D desktop application GFX-card

@thatsIch
Member

I mean a direct indicator like upon shift show an iron ingot in the corner to indicate that these are oredictionaried.

@yueh
Member
yueh commented Oct 10, 2015

Hm. There is just the general issue with only 16x16 pixel large icons.

But probably another FR. Also not sure if still possible with 1.8/1.9. I do not really want to add something, if we already know it needs to be reverted later.

@yueh yueh merged commit 5643519 into AppliedEnergistics:master Oct 10, 2015

3 checks passed

default Finished TeamCity Build Applied Energistics :: Pull Requests : Tests passed: 53
Details
jenkins Success 53 tests run, 0 skipped, 0 failed.
Details
sonarqube SonarQube reported 9 issues, no critical nor blocker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment