Skip to content

Commit

Permalink
Fix passive import/export ignoring active aspect channel, Closes #308
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Nov 19, 2024
1 parent 06e21c1 commit a5266e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
import org.cyclops.integrateddynamics.api.network.INetworkCraftingHandlerRegistry;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.aspect.IAspectWrite;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integrateddynamics.core.part.write.PartStateWriterBase;
import org.cyclops.integratedtunnels.GeneralConfig;
import org.cyclops.integratedtunnels.IntegratedTunnels;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import org.cyclops.integratedtunnels.part.aspect.ITunnelConnection;
import org.cyclops.integratedtunnels.part.aspect.TunnelAspectWriteBuilders;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -248,4 +252,22 @@ public static BlockPlaceContext createBlockItemUseContext(Level world, @Nullable
(double)pos.getY() + 0.5D + (double)side.getStepY() * 0.5D,
(double)pos.getZ() + 0.5D + (double)side.getStepZ() * 0.5D), side, pos, false));
}

/**
* Determine the channel for passive interaction of a part.
* This prefers the active aspect's channel property, and falls back to the part's energy channel.
* @param partStateBase The part's state.
* @return The channel.
*/
public static int getPassiveInteractionChannel(PartStateWriterBase<?> partStateBase) {
int channel = partStateBase.getChannel();
IAspectWrite aspect = partStateBase.getActiveAspect();
if (aspect != null) {
IAspectProperties properties = partStateBase.getAspectProperties(aspect);
if (properties != null) {
channel = properties.getValue(TunnelAspectWriteBuilders.PROP_CHANNEL).getRawValue();
}
}
return channel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.write.IPartTypeWriter;
import org.cyclops.integratedtunnels.core.TunnelHelpers;
import org.cyclops.integratedtunnels.core.part.PartStatePositionedAddon;

/**
Expand All @@ -32,7 +33,7 @@ public <T2> LazyOptional<T2> getCapability(Capability<T2> capability, INetwork n
}

protected IEnergyStorage getEnergyStorage() {
return getPositionedAddonsNetwork().getChannelExternal(CapabilityEnergy.ENERGY, getChannel());
return getPositionedAddonsNetwork().getChannelExternal(CapabilityEnergy.ENERGY, TunnelHelpers.getPassiveInteractionChannel(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
import org.cyclops.integrateddynamics.api.part.write.IPartTypeWriter;
import org.cyclops.integratedtunnels.GeneralConfig;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.core.TunnelHelpers;
import org.cyclops.integratedtunnels.core.part.PartStatePositionedAddon;

import javax.annotation.Nonnull;

import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;

/**
* A part state for handling fluid import and export.
* It also acts as an fluid capability that can be added to itself.
Expand All @@ -38,7 +37,7 @@ public <T2> LazyOptional<T2> getCapability(Capability<T2> capability, INetwork n
}

protected IFluidHandler getFluidHandler() {
return getPositionedAddonsNetwork().getChannelExternal(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, getChannel());
return getPositionedAddonsNetwork().getChannelExternal(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, TunnelHelpers.getPassiveInteractionChannel(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.write.IPartTypeWriter;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.core.TunnelHelpers;
import org.cyclops.integratedtunnels.core.part.PartStatePositionedAddon;

import javax.annotation.Nonnull;
Expand All @@ -35,7 +36,7 @@ public <T2> LazyOptional<T2> getCapability(Capability<T2> capability, INetwork n
}

protected IItemHandler getItemHandler() {
return getPositionedAddonsNetwork().getChannelExternal(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getChannel());
return getPositionedAddonsNetwork().getChannelExternal(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, TunnelHelpers.getPassiveInteractionChannel(this));
}

@Override
Expand Down

0 comments on commit a5266e7

Please sign in to comment.