Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cyclops.integratedcrafting.part;

import com.google.common.collect.Lists;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -133,7 +134,10 @@ public boolean shouldTriggerBlockRenderUpdate(@Nullable State oldPartState, @Nul

@Override
public void onBlockNeighborChange(INetwork network, IPartNetwork partNetwork, PartTarget target, State state, BlockGetter world, Block neighbourBlock, BlockPos neighbourBlockPos) {
boolean isNeighbourTarget = neighbourBlockPos.equals(target.getTarget().getPos().getBlockPos());
// Targets such as furnaces notify their neighbours on every operation, while their recipes remain the same.
// Only re-register if the target really changed, as this temporarily removes our crafting jobs from the network.
boolean isNeighbourTarget = neighbourBlockPos.equals(target.getTarget().getPos().getBlockPos())
&& state.hasTargetChanged();
boolean hadValidTarget = false;
if (isNeighbourTarget) {
hadValidTarget = state.hasValidTarget();
Expand Down Expand Up @@ -179,6 +183,21 @@ public boolean hasValidTarget() {
return this.hasValidTarget;
}

/**
* @return If the target gained or lost its recipe handler, or exposes other recipes than the ones that were last read.
*/
public boolean hasTargetChanged() {
if (getTarget() == null || this.recipes == null) {
return true;
}
LazyOptional<IRecipeHandler> recipeHandler = getTargetRecipeHandler();
if (recipeHandler.isPresent() != this.hasValidTarget) {
return true;
}
return recipeHandler.isPresent() && !Lists.newArrayList(recipeHandler.orElseThrow(IllegalStateException::new).getRecipes())
.equals(Lists.newArrayList(this.recipes));
}

@Override
public void writeToNBT(CompoundTag tag) {
super.writeToNBT(tag);
Expand Down
Loading