Skip to content

Commit 5d5882c

Browse files
committed
Debug code clean; Fix a strange invalid item output issue; selective-update-tileentity now is enabled by default.
1 parent 1942452 commit 5d5882c

File tree

6 files changed

+104
-92
lines changed

6 files changed

+104
-92
lines changed

src/main/java/hellfirepvp/modularmachinery/client/gui/GuiFactoryController.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import hellfirepvp.modularmachinery.common.machine.DynamicMachine;
1212
import hellfirepvp.modularmachinery.common.machine.factory.RecipeThread;
1313
import hellfirepvp.modularmachinery.common.tiles.TileFactoryController;
14-
import io.netty.util.internal.ThrowableUtil;
1514
import net.minecraft.client.gui.FontRenderer;
1615
import net.minecraft.client.gui.Gui;
1716
import net.minecraft.client.renderer.GlStateManager;
@@ -51,12 +50,8 @@ public GuiFactoryController(TileFactoryController factory, EntityPlayer player)
5150

5251
@Override
5352
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
54-
try {
55-
drawRecipeQueue();
56-
drawFactoryStatus();
57-
} catch (Exception e) {
58-
ModularMachinery.log.warn(ThrowableUtil.stackTraceToString(e));
59-
}
53+
drawRecipeQueue();
54+
drawFactoryStatus();
6055
}
6156

6257
@Override
@@ -96,17 +91,17 @@ private void drawRecipeInfo(RecipeThread thread, int id, int offsetY) {
9691

9792
// Daemon Thread Color
9893
if (thread.isDaemon()) {
99-
GlStateManager.color(0.8F, 0.8F, 1.0F, 1.0F);
94+
GlStateManager.color(0.5F, 0.8F, 1.0F, 1.0F);
10095
} else {
10196
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
10297
}
10398
drawTexturedModalRect(RECIPE_QUEUE_OFFSET_X, offsetY, 0, 0, FACTORY_ELEMENT_WIDTH, FACTORY_ELEMENT_HEIGHT);
10499

105100
// Thread Status Color
106101
if (status.isCrafting()) {
107-
GlStateManager.color(0.5F, 1.0F, 0.75F, 1.0F);
102+
GlStateManager.color(0.6F, 1.0F, 0.75F, 1.0F);
108103
} else {
109-
GlStateManager.color(1.0F, 0.6F, 0.6F, 1.0F);
104+
GlStateManager.color(1.0F, 0.45F, 0.45F, 1.0F);
110105
}
111106

112107
if (activeRecipe != null) {

src/main/java/hellfirepvp/modularmachinery/common/crafting/requirement/RequirementItem.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import javax.annotation.Nonnull;
3333
import java.util.ArrayList;
3434
import java.util.List;
35-
import java.util.Objects;
3635

3736
/**
3837
* This class is part of the Modular Machinery Mod
@@ -251,15 +250,15 @@ public CraftCheck canStartCrafting(ProcessingComponent<?> component, RecipeCraft
251250
}
252251
return CraftCheck.failure("craftcheck.failure.item.input");
253252
} else if (actionType == IOType.OUTPUT) {
254-
for (ComponentOutputRestrictor restrictor : restrictions) {
255-
if (restrictor instanceof ComponentOutputRestrictor.RestrictionInventory) {
256-
ComponentOutputRestrictor.RestrictionInventory inv = (ComponentOutputRestrictor.RestrictionInventory) restrictor;
257-
258-
if (inv.exactComponent.equals(component)) {
259-
ItemUtils.tryPlaceItemInInventory(inv.inserted.copy(), handler, true);
260-
}
261-
}
262-
}
253+
// for (ComponentOutputRestrictor restrictor : restrictions) {
254+
// if (restrictor instanceof ComponentOutputRestrictor.RestrictionInventory) {
255+
// ComponentOutputRestrictor.RestrictionInventory inv = (ComponentOutputRestrictor.RestrictionInventory) restrictor;
256+
//
257+
// if (inv.exactComponent.equals(component)) {
258+
// ItemUtils.tryPlaceItemInInventory(inv.inserted.copy(), handler, false);
259+
// }
260+
// }
261+
// }
263262

264263
ItemStack stack = ItemStack.EMPTY;
265264
if (oreDictName != null) {
@@ -352,7 +351,7 @@ public CraftCheck finishCrafting(ProcessingComponent<?> component, RecipeCraftin
352351
throw new IllegalStateException("Invalid item output!");
353352
}
354353
IOInventory handler = (IOInventory) component.providedComponent;
355-
if (Objects.requireNonNull(actionType) == IOType.OUTPUT) {
354+
if (actionType == IOType.OUTPUT) {
356355
ItemStack stack;
357356
if (oreDictName != null) {
358357
stack = Iterables.getFirst(OreDictionary.getOres(oreDictName), ItemStack.EMPTY);

src/main/java/hellfirepvp/modularmachinery/common/data/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Config {
3333
public static boolean mocCompatibleMode = false;
3434
public static boolean onlyOneMachineController = false;
3535
public static boolean disableMocDeprecatedTip = false;
36-
public static boolean selectiveUpdateTileEntity = false;
36+
public static boolean selectiveUpdateTileEntity = true;
3737
public static boolean machineParallelizeEnabledByDefault = true;
3838
public static boolean recipeParallelizeEnabledByDefault = true;
3939
public static boolean enableFluxNetworksIntegration = true;
@@ -91,7 +91,7 @@ private static void load() {
9191
"Disable the ModularController is deprecated tooltip.");
9292

9393
// Network
94-
selectiveUpdateTileEntity = lastReadConfig.getBoolean("selective-update-tileentity", "general", false,
94+
selectiveUpdateTileEntity = lastReadConfig.getBoolean("selective-update-tileentity", "general", true,
9595
"Provide selective updates for certain tile entities that tend to consume a lot of bandwidth to relieve network pressure.");
9696

9797
// FluxNetworks Integration

src/main/java/hellfirepvp/modularmachinery/common/machine/factory/RecipeThread.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public CraftingStatus onTick() {
7676
return new CraftingStatus(TileMultiblockMachineController.Type.NO_RECIPE, "");
7777
}
7878
if (context == null) {
79-
context = factory.createContext(activeRecipe);
79+
context = createContext(activeRecipe);
8080
}
8181

8282
return (status = activeRecipe.tick(factory, context));
@@ -88,7 +88,7 @@ public void onFinished() {
8888
return;
8989
}
9090
if (context == null) {
91-
context = factory.createContext(activeRecipe);
91+
context = createContext(activeRecipe);
9292
}
9393

9494
RecipeCraftingContext.CraftingCheckResult checkResult = context.canFinishCrafting();
@@ -105,7 +105,7 @@ public void onFinished() {
105105

106106
activeRecipe.reset();
107107
activeRecipe.setMaxParallelism(factory.getAvailableParallelism());
108-
context = factory.createContext(activeRecipe);
108+
context = createContext(activeRecipe);
109109

110110
RecipeCraftingContext.CraftingCheckResult result = factory.onCheck(context);
111111
if (result.isSuccess()) {
@@ -114,9 +114,19 @@ public void onFinished() {
114114
activeRecipe = null;
115115
context = null;
116116
status = CraftingStatus.IDLE;
117+
if (isDaemon) {
118+
createRecipeSearchTask();
119+
}
117120
}
118121
}
119122

123+
public RecipeCraftingContext createContext(ActiveMachineRecipe activeRecipe) {
124+
RecipeCraftingContext context = factory.createContext(activeRecipe);
125+
context.addModifier(semiPermanentModifiers.values());
126+
context.addModifier(permanentModifiers.values());
127+
return context;
128+
}
129+
120130
public void searchAndStartRecipe() {
121131
if (searchTask != null) {
122132
if (!searchTask.isDone()) {
@@ -143,20 +153,24 @@ public void searchAndStartRecipe() {
143153
}
144154
} else {
145155
if (factory.getTicksExisted() % RECIPE_SEARCH_DELAY == 0) {
146-
TileFactoryController factory = this.factory;
147-
Iterable<MachineRecipe> recipeSet = this.recipeSet.isEmpty() ? RecipeRegistry.getRecipesFor(factory.getFoundMachine()) : this.recipeSet;
148-
searchTask = new FactoryRecipeSearchTask(
149-
factory,
150-
factory.getFoundMachine(),
151-
factory.getAvailableParallelism(),
152-
recipeSet,
153-
this,
154-
factory.getActiveRecipeList());
155-
TaskExecutor.FORK_JOIN_POOL.submit(searchTask);
156+
createRecipeSearchTask();
156157
}
157158
}
158159
}
159160

161+
private void createRecipeSearchTask() {
162+
TileFactoryController factory = this.factory;
163+
Iterable<MachineRecipe> recipeSet = this.recipeSet.isEmpty() ? RecipeRegistry.getRecipesFor(factory.getFoundMachine()) : this.recipeSet;
164+
searchTask = new FactoryRecipeSearchTask(
165+
factory,
166+
factory.getFoundMachine(),
167+
factory.getAvailableParallelism(),
168+
recipeSet,
169+
this,
170+
factory.getActiveRecipeList());
171+
TaskExecutor.FORK_JOIN_POOL.submit(searchTask);
172+
}
173+
160174
public NBTTagCompound serialize() {
161175
NBTTagCompound tag = new NBTTagCompound();
162176
tag.setTag("status", status.serialize());

src/main/java/hellfirepvp/modularmachinery/common/util/IOInventory.java

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import github.kasuminova.mmce.common.concurrent.Sync;
1212
import hellfirepvp.modularmachinery.common.tiles.base.TileEntitySynchronized;
1313
import hellfirepvp.modularmachinery.common.tiles.base.TileItemBus;
14+
import io.netty.util.collection.IntObjectHashMap;
1415
import net.minecraft.item.ItemStack;
1516
import net.minecraft.nbt.NBTTagCompound;
1617
import net.minecraft.nbt.NBTTagList;
@@ -24,7 +25,10 @@
2425
import net.minecraftforge.items.IItemHandlerModifiable;
2526

2627
import javax.annotation.Nonnull;
27-
import java.util.*;
28+
import java.util.ArrayList;
29+
import java.util.Arrays;
30+
import java.util.List;
31+
import java.util.Map;
2832
import java.util.concurrent.atomic.AtomicReference;
2933

3034
/**
@@ -37,8 +41,8 @@
3741
public class IOInventory implements IItemHandlerModifiable {
3842

3943
private final TileEntitySynchronized owner;
40-
private final Map<Integer, Integer> slotLimits = new HashMap<>(); // Value not present means default, aka 64.
41-
private final Map<Integer, SlotStackHolder> inventory = new HashMap<>();
44+
private final Map<Integer, Integer> slotLimits = new IntObjectHashMap<>(); // Value not present means default, aka 64.
45+
private final Map<Integer, SlotStackHolder> inventory = new IntObjectHashMap<>();
4246
public boolean allowAnySlots = false;
4347

4448
/**
@@ -71,14 +75,6 @@ public IOInventory(TileEntitySynchronized owner, int[] inSlots, int[] outSlots,
7175
this.accessibleSides = Arrays.asList(accessibleFrom);
7276
}
7377

74-
@Nonnull
75-
private static ItemStack copyWithSize(@Nonnull ItemStack stack, int amount) {
76-
if (stack.isEmpty() || amount <= 0) return ItemStack.EMPTY;
77-
ItemStack copiedStack = stack.copy();
78-
copiedStack.setCount(Math.min(amount, stack.getMaxStackSize()));
79-
return copiedStack;
80-
}
81-
8278
private static boolean arrayContains(int[] array, int i) {
8379
return Arrays.binarySearch(array, i) >= 0;
8480
}
@@ -166,7 +162,7 @@ private void redirectItemStackToNearContainers(int internalSlotId, ItemStack wil
166162
continue;
167163
}
168164

169-
ItemStack notInserted = insertItemStackToContainer(itemHandler, beInserted);
165+
ItemStack notInserted = ItemUtils.insertItemStackToContainer(itemHandler, beInserted);
170166
if (notInserted == ItemStack.EMPTY) {
171167
return;
172168
} else {
@@ -177,34 +173,6 @@ private void redirectItemStackToNearContainers(int internalSlotId, ItemStack wil
177173
setStackInSlotStrict(internalSlotId, beInserted);
178174
}
179175

180-
private static ItemStack insertItemStackToContainer(IItemHandler external, ItemStack willBeInserted) {
181-
ItemStack beInserted = willBeInserted;
182-
for (int externalSlotId = 0; externalSlotId < external.getSlots(); externalSlotId++) {
183-
ItemStack stackInSlot = external.getStackInSlot(externalSlotId);
184-
185-
if (stackInSlot == ItemStack.EMPTY) {
186-
ItemStack notInserted = external.insertItem(externalSlotId, beInserted, false);
187-
if (notInserted == ItemStack.EMPTY) {
188-
return ItemStack.EMPTY;
189-
} else {
190-
beInserted = notInserted;
191-
continue;
192-
}
193-
}
194-
195-
if (ItemUtils.matchStacks(stackInSlot, willBeInserted)) {
196-
ItemStack notInserted = external.insertItem(externalSlotId, beInserted, false);
197-
if (notInserted == ItemStack.EMPTY) {
198-
return ItemStack.EMPTY;
199-
} else {
200-
beInserted = notInserted;
201-
}
202-
}
203-
}
204-
205-
return beInserted;
206-
}
207-
208176
@Override
209177
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
210178
Sync.doSyncAction(() -> {
@@ -266,20 +234,20 @@ private ItemStack insertItemInternal(int slot, @Nonnull ItemStack stack, boolean
266234
}
267235

268236
SlotStackHolder holder = this.inventory.get(slot);
269-
ItemStack toInsert = copyWithSize(stack, stack.getCount());
237+
ItemStack toInsert = ItemUtils.copyStackWithSize(stack, stack.getCount());
270238
if (!holder.itemStack.isEmpty()) {
271-
ItemStack existing = copyWithSize(holder.itemStack, holder.itemStack.getCount());
239+
ItemStack existing = ItemUtils.copyStackWithSize(holder.itemStack, holder.itemStack.getCount());
272240
int max = Math.min(existing.getMaxStackSize(), getSlotLimit(slot));
273241
if (existing.getCount() >= max || !canMergeItemStacks(existing, toInsert)) {
274242
return stack;
275243
}
276244
int movable = Math.min(max - existing.getCount(), stack.getCount());
277245
if (!simulate) {
278246
holder.itemStack.grow(movable);
279-
owner.markForUpdateSync();
280247
if (listener != null) {
281248
listener.onChange();
282249
}
250+
owner.markForUpdateSync();
283251
}
284252
if (movable >= stack.getCount()) {
285253
return ItemStack.EMPTY;
@@ -293,21 +261,21 @@ private ItemStack insertItemInternal(int slot, @Nonnull ItemStack stack, boolean
293261
if (max >= stack.getCount()) {
294262
if (!simulate) {
295263
holder.itemStack = stack.copy();
296-
owner.markForUpdateSync();
297264
if (listener != null) {
298265
listener.onChange();
299266
}
267+
owner.markForUpdateSync();
300268
}
301269
return ItemStack.EMPTY;
302270
} else {
303271
ItemStack copy = stack.copy();
304272
copy.setCount(max);
305273
if (!simulate) {
306274
holder.itemStack = copy;
307-
owner.markForUpdateSync();
308275
if (listener != null) {
309276
listener.onChange();
310277
}
278+
owner.markForUpdateSync();
311279
}
312280
copy = stack.copy();
313281
copy.shrink(max);
@@ -338,12 +306,12 @@ private ItemStack extractItemInternal(int slot, int amount, boolean simulate) {
338306
return ItemStack.EMPTY;
339307
}
340308

341-
ItemStack extract = copyWithSize(holder.itemStack, Math.min(amount, holder.itemStack.getCount()));
309+
ItemStack extract = ItemUtils.copyStackWithSize(holder.itemStack, Math.min(amount, holder.itemStack.getCount()));
342310
if (extract.isEmpty()) {
343311
return ItemStack.EMPTY;
344312
}
345313
if (!simulate) {
346-
holder.itemStack = copyWithSize(holder.itemStack, holder.itemStack.getCount() - extract.getCount());
314+
holder.itemStack = ItemUtils.copyStackWithSize(holder.itemStack, holder.itemStack.getCount() - extract.getCount());
347315
if (listener != null) {
348316
listener.onChange();
349317
}

0 commit comments

Comments
 (0)