Skip to content

Commit

Permalink
Fix variable-based offsets not working in interfaces, Closes #289
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Apr 27, 2024
1 parent f9248fb commit 95e3e4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod_version=1.8.25
minecraft_version=1.19.2
forge_version=43.0.8
cyclopscore_version=1.17.0-237
integrateddynamics_version=1.19.2-1.21.0-696
integrateddynamics_version=1.19.2-1.21.3-724
integratedtunnelscompat_version=1.19-1.0.0-19
release_type=release
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import org.apache.commons.lang3.tuple.Triple;
import org.cyclops.cyclopscore.datastructure.DimPos;
import org.cyclops.cyclopscore.network.PacketCodec;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork;
import org.cyclops.integrateddynamics.api.part.IPartContainer;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
import org.cyclops.integrateddynamics.core.network.PartNetworkElement;
import org.cyclops.integrateddynamics.core.part.PartStateBase;
import org.cyclops.integrateddynamics.core.part.PartTypeBase;

Expand All @@ -45,7 +48,8 @@ public PartTypeInterfacePositionedAddon(String name) {

@Override
public boolean isUpdate(S state) {
return getConsumptionRate(state) > 0 && org.cyclops.integrateddynamics.GeneralConfig.energyConsumptionMultiplier > 0;
return (getConsumptionRate(state) > 0 && org.cyclops.integrateddynamics.GeneralConfig.energyConsumptionMultiplier > 0)
|| state.requiresOffsetUpdates();
}

@Override
Expand Down Expand Up @@ -137,6 +141,20 @@ public boolean setTargetOffset(S state, PartPos center, Vec3i offset) {
return ret;
}

@Override
public void onOffsetVariablesChanged(PartTarget target, S state) {
super.onOffsetVariablesChanged(target, state);

// Force the network element to be re-added,
// as a change in offset variable might have influenced whether or not this part is updatable or not,
// so we need to let the network re-check it, otherwise the part may not tick while it should.
state.initializeOffsets(); // Force the state to sync up with the offset variables inventory.
DimPos dimPos = target.getCenter().getPos();
INetwork network = NetworkHelpers.getNetworkChecked(dimPos.getLevel(true), dimPos.getBlockPos(), target.getCenter().getSide());
PartNetworkElement networkElement = new PartNetworkElement<>((P) this, target.getCenter());
network.setPriorityAndChannel(networkElement, getPriority(state), getChannel(state));
}

public static abstract class State<N extends IPositionedAddonsNetwork, T, P extends PartTypeInterfacePositionedAddon<N, T, P, S>, S extends State<N, T, P, S>>
extends PartStateBase<P>
implements IPartTypeInterfacePositionedAddon.IState<N, T, P, S> {
Expand Down

0 comments on commit 95e3e4c

Please sign in to comment.