Skip to content

Commit 01bffe1

Browse files
Merge branch 'master' into FixPumpCoverNPE
2 parents 34f67b3 + 22a594d commit 01bffe1

35 files changed

+877
-222
lines changed

CHANGELOG.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
11
## Changelog
22

3+
### 1.10.8
4+
* Added Sifter to Smart Item FIlter options (#1345) - LAGIdiot
5+
* Fixed shouldCheckWeakPower not working correctly because of Vanilla MC bug (#1331) - solidDoWant
6+
* Fixed wrong localization key for empty hand (#1327) - Pierre Zhang
7+
* Fixed wrong translation of Rubber nuget in ZH (#1327) - Pierre Zhang
8+
* Fixed Multiblocks voiding partial recipe outputs when output bus is mostly full (#1337) - ALongStringOfNumbers
9+
10+
### 1.10.7 (Hotfix)
11+
* Fixed Brewery and Forming Press recipe finder not working properly - LAGIdiot
12+
* Fixed Fluid Canner and Electric Furnace recipe finder not working properly (#1326) - ALongStringOfNumbers
13+
14+
### 1.10.6
15+
* Added Oredicts to granite variants, marble, basalt (#1306) - ALongStringOfNumbers
16+
* Added Matching Mode to API for possible recipe filtering (#1308) - galyfray
17+
* Added Smart Matching Mode to Smart Item Filter allowing it ignoring fluids in recipes (#1308) - galyfray
18+
* Updated Crafting Station to show only extractable items from connected inventories (#1290) - Frederic Marceau
19+
* Updated zh_cn localization (#1307) - Pierre Zhang
20+
* Updated Ore Byproduct JEI page to include data for Chemical Bath byproducts (#1310) - ALongStringOfNumbers
21+
* Fixed a missing command warning for hand (#1307) - Pierre Zhang
22+
* Fixed Smart Item Filter tooltip on Filter Mode (#1308) - galyfray
23+
* Fixed Ore Byproduct JEI page showing some unobtainable resources (#1310) - ALongStringOfNumbers
24+
* Fixed multiblock fluid tank forming on load not respecting blocked sides (#1313) - PrototypeTrousers
25+
* Fixed multiblock fluid tank incorrectly providing capabilities on load (#1313) - PrototypeTrousers
26+
* Fixed Ice broken by Saw still creating water block (#1317) - Eutro
27+
* Fixed drained Fluid Cells not stacking due to NBT (#1319) - ALongStringOfNumbers
28+
29+
### 1.10.5
30+
* Added LargeStackSizeItemStackHandler to API (#1284) - LAGIdiot
31+
* Added a JEI Info Tab for the Fluid Canner Machines for Buckets and Fluid Cells (#1288) - Frederic Marceau
32+
* Added recipe for turning Block of Quartz (Vanilla MC) to 4 Nether Quartz (Vanilla MC) (#1293) - LAGIdiot
33+
* Updated Granite to be its own material (#1287) - LAGIdiot
34+
* Macerating recipe changed
35+
* Fixed Item Filter not persisting items with size > 127 (#1284) - LAGIdiot
36+
* Fixed recipe validation logging data from builder chance instead of recipe chance (#1297) - galyfray
37+
* Fixed Machine Controller GUI allowing to set too high redstone signal (#1299) - galyfray
38+
* Fixed Machine Controller incorrectly setting working enabled on cover removal (#1299) - galyfray
39+
* Fixed recipes taking 1 tick less to finish then they should (#1301) - LAGIdiot
40+
341
### 1.10.4
442
* Added placing Pump/Conveyor/Robotic Arm on Output side of machine will turn allow input from output side on (#1266) - PrototypeTrousers
543
* Fixed issue preventing battery from fully charged. (#1267) - Derek.CHAN
6-
* Fixes Crafting Station crash and item dupe (#1274) - PrototypeTrousers
44+
* Fixed Crafting Station crash and item dupe (#1274) - PrototypeTrousers
745
* Fixed some RU lang entries (#1279) - Bombm
846

947
### 1.10.3

src/main/java/gregtech/GregTechVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public final class GregTechVersion {
66
//This number is incremented every major feature update
77
public static final int MINOR = 10;
88
//This number is incremented every time the feature is added, or bug is fixed. resets every major version change
9-
public static final int REVISION = 4;
9+
public static final int REVISION = 8;
1010
//This number is incremented every build, and never reset. Should always be 0 in the repo code.
1111
public static final int BUILD = 0;
1212

src/main/java/gregtech/api/block/machines/BlockMachine.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPo
315315

316316
@Override
317317
public boolean shouldCheckWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
318-
return true;
318+
// The check in World::getRedstonePower in the vanilla code base is reversed. Setting this to false will
319+
// actually cause getWeakPower to be called, rather than prevent it.
320+
return false;
319321
}
320322

321323
@Override

src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ protected void updateRecipeProgress() {
131131
boolean drawEnergy = drawEnergy(recipeEUt);
132132
if (drawEnergy || (recipeEUt < 0)) {
133133
metaTileEntity.setSituation(WORKING);
134-
if (++progressTime >= maxProgressTime) {
134+
//as recipe starts with progress on 1 this has to be > only not => to compensate for it
135+
if (++progressTime > maxProgressTime) {
135136
completeRecipe();
136137
}
137138
} else if (recipeEUt > 0) {

src/main/java/gregtech/api/capability/impl/SimpleThermalFluidHandlerItemStack.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,25 @@ public boolean canFillFluidType(FluidStack fluid) {
2626
int liquidTemperature = fluid.getFluid().getTemperature();
2727
return liquidTemperature >= minFluidTemperature && liquidTemperature <= maxFluidTemperature;
2828
}
29+
30+
31+
@Override
32+
public FluidStack drain(FluidStack resource, boolean doDrain) {
33+
FluidStack drained = super.drain(resource, doDrain);
34+
this.removeTagWhenEmpty(doDrain);
35+
return drained;
36+
}
37+
38+
@Override
39+
public FluidStack drain(int maxDrain, boolean doDrain) {
40+
FluidStack drained = super.drain(maxDrain, doDrain);
41+
this.removeTagWhenEmpty(doDrain);
42+
return drained;
43+
}
44+
45+
private void removeTagWhenEmpty(Boolean doDrain) {
46+
if(doDrain && this.getFluid() == null) {
47+
this.container.setTagCompound(null);
48+
}
49+
}
2950
}

src/main/java/gregtech/api/capability/impl/ThermalFluidHandlerItemStack.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,24 @@ public boolean canFillFluidType(FluidStack fluid) {
2626
int liquidTemperature = fluid.getFluid().getTemperature();
2727
return liquidTemperature >= minFluidTemperature && liquidTemperature <= maxFluidTemperature;
2828
}
29+
30+
@Override
31+
public FluidStack drain(FluidStack resource, boolean doDrain) {
32+
FluidStack drained = super.drain(resource, doDrain);
33+
this.removeTagWhenEmpty(doDrain);
34+
return drained;
35+
}
36+
37+
@Override
38+
public FluidStack drain(int maxDrain, boolean doDrain) {
39+
FluidStack drained = super.drain(maxDrain, doDrain);
40+
this.removeTagWhenEmpty(doDrain);
41+
return drained;
42+
}
43+
44+
private void removeTagWhenEmpty(Boolean doDrain) {
45+
if(doDrain && this.getFluid() == null) {
46+
this.container.setTagCompound(null);
47+
}
48+
}
2949
}

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.util.function.Consumer;
5959

6060
import static gregtech.api.situation.Situations.*;
61+
import static gregtech.api.util.InventoryUtils.simulateItemStackMerge;
6162

6263
public abstract class MetaTileEntity implements ICoverable {
6364

@@ -947,13 +948,38 @@ protected void moveInventoryItems(IItemHandler sourceInventory, IItemHandler tar
947948
if (hasItemsToMove && !movedItems) this.failedToMoveItems = true;
948949
}
949950

950-
public static boolean addItemsToItemHandler(IItemHandler handler, boolean simulate, List<ItemStack> items) {
951-
boolean insertedAll = true;
952-
for (ItemStack stack : items) {
953-
insertedAll &= ItemHandlerHelper.insertItemStacked(handler, stack, simulate).isEmpty();
954-
if (!insertedAll && simulate) return false;
955-
}
956-
return insertedAll;
951+
/**
952+
* Simulates the insertion of items into a target inventory, then optionally performs the insertion.
953+
* <br /><br />
954+
* Simulating will not modify any of the input parameters. Insertion will either succeed completely, or fail
955+
* without modifying anything.
956+
*
957+
* @param handler the target inventory
958+
* @param simulate whether to simulate ({@code true}) or actually perform the insertion ({@code false})
959+
* @param items the items to insert into {@code handler}.
960+
* @return {@code true} if the insertion succeeded, {@code false} otherwise.
961+
* @throws IllegalStateException if {@code handler} does not accept all items as expected while performing a
962+
* real insertion. This should not be possible unless the handler is modified in
963+
* another thread, or it does not behave in a manner conforming with the contract
964+
* of {@link gregtech.api.util.InventoryUtils#simulateItemStackMerge simulateItemStackMerge}.
965+
*/
966+
public static boolean addItemsToItemHandler(final IItemHandler handler,
967+
final boolean simulate,
968+
final List<ItemStack> items)
969+
{
970+
// determine if there is sufficient room to insert all items into the target inventory
971+
final boolean canMerge = simulateItemStackMerge(items, handler);
972+
973+
// if we're not simulating and the merge should succeed, perform the merge.
974+
if(!simulate && canMerge)
975+
items.forEach(stack -> {
976+
ItemStack rest = ItemHandlerHelper.insertItemStacked(handler, stack, simulate);
977+
if(!rest.isEmpty())
978+
throw new IllegalStateException(
979+
String.format("Insertion failed, remaining stack contained %d items.", rest.getCount()));
980+
});
981+
982+
return canMerge;
957983
}
958984

959985
public static boolean addFluidsToFluidHandler(IFluidHandler handler, boolean simulate, List<FluidStack> items) {

src/main/java/gregtech/api/pipenet/block/BlockPipe.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPo
140140

141141
@Override
142142
public boolean shouldCheckWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
143-
return true;
143+
// The check in World::getRedstonePower in the vanilla code base is reversed. Setting this to false will
144+
// actually cause getWeakPower to be called, rather than prevent it.
145+
return false;
144146
}
145147

146148
@Override
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package gregtech.api.recipes;
2+
3+
/**
4+
* This enum is used to describe the way {@link Recipe#matches} should determine if the recipe matches the provided input.
5+
* DEFAULT - Both Items and Liquids are checked.
6+
* IGNORE_ITEMS - Items input are ignored, only Liquids input are checked.
7+
* IGNORE_FLUIDS - Liquids input are ignored, only Items input are checked.
8+
*/
9+
public enum MatchingMode {
10+
DEFAULT,
11+
IGNORE_ITEMS,
12+
IGNORE_FLUIDS
13+
}

src/main/java/gregtech/api/recipes/Recipe.java

Lines changed: 96 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraftforge.fluids.FluidStack;
1010
import net.minecraftforge.items.IItemHandlerModifiable;
1111
import org.apache.commons.lang3.Validate;
12+
import org.apache.commons.lang3.tuple.Pair;
1213

1314
import java.util.*;
1415
import java.util.stream.Collectors;
@@ -77,41 +78,83 @@ public Recipe(List<CountableIngredient> inputs, List<ItemStack> outputs, List<Ch
7778
this.inputs.sort(Comparator.comparing(CountableIngredient::getCount).reversed());
7879
}
7980

81+
public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs, MatchingMode matchingMode) {
82+
return matches(consumeIfSuccessful, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs), matchingMode);
83+
}
84+
8085
public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) {
81-
return matches(consumeIfSuccessful, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs));
86+
return matches(consumeIfSuccessful, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs), MatchingMode.DEFAULT);
8287
}
8388

8489
public boolean matches(boolean consumeIfSuccessful, List<ItemStack> inputs, List<FluidStack> fluidInputs) {
85-
int[] fluidAmountInTank = new int[fluidInputs.size()];
86-
int[] itemAmountInSlot = new int[inputs.size()];
90+
return matches(consumeIfSuccessful, inputs, fluidInputs, MatchingMode.DEFAULT);
91+
}
8792

88-
for (int i = 0; i < fluidAmountInTank.length; i++) {
89-
FluidStack fluidInTank = fluidInputs.get(i);
90-
fluidAmountInTank[i] = fluidInTank == null ? 0 : fluidInTank.amount;
93+
/**
94+
* This methods aim to verify if the current recipe matches the given inputs according to matchingMode mode.
95+
*
96+
* @param consumeIfSuccessful if true and matchingMode is equal to {@link MatchingMode#DEFAULT} will consume the inputs of the recipe.
97+
* @param inputs Items input or Collections.emptyList() if none.
98+
* @param fluidInputs Fluids input or Collections.emptyList() if none.
99+
* @param matchingMode How this method should check if inputs matches according to {@link MatchingMode} description.
100+
* @return true if the recipe matches the given inputs false otherwise.
101+
*/
102+
public boolean matches(boolean consumeIfSuccessful, List<ItemStack> inputs, List<FluidStack> fluidInputs, MatchingMode matchingMode) {
103+
Pair<Boolean, Integer[]> fluids = null;
104+
Pair<Boolean, Integer[]> items = null;
105+
106+
if (matchingMode == MatchingMode.IGNORE_FLUIDS) {
107+
if (getInputs().isEmpty()) {
108+
return false;
109+
}
110+
} else {
111+
fluids = matchesFluid(fluidInputs);
112+
if (!fluids.getKey()) {
113+
return false;
114+
}
91115
}
92-
for (int i = 0; i < itemAmountInSlot.length; i++) {
93-
ItemStack itemInSlot = inputs.get(i);
94-
itemAmountInSlot[i] = itemInSlot.isEmpty() ? 0 : itemInSlot.getCount();
116+
117+
if (matchingMode == MatchingMode.IGNORE_ITEMS) {
118+
if (getFluidInputs().isEmpty()) {
119+
return false;
120+
}
121+
} else {
122+
items = matchesItems(inputs);
123+
if (!items.getKey()) {
124+
return false;
125+
}
95126
}
96127

97-
for (FluidStack fluid : this.fluidInputs) {
98-
int fluidAmount = fluid.amount;
99-
boolean isNotConsumed = false;
100-
if (fluidAmount == 0) {
101-
fluidAmount = 1;
102-
isNotConsumed = true;
128+
if (consumeIfSuccessful && matchingMode == MatchingMode.DEFAULT) {
129+
Integer[] fluidAmountInTank = fluids.getValue();
130+
Integer[] itemAmountInSlot = items.getValue();
131+
for (int i = 0; i < fluidAmountInTank.length; i++) {
132+
FluidStack fluidStack = fluidInputs.get(i);
133+
int fluidAmount = fluidAmountInTank[i];
134+
if (fluidStack == null || fluidStack.amount == fluidAmount)
135+
continue;
136+
fluidStack.amount = fluidAmount;
137+
if (fluidStack.amount == 0)
138+
fluidInputs.set(i, null);
103139
}
104-
for (int i = 0; i < fluidInputs.size(); i++) {
105-
FluidStack tankFluid = fluidInputs.get(i);
106-
if (tankFluid == null || !tankFluid.isFluidEqual(fluid))
140+
for (int i = 0; i < itemAmountInSlot.length; i++) {
141+
ItemStack itemInSlot = inputs.get(i);
142+
int itemAmount = itemAmountInSlot[i];
143+
if (itemInSlot.isEmpty() || itemInSlot.getCount() == itemAmount)
107144
continue;
108-
int fluidAmountToConsume = Math.min(fluidAmountInTank[i], fluidAmount);
109-
fluidAmount -= fluidAmountToConsume;
110-
if (!isNotConsumed) fluidAmountInTank[i] -= fluidAmountToConsume;
111-
if (fluidAmount == 0) break;
145+
itemInSlot.setCount(itemAmountInSlot[i]);
112146
}
113-
if (fluidAmount > 0)
114-
return false;
147+
}
148+
149+
return true;
150+
}
151+
152+
private Pair<Boolean, Integer[]> matchesItems(List<ItemStack> inputs) {
153+
Integer[] itemAmountInSlot = new Integer[inputs.size()];
154+
155+
for (int i = 0; i < itemAmountInSlot.length; i++) {
156+
ItemStack itemInSlot = inputs.get(i);
157+
itemAmountInSlot[i] = itemInSlot.isEmpty() ? 0 : itemInSlot.getCount();
115158
}
116159

117160
for (CountableIngredient ingredient : this.inputs) {
@@ -131,29 +174,40 @@ public boolean matches(boolean consumeIfSuccessful, List<ItemStack> inputs, List
131174
if (ingredientAmount == 0) break;
132175
}
133176
if (ingredientAmount > 0)
134-
return false;
177+
return Pair.of(false, itemAmountInSlot);
135178
}
136179

137-
if (consumeIfSuccessful) {
138-
for (int i = 0; i < fluidAmountInTank.length; i++) {
139-
FluidStack fluidStack = fluidInputs.get(i);
140-
int fluidAmount = fluidAmountInTank[i];
141-
if (fluidStack == null || fluidStack.amount == fluidAmount)
142-
continue;
143-
fluidStack.amount = fluidAmount;
144-
if (fluidStack.amount == 0)
145-
fluidInputs.set(i, null);
180+
return Pair.of(true, itemAmountInSlot);
181+
}
182+
183+
private Pair<Boolean, Integer[]> matchesFluid(List<FluidStack> fluidInputs) {
184+
Integer[] fluidAmountInTank = new Integer[fluidInputs.size()];
185+
186+
for (int i = 0; i < fluidAmountInTank.length; i++) {
187+
FluidStack fluidInTank = fluidInputs.get(i);
188+
fluidAmountInTank[i] = fluidInTank == null ? 0 : fluidInTank.amount;
189+
}
190+
191+
for (FluidStack fluid : this.fluidInputs) {
192+
int fluidAmount = fluid.amount;
193+
boolean isNotConsumed = false;
194+
if (fluidAmount == 0) {
195+
fluidAmount = 1;
196+
isNotConsumed = true;
146197
}
147-
for (int i = 0; i < itemAmountInSlot.length; i++) {
148-
ItemStack itemInSlot = inputs.get(i);
149-
int itemAmount = itemAmountInSlot[i];
150-
if (itemInSlot.isEmpty() || itemInSlot.getCount() == itemAmount)
198+
for (int i = 0; i < fluidInputs.size(); i++) {
199+
FluidStack tankFluid = fluidInputs.get(i);
200+
if (tankFluid == null || !tankFluid.isFluidEqual(fluid))
151201
continue;
152-
itemInSlot.setCount(itemAmountInSlot[i]);
202+
int fluidAmountToConsume = Math.min(fluidAmountInTank[i], fluidAmount);
203+
fluidAmount -= fluidAmountToConsume;
204+
if (!isNotConsumed) fluidAmountInTank[i] -= fluidAmountToConsume;
205+
if (fluidAmount == 0) break;
153206
}
207+
if (fluidAmount > 0)
208+
return Pair.of(false, fluidAmountInTank);
154209
}
155-
156-
return true;
210+
return Pair.of(true, fluidAmountInTank);
157211
}
158212

159213
///////////////////
@@ -176,7 +230,7 @@ public List<ItemStack> getResultItemOutputs(int maxOutputSlots, Random random, i
176230
chancedOutputsList = chancedOutputsList.subList(0, Math.max(0, maxChancedSlots));
177231
}
178232
for (ChanceEntry chancedOutput : chancedOutputsList) {
179-
int outputChance = RecipeMap.getChanceFunction().chanceFor(chancedOutput.getChance(),chancedOutput.getBoostPerTier(), tier);
233+
int outputChance = RecipeMap.getChanceFunction().chanceFor(chancedOutput.getChance(), chancedOutput.getBoostPerTier(), tier);
180234
if (random.nextInt(Recipe.getMaxChancedValue()) <= outputChance) {
181235
outputs.add(chancedOutput.getItemStack().copy());
182236
}

0 commit comments

Comments
 (0)