Skip to content

Commit

Permalink
Fix chain cogwheels not connecting to each other via cogwheels (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine committed Mar 16, 2024
1 parent 9afeceb commit 86b1854
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.hlysine.create_connected.mixin.chaincogwheel;

import com.hlysine.create_connected.CCBlocks;
import com.simibubi.create.content.kinetics.RotationPropagator;
import com.simibubi.create.content.kinetics.base.IRotate;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import com.simibubi.create.content.kinetics.chainDrive.ChainDriveBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = RotationPropagator.class, remap = false)
public class RotationPropagatorMixin {
@Inject(
method = "getRotationSpeedModifier(Lcom/simibubi/create/content/kinetics/base/KineticBlockEntity;Lcom/simibubi/create/content/kinetics/base/KineticBlockEntity;)F",
at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/kinetics/chainDrive/ChainDriveBlock;areBlocksConnected(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/Direction;)Z"),
cancellable = true
)
private static void handleChainCogwheels(KineticBlockEntity from,
KineticBlockEntity to,
CallbackInfoReturnable<Float> cir) {
final BlockState stateFrom = from.getBlockState();
final BlockState stateTo = to.getBlockState();
Block fromBlock = stateFrom.getBlock();
Block toBlock = stateTo.getBlock();
final IRotate definitionFrom = (IRotate) fromBlock;
final IRotate definitionTo = (IRotate) toBlock;
final BlockPos diff = to.getBlockPos()
.subtract(from.getBlockPos());
final Direction direction = Direction.getNearest(diff.getX(), diff.getY(), diff.getZ());

if (stateFrom.is(CCBlocks.ENCASED_CHAIN_COGWHEEL.get()) && stateTo.is(CCBlocks.ENCASED_CHAIN_COGWHEEL.get())) {
boolean connected = ChainDriveBlock.areBlocksConnected(stateFrom, stateTo, direction);
if (!connected) {
if (diff.distManhattan(BlockPos.ZERO) != 1) {
cir.setReturnValue(0f);
return;
}
if (direction.getAxis() == definitionFrom.getRotationAxis(stateFrom)) {
cir.setReturnValue(0f);
return;
}
if (definitionFrom.getRotationAxis(stateFrom) == definitionTo.getRotationAxis(stateTo)) {
cir.setReturnValue(-1f);
}
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/create_connected.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ItemUseOverridesMixin",
"KineticBlockAdvancementMixin",
"ManualApplicationRecipeMixin",
"chaincogwheel.RotationPropagatorMixin",
"compat.CopycatBlockEntityMixin",
"compat.CopycatBlockMixin",
"contraption.AbstractContainerMenuMixin",
Expand Down

1 comment on commit 86b1854

@hlysine
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops wrong issue. Should be #52

Please sign in to comment.