Skip to content

Commit a4be038

Browse files
committed
Fix for input item/fluid restrictions
1 parent 2f18a6a commit a4be038

File tree

8 files changed

+39
-29
lines changed

8 files changed

+39
-29
lines changed

src/main/java/igentuman/nc/block/entity/fission/FissionControllerBE.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,16 @@ public FissionControllerBE(BlockPos pPos, BlockState pBlockState) {
172172
contentHandler.itemHandler.setGlobalMode(1, SlotModePair.SlotMode.PUSH);
173173
contentHandler.fluidCapability.tanks.get(0).setCapacity(10000);
174174
contentHandler.fluidCapability.tanks.get(1).setCapacity(10000);
175-
contentHandler.setAllowedInputFluids(0, getAllowedCoolants());
176-
contentHandler.setAllowedInputFluids(1, getAllowedCoolantsOutput());
175+
contentHandler.setAllowedInputFluids(0, this::getAllowedCoolants);
176+
contentHandler.setAllowedInputFluids(1, this::getAllowedCoolantsOutput);
177177
for(String type: activeCoolersTypes()) {
178178
contentHandler.setAllowedInputFluids(
179179
1+activeCoolersTypes().indexOf(type),
180-
FissionBlocks.heatsinks.get(type).getAllowedFluids()
180+
() -> FissionBlocks.heatsinks.get(type).getAllowedFluids()
181181
);
182182
contentHandler.fluidCapability.setGlobalMode(2+activeCoolersTypes().indexOf(type), SlotModePair.SlotMode.PULL);
183183
}
184+
contentHandler.setAllowedInputItems(this::getAllowedInputItems);
184185
}
185186

186187
private List<String> activeCoolersTypes() {
@@ -427,7 +428,7 @@ public void tickServer() {
427428
}
428429
trackChanges(coolDown());
429430
handleMeltdown();
430-
contentHandler.setAllowedInputItems(getAllowedInputItems());
431+
431432
} else {
432433
//if reactor was broken during processing, contaminate area
433434
if(isProcessing() && wasFormed) {

src/main/java/igentuman/nc/block/entity/fusion/FusionCoreBE.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ public FusionCoreBE(BlockPos pPos, BlockState pBlockState) {
183183
contentHandler.fluidCapability.setGlobalMode(6, SlotModePair.SlotMode.OUTPUT);
184184
//hot coolant
185185
contentHandler.fluidCapability.setGlobalMode(7, SlotModePair.SlotMode.OUTPUT);
186-
contentHandler.setAllowedInputFluids(0, getAllowedInputFluids());
187-
contentHandler.setAllowedInputFluids(1, getAllowedInputFluids());
188-
contentHandler.setAllowedInputFluids(2, getAllowedCoolants());
189-
contentHandler.setAllowedInputFluids(7, getAllowedCoolantsOutput());
186+
contentHandler.setAllowedInputFluids(0, this::getAllowedInputFluids);
187+
contentHandler.setAllowedInputFluids(1, this::getAllowedInputFluids);
188+
contentHandler.setAllowedInputFluids(2, this::getAllowedCoolants);
189+
contentHandler.setAllowedInputFluids(7, this::getAllowedCoolantsOutput);
190190
contentHandler.fluidCapability.tanks.get(2).setCapacity(100000);
191191
contentHandler.fluidCapability.tanks.get(7).setCapacity(100000);
192192
}
@@ -580,6 +580,10 @@ protected void simulateReaction() {
580580
trackChanges(powered);
581581
} else {
582582
powered = false;
583+
if(plasmaTemperature > 0) {
584+
plasmaTemperature = (long) Math.max(0, plasmaTemperature/1.2f - 10000);
585+
changed = true;
586+
}
583587
}
584588
if (!hasRecipe()) {
585589
updateRecipe();

src/main/java/igentuman/nc/block/entity/kugelblitz/ChamberTerminalBE.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public ChamberTerminalBE(BlockPos pPos, BlockState pBlockState) {
118118
contentHandler.fluidCapability.setGlobalMode(0, SlotModePair.SlotMode.INPUT);
119119
contentHandler.fluidCapability.setGlobalMode(1, SlotModePair.SlotMode.OUTPUT);
120120
contentHandler.setBlockEntity(this);
121+
contentHandler.setAllowedInputFluids(0, this::getAllowedInputFluids);
121122
}
122123

123124
@Override
@@ -248,7 +249,6 @@ public void tickServer() {
248249
powered = false;
249250
}
250251
handleMeltdown();
251-
contentHandler.setAllowedInputFluids(0, getAllowedInputFluids());
252252
}
253253
refreshCacheFlag = !multiblock().isFormed();
254254
if(wasPowered != powered) {

src/main/java/igentuman/nc/block/entity/processor/NCProcessorBE.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class NCProcessorBE<RECIPE extends AbstractRecipe> extends NuclearCraftBE
8686
private List<FluidStack> allowedFluids;
8787
private LazyOptional<NCGTEnergyHandler> gtEnergyCap;
8888
private ParticleOptions particle1 = ParticleTypes.SMOKE;
89-
protected ProcessorPrefab prefab;
89+
protected ProcessorPrefab<?,?> prefab;
9090

9191
public LazyOptional<IEnergyStorage> getEnergy() {
9292
return energy;
@@ -96,7 +96,7 @@ public LazyOptional<IEnergyStorage> getEnergy() {
9696

9797
public RecipeInfo<RECIPE> recipeInfo = new RecipeInfo<RECIPE>();
9898

99-
public ProcessorPrefab prefab() {
99+
public ProcessorPrefab<?,?> prefab() {
100100
if(prefab == null) {
101101
prefab = Processors.all().get(getName());
102102
}
@@ -354,9 +354,9 @@ public void tickServer() {
354354
return;
355355
}
356356
boolean updated = manualUpdate();
357-
contentHandler.setAllowedInputItems(getAllowedInputItems());
357+
contentHandler.setAllowedInputItems(this::getAllowedInputItems);
358358
for(int i = 0; i < prefab().getSlotsConfig().getInputFluids(); i++) {
359-
contentHandler.setAllowedInputFluids(i, getAllowedInputFluids());
359+
contentHandler.setAllowedInputFluids(i, this::getAllowedInputFluids);
360360
}
361361
processRecipe();
362362
handleRecipeOutput();

src/main/java/igentuman/nc/block/entity/turbine/TurbineControllerBE.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public TurbineControllerBE(BlockPos pPos, BlockState pBlockState) {
120120
contentHandler.fluidCapability.setGlobalMode(0, SlotModePair.SlotMode.INPUT);
121121
contentHandler.fluidCapability.setGlobalMode(1, SlotModePair.SlotMode.OUTPUT);
122122
contentHandler.setBlockEntity(this);
123+
contentHandler.setAllowedInputFluids(0, this::getAllowedInputFluids);
124+
123125
}
124126

125127
@Override
@@ -268,7 +270,6 @@ public void tickServer() {
268270
powered = false;
269271
}
270272
handleMeltdown();
271-
contentHandler.setAllowedInputFluids(0, getAllowedInputFluids());
272273
}
273274
refreshCacheFlag = !multiblock().isFormed();
274275
if(wasPowered != powered) {

src/main/java/igentuman/nc/handler/sided/SidedContentHandler.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.util.HashMap;
1818
import java.util.List;
19+
import java.util.function.Supplier;
1920

2021
import static igentuman.nc.handler.sided.SlotModePair.SlotMode.INPUT;
2122

@@ -192,10 +193,9 @@ public SlotModePair.SlotMode getSlotType(int id)
192193
}
193194
private Direction lastPushSide = Direction.UP;
194195
private Direction lastPullSide = Direction.UP;
196+
195197
public boolean tick() {
196198
updated = false;
197-
198-
199199
if(!canPush() && !canPull()) {
200200
return updated;
201201
}
@@ -293,13 +293,13 @@ public void saveSideMap() {
293293
}
294294
}
295295

296-
public void setAllowedInputItems(List<ItemStack> allowedInputItems) {
296+
public void setAllowedInputItems(Supplier<List<ItemStack>> allowedInputItems) {
297297
if(itemHandler != null) {
298298
itemHandler.allowedInputItems = allowedInputItems;
299299
}
300300
}
301301

302-
public void setAllowedInputFluids(int slotId, List<FluidStack> allowedInputFluids) {
302+
public void setAllowedInputFluids(int slotId, Supplier<List<FluidStack>> allowedInputFluids) {
303303
if(fluidCapability != null) {
304304
if(fluidCapability.allowedFluids == null) {
305305
fluidCapability.allowedFluids = new HashMap<>();
@@ -322,8 +322,7 @@ public void voidSlot(int slotId) {
322322
fluidCapability.voidSlot(getSlotIdFromGlobalId(slotId) + inputFluidSlots);
323323
}
324324
itemHandler.voidSlot(getSlotIdFromGlobalId(slotId) + inputItemSlots);
325-
} catch (NullPointerException|IndexOutOfBoundsException e) {
326-
}
325+
} catch (NullPointerException|IndexOutOfBoundsException ignored) { }
327326
}
328327

329328
public Object[] getSlotContent(int slotId) {

src/main/java/igentuman/nc/handler/sided/capability/FluidCapabilityHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.minecraftforge.registries.ForgeRegistries;
1717

1818
import java.util.*;
19+
import java.util.function.Supplier;
1920

2021
import static igentuman.nc.handler.sided.SlotModePair.SlotMode.*;
2122

@@ -27,7 +28,7 @@ public class FluidCapabilityHandler extends AbstractCapabilityHandler implements
2728
public List<FluidStack> holdedInputs = new ArrayList<>();
2829
private Map<Direction, LazyOptional<FluidHandlerWrapper>> handlerCache = new HashMap<>();
2930

30-
public HashMap<Integer, List<FluidStack>> allowedFluids;
31+
public HashMap<Integer, Supplier<List<FluidStack>>> allowedFluids;
3132

3233

3334
public FluidCapabilityHandler(int inputSlots, int outputSlots, int inputCapacity, int outputCapacity) {
@@ -70,7 +71,7 @@ public boolean isValidSlotFluid(int id, FluidStack fluid)
7071
{
7172
if(allowedFluids == null) return true;
7273
if(!allowedFluids.containsKey(id)) return true;
73-
for(FluidStack stack: allowedFluids.get(id)) {
74+
for(FluidStack stack: allowedFluids.get(id).get()) {
7475
if(stack.isFluidEqual(fluid)) {
7576
return true;
7677
}

src/main/java/igentuman/nc/handler/sided/capability/ItemCapabilityHandler.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323

2424
import javax.annotation.Nonnull;
2525
import java.util.*;
26+
import java.util.function.Supplier;
2627

2728
import static igentuman.nc.handler.sided.SlotModePair.SlotMode.*;
2829

2930
public class ItemCapabilityHandler extends AbstractCapabilityHandler implements IItemHandlerModifiable, INBTSerializable<CompoundTag> {
3031

31-
public List<ItemStack> allowedInputItems;
32+
public Supplier<List<ItemStack>> allowedInputItems;
3233
public HashMap<Integer, List<Item>> validItemsForSlot = new HashMap<>();
3334
protected NonNullList<ItemStack> stacks;
3435
protected ItemStack[] sortedStacks;
@@ -163,7 +164,7 @@ protected int getStackLimit(int slot, @NotNull ItemStack stack) {
163164

164165
@Override
165166
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
166-
return true;
167+
return isValidInputItem(stack);
167168
}
168169

169170
private int isValidForAnyInputSlot(ItemStack stack) {
@@ -262,7 +263,7 @@ public LazyOptional<ItemHandlerWrapper> getCapability(Direction side) {
262263
private LazyOptional<ItemHandlerWrapper> globalCap() {
263264

264265
if(globalCap == null) {
265-
globalCap = LazyOptional.of(() -> new ItemHandlerWrapper(null, this, (i) -> true, (i, s) -> true));
266+
globalCap = LazyOptional.of(() -> new ItemHandlerWrapper(null, this, (i) -> outputAllowed(i, null), (i, s) -> inputAllowed(i, s, null)));
266267
}
267268
return globalCap;
268269
}
@@ -284,21 +285,24 @@ private boolean inputAllowed(Integer i, ItemStack stack, Direction side) {
284285
validForSlot = validItemsForSlot.get(i).contains(stack.getItem());
285286
}
286287
if (!validForSlot) return false;
288+
if (side == null) {
289+
return i == isValidForAnyInputSlot(stack);
290+
}
287291
SidedContentHandler.RelativeDirection relativeDirection = SidedContentHandler.RelativeDirection.toRelative(side, getFacing());
288292
SlotModePair.SlotMode mode = sideMap.get(relativeDirection.ordinal())[i].getMode();
289-
return mode == INPUT || mode == PULL && isValidInputItem(stack);
293+
return (mode == INPUT || mode == PULL || mode == DEFAULT) && isValidInputItem(stack);
290294
}
291295

292296
public boolean isValidInputItem(ItemStack item)
293297
{
294298
if(allowedInputItems == null) return true;
295-
if(allowedInputItems.contains(item)) return true;
296-
for(ItemStack stack: allowedInputItems) {
299+
if(allowedInputItems.get().contains(item)) return true;
300+
for(ItemStack stack: allowedInputItems.get()) {
297301
if(stack.is(item.getItem())) {
298302
return true;
299303
}
300304
}
301-
return allowedInputItems.isEmpty();
305+
return allowedInputItems.get().isEmpty();
302306
}
303307
public boolean pushItems(Direction dir) {
304308
return pushItems(dir, false, tile.getBlockPos());

0 commit comments

Comments
 (0)