Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Fixes #50 #51 #52
Browse files Browse the repository at this point in the history
+ fixes a bug where old recipes were still chosen due to missing buffer update
+ copyright update
+ version increase

Signed-off-by: bartimaeusnek <[email protected]>
  • Loading branch information
bartimaeusnek committed Mar 6, 2020
1 parent 6f1ec50 commit 1256381
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 47 deletions.
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019 bartimaeusnek
# Copyright (c) 2018-2020 bartimaeusnek
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,7 +22,7 @@
mc_version=1.7.10
majorUpdate=0
minorUpdate=5
buildNumber=10
buildNumber=11
APIVersion=8
ic2.version=2.2.828-experimental
gregtech.version=5.09.32.36
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019 bartimaeusnek
* Copyright (c) 2018-2020 bartimaeusnek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,6 +22,7 @@

package com.github.bartimaeusnek.ASM;

import com.github.bartimaeusnek.bartworks.util.NonNullWrappedHashSet;
import com.github.bartimaeusnek.bartworks.util.accessprioritylist.AccessPriorityList;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -96,21 +97,33 @@ public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCraf
}

ItemStack stack = null;
HashSet<IRecipe> recipeHashSet = new HashSet<>();
for (IRecipe recipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList())
if (recipe.matches(inventoryCrafting, world))
recipeHashSet.add(recipe);

for (IRecipe recipe : recipeHashSet){
stack = recipe.getCraftingResult(inventoryCrafting);
if (stack != null && recipeHashSet.size() == 1)
RECENTLYUSEDRECIPES.addLast(recipe);

HashSet<IRecipe> recipeSet = new NonNullWrappedHashSet<>();
List recipeList = CraftingManager.getInstance().getRecipeList();

for (int k = 0; k < recipeList.size(); k++) {
recipeSet.add((IRecipe) recipeList.get(k));
}

Object[] arr = recipeSet.parallelStream().filter(r -> r.matches(inventoryCrafting, world)).toArray();

if (arr.length == 0)
return null;

IRecipe recipe = (IRecipe) arr[0];
stack = recipe.getCraftingResult(inventoryCrafting);

if (arr.length != 1)
return stack;

if (stack != null)
RECENTLYUSEDRECIPES.addLast(recipe);

return stack;
}
}

private BWCoreStaticReplacementMethodes() {
}

}
}
30 changes: 16 additions & 14 deletions src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019 bartimaeusnek
* Copyright (c) 2018-2020 bartimaeusnek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -53,6 +53,7 @@
import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler;
import com.github.bartimaeusnek.bartworks.util.BWRecipes;
import com.github.bartimaeusnek.bartworks.util.BW_Util;
import com.github.bartimaeusnek.bartworks.util.StreamUtils;
import com.github.bartimaeusnek.crossmod.BartWorksCrossmod;
import com.google.common.collect.ArrayListMultimap;
import cpw.mods.fml.common.FMLCommonHandler;
Expand Down Expand Up @@ -230,7 +231,6 @@ public void onModLoadingComplete(FMLLoadCompleteEvent event) {
PlatinumSludgeOverHaul.replacePureElements();

runOnServerStarted();
fixEnergyRequirements();
MainMod.unificationRecipeEnforcer();
}

Expand All @@ -248,25 +248,27 @@ public static void runOnPlayerJoined(boolean classicMode, boolean extraGasRecipe
}
if (classicMode)
new DownTierLoader().run();
// removeDuplicateRecipes();
// removeDuplicateRecipes();
recipesAdded = true;
}

fixEnergyRequirements();

//Accept recipe map changes into Buffers
GT_Recipe.GT_Recipe_Map.sMappings.forEach(GT_Recipe.GT_Recipe_Map::reInit);
}

private static void fixEnergyRequirements() {
maploop:
for (GT_Recipe.GT_Recipe_Map map : GT_Recipe.GT_Recipe_Map.sMappings) {
for (GT_Recipe recipe : map.mRecipeList) {
if (recipe.mFakeRecipe)
continue maploop;
for (int i = 0; i < (VN.length - 1); i++) {
if (recipe.mEUt == BW_Util.getTierVoltage(i)) {
recipe.mEUt = BW_Util.getMachineVoltageFromTier(i);
GT_Recipe.GT_Recipe_Map.sMappings.stream()
.filter(StreamUtils::filterVisualMaps)
.forEach(gt_recipe_map ->
gt_recipe_map.mRecipeList.parallelStream().forEach( gt_recipe -> {
for (int i = 0; i < (VN.length - 1); i++) {
if (gt_recipe.mEUt > BW_Util.getMachineVoltageFromTier(i) && gt_recipe.mEUt <= BW_Util.getTierVoltage(i)) {
gt_recipe.mEUt = BW_Util.getMachineVoltageFromTier(i);
}
}
}
}
}
}));
}

private static void unificationRecipeEnforcer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019 bartimaeusnek
* Copyright (c) 2018-2020 bartimaeusnek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -103,7 +103,7 @@ public void run() {
"CDC",
"SBS",
"CFC",
'C', GT_OreDictUnificator.get(OrePrefixes.circuit, ConfigHandler.GTNH ? Materials.Advanced : Materials.Basic, 1L),
'C', ConfigHandler.GTNH ? "circuitAdvanced" : "circuitBasic",
'D', ItemList.Cover_Screen.get(1L),
'S', GT_OreDictUnificator.get(OrePrefixes.cableGt12, ConfigHandler.GTNH ? Materials.Platinum : Materials.AnnealedCopper, 1L),
'B', new ItemStack(ItemRegistry.BW_BLOCKS[1]),
Expand All @@ -112,24 +112,24 @@ public void run() {

GT_ModHandler.addCraftingRecipe(
new ItemStack(ItemRegistry.DESTRUCTOPACK),
RecipeLoader.BITSD,
GT_ModHandler.RecipeBits.NOT_REMOVABLE,
new Object[]{
"CPC",
"PLP",
"CPC",
'C', GT_OreDictUnificator.get(OrePrefixes.circuit, Materials.Advanced, 1L),
'C', "circuitAdvanced",
'P', GT_OreDictUnificator.get(ConfigHandler.GTNH ? OrePrefixes.plateDouble : OrePrefixes.plate, Materials.Aluminium, 1L),
'L', new ItemStack(Items.lava_bucket)
});

GT_ModHandler.addCraftingRecipe(
new ItemStack(ItemRegistry.DESTRUCTOPACK),
RecipeLoader.BITSD,
GT_ModHandler.RecipeBits.NOT_REMOVABLE,
new Object[]{
"CPC",
"PLP",
"CPC",
'C', GT_OreDictUnificator.get(OrePrefixes.circuit, Materials.Advanced, 1L),
'C', "circuitAdvanced",
'P', GT_OreDictUnificator.get(ConfigHandler.GTNH ? OrePrefixes.plateDouble : OrePrefixes.plate, ConfigHandler.GTNH ? Materials.Steel : Materials.Iron, 1L),
'L', new ItemStack(Items.lava_bucket)
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019 bartimaeusnek
* Copyright (c) 2018-2020 bartimaeusnek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -764,6 +764,7 @@ private WerkstoffLoader() {}
public static final Werkstoff PTResidue = new Werkstoff(
new short[]{0x64,0x63,0x2E},
"Platinum Residue",
"??IrOsRhRu??",
new Werkstoff.Stats(),
Werkstoff.Types.MIXTURE,
new Werkstoff.GenerationFeatures().disable().onlyDust(),
Expand Down Expand Up @@ -899,7 +900,7 @@ private WerkstoffLoader() {}
public static final Werkstoff LeachResidue = new Werkstoff(
new short[]{0x64, 0x46, 0x29},
"Leach Residue",
"??IrOsRhRu??",
"??IrOsRu??",
new Werkstoff.Stats(),
Werkstoff.Types.MIXTURE,
new Werkstoff.GenerationFeatures(),
Expand Down Expand Up @@ -1731,8 +1732,8 @@ private static void runGTItemDataRegistrator() {
}

public static void addAssociationToItems() {
Arrays.stream(values()).forEach( prefixes -> {
Werkstoff.werkstoffHashSet.stream()
Arrays.stream(values()).forEach( prefixes ->
Werkstoff.werkstoffHashSet.stream()
.filter(werkstoff -> werkstoff.hasItemType(prefixes) && (werkstoff.getGenerationFeatures().blacklist & Werkstoff.GenerationFeatures.prefixLogic.get(prefixes)) == 0)
.forEach(werkstoff -> {
Materials werkstoffBridgeMaterial = werkstoff.getBridgeMaterial();
Expand All @@ -1741,8 +1742,7 @@ public static void addAssociationToItems() {
GT_OreDictUnificator.addAssociation(prefixes, werkstoffBridgeMaterial, stack, false);
GT_OreDictUnificator.set(prefixes, werkstoffBridgeMaterial, stack, true, true);
}
});
});
}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019 bartimaeusnek
* Copyright (c) 2018-2020 bartimaeusnek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,6 +23,7 @@
package com.github.bartimaeusnek.bartworks.system.material.processingLoaders;

import com.github.bartimaeusnek.bartworks.util.BW_Util;
import com.github.bartimaeusnek.bartworks.util.StreamUtils;
import gregtech.api.util.GT_Recipe;

import java.util.HashSet;
Expand All @@ -33,13 +34,8 @@ public class DownTierLoader implements Runnable {

@Override
public void run() {
GT_Recipe.GT_Recipe_Map.sMappings.stream().filter(map ->
!(map == GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes
|| map == GT_Recipe.GT_Recipe_Map.sReplicatorFakeRecipes
|| map == GT_Recipe.GT_Recipe_Map.sMassFabFakeRecipes
|| map == GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes
|| map == GT_Recipe.GT_Recipe_Map.sFusionRecipes
|| map == GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes))
GT_Recipe.GT_Recipe_Map.sMappings.stream()
.filter(map -> StreamUtils.filterVisualMaps(map) && map != GT_Recipe.GT_Recipe_Map.sFusionRecipes)
.forEach(map -> {
Set<GT_Recipe> newRecipes = new HashSet<>();
Set<GT_Recipe> toRem = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2018-2020 bartimaeusnek
*
* 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 com.github.bartimaeusnek.bartworks.util;

import java.util.Collection;
import java.util.HashSet;

public class NonNullWrappedHashSet<E> extends HashSet<E> {

public NonNullWrappedHashSet() {
super();
}

public NonNullWrappedHashSet(Collection<? extends E> c) {
super();
this.addAll(c);
}

public NonNullWrappedHashSet(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}

public NonNullWrappedHashSet(int initialCapacity) {
super(initialCapacity);
}

public boolean add(E e) {
if (e != null)
return super.add(e);
return false;
}

public boolean addAll(Collection<? extends E> c) {
boolean wasChanged = false;
for (E element : c) {
if (element != null)
wasChanged |= this.add(element);
}
return wasChanged;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018-2020 bartimaeusnek
*
* 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 com.github.bartimaeusnek.bartworks.util;

import gregtech.api.util.GT_Recipe;

import java.util.Optional;
import java.util.function.Predicate;

public class StreamUtils {
private StreamUtils(){}

public static Predicate<GT_Recipe.GT_Recipe_Map> filterVisualMaps() {
return gt_recipe_map -> {
Optional<GT_Recipe> op = gt_recipe_map.mRecipeList.stream().findAny();
return op.isPresent() && !op.get().mFakeRecipe;
};
}

public static boolean filterVisualMaps(GT_Recipe.GT_Recipe_Map gt_recipe_map) {
return filterVisualMaps().test(gt_recipe_map);
}
}

0 comments on commit 1256381

Please sign in to comment.