Skip to content

Commit

Permalink
Fix predicate-based importing ignoring round-robin
Browse files Browse the repository at this point in the history
This bug was introduced in 8f659ea
as a fix for #271. That commit enforced slot-based iteration over
the network, which ignores round-robin-based iterators. That fix
actually only needed to be applied to exporting, which is what this
commit does now.

Closes #288
  • Loading branch information
rubensworks committed Apr 28, 2024
1 parent 7e71f9d commit fe31ada
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageSlotted;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
Expand Down Expand Up @@ -48,11 +49,11 @@ public PartTarget getPartTarget() {

@Override
public IIngredientComponentStorage<FluidStack, Integer> getFluidChannel() {
if (getFluidStackMatcher().hasMatchFlags()) {
return getChanneledNetwork().getChannel(getChannel());
}
// For predicate-based matchers, make sure we can iterate over the contents in a slotted manner,
// as the predicate must apply to each slotted ingredient.
return getChanneledNetwork().getChannel(getChannel());
}

@Override
public IIngredientComponentStorageSlotted<FluidStack, Integer> getFluidChannelSlotted() {
return getChanneledNetwork().getChannelSlotted(getChannel());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageSlotted;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
Expand Down Expand Up @@ -44,6 +45,11 @@ public IIngredientComponentStorage<FluidStack, Integer> getFluidChannel() {
return getChanneledNetwork().getChannel(getChannel());
}

@Override
public IIngredientComponentStorageSlotted<FluidStack, Integer> getFluidChannelSlotted() {
return getChanneledNetwork().getChannelSlotted(getChannel());
}

@Override
public boolean hasValidTarget() {
return storage != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageSlotted;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.PartTarget;
Expand All @@ -21,6 +22,8 @@ public interface IFluidTarget extends IChanneledTarget<IFluidNetwork, FluidStack

public IIngredientComponentStorage<FluidStack, Integer> getFluidChannel();

public IIngredientComponentStorageSlotted<FluidStack, Integer> getFluidChannelSlotted();

public IIngredientComponentStorage<FluidStack, Integer> getStorage();

public IngredientPredicate<FluidStack, Integer> getFluidStackMatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageSlotted;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.PartTarget;
Expand All @@ -21,6 +22,8 @@ public interface IItemTarget extends IChanneledTarget<IItemNetwork, ItemStack> {

public IIngredientComponentStorage<ItemStack, Integer> getItemChannel();

public IIngredientComponentStorageSlotted<ItemStack, Integer> getItemChannelSlotted();

public IIngredientComponentStorage<ItemStack, Integer> getStorage();

public int getSlot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageSlotted;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
Expand Down Expand Up @@ -45,11 +46,11 @@ public ItemTargetCapabilityProvider(ITunnelTransfer transfer, INetwork network,

@Override
public IIngredientComponentStorage<ItemStack, Integer> getItemChannel() {
if (getItemStackMatcher().hasMatchFlags()) {
return getChanneledNetwork().getChannel(getChannel());
}
// For predicate-based matchers, make sure we can iterate over the contents in a slotted manner,
// as the predicate must apply to each slotted ingredient.
return getChanneledNetwork().getChannel(getChannel());
}

@Override
public IIngredientComponentStorageSlotted<ItemStack, Integer> getItemChannelSlotted() {
return getChanneledNetwork().getChannelSlotted(getChannel());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.world.item.ItemStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorageSlotted;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
Expand Down Expand Up @@ -46,6 +47,11 @@ public IIngredientComponentStorage<ItemStack, Integer> getItemChannel() {
return getChanneledNetwork().getChannel(getChannel());
}

@Override
public IIngredientComponentStorageSlotted<ItemStack, Integer> getItemChannelSlotted() {
return getChanneledNetwork().getChannelSlotted(getChannel());
}

@Override
public boolean hasValidTarget() {
return storage != null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.cyclops.integratedtunnels.part.aspect;

import com.google.common.collect.ImmutableList;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.Tag;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.phys.AABB;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
Expand Down Expand Up @@ -786,12 +786,16 @@ public static final class Item {

if (input.hasValidTarget()) {
input.preTransfer();
// For predicate-based matchers, make sure we can iterate over the contents in a slotted manner,
// as the predicate must apply to each slotted ingredient.
// Only do this for exporting, not for importing, as this would otherwise break round-robin imports.
IIngredientComponentStorage<ItemStack, Integer> source = input.getItemStackMatcher().hasMatchFlags() ? input.getItemChannel() : input.getItemChannelSlotted();
TunnelHelpers.moveSingleStateOptimized(
input.getNetwork(),
input.getChanneledNetwork(),
input.getChannel(),
input.getConnection(),
input.getItemChannel(), -1,
source, -1,
input.getStorage(), input.getSlot(),
input.getItemStackMatcher(),
input.getPartTarget().getCenter(),
Expand Down Expand Up @@ -1152,12 +1156,16 @@ public boolean test(FluidStack integer) {

if (input.hasValidTarget()) {
input.preTransfer();
// For predicate-based matchers, make sure we can iterate over the contents in a slotted manner,
// as the predicate must apply to each slotted ingredient.
// Only do this for exporting, not for importing, as this would otherwise break round-robin imports.
IIngredientComponentStorage<FluidStack, Integer> source = input.getFluidStackMatcher().hasMatchFlags() ? input.getFluidChannel() : input.getFluidChannelSlotted();
TunnelHelpers.moveSingleStateOptimized(
input.getNetwork(),
input.getChanneledNetwork(),
input.getChannel(),
input.getConnection(),
input.getFluidChannel(),
source,
-1,
input.getStorage(),
-1,
Expand Down

0 comments on commit fe31ada

Please sign in to comment.