[Suggestion] Pistons redirecting redstone
apple502j opened this issue ยท 4 comments
An option to have pistons (and sticky pistons) redirect redstone would be nice - allows pistons on the floor to be powered seamlessly without qc/line of torches or targets. Also Bedrock parity.
My attempt (build successful, crashes when launched with no crash report):
package carpetextra.mixins;
import carpetextra.CarpetExtraSettings;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.Direction;
import net.minecraft.block.Blocks;
import net.minecraft.state.property.Property;
import net.minecraft.block.PistonBlock;
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(RedstoneWireBlock.class)
public abstract class RedstoneWireBlockMixin
{
@Inject(
method = "Lnet/minecraft/block/RedstoneWireBlock;connectsTo(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Direction;)Z",
at = @At(value = "HEAD"),
cancellable = true
)
protected static void onConnectsTo(BlockState state, Direction dir, CallbackInfoReturnable<Boolean> cir)
{
if (state.isOf(Blocks.PISTON) && CarpetExtraSettings.pistonRedirectsRedstone)
cir.setReturnValue(dir != state.get((Property<?>)PistonBlock.FACING));
}
}
The method needs to be private and you need the opposite of the direction.
private static void onConnectsTo(BlockState state, Direction dir, CallbackInfoReturnable<Boolean> cir)
{
if (state.isOf(Blocks.PISTON) && CarpetExtraSettings.pistonRedirectsRedstone) {
cir.setReturnValue(dir != state.get(PistonBlock.FACING).getOpposite());
cir.cancel();
}
}
made a pr #148
Would you mind making a PR to Carpet Extra with this? (or would you allow me or someone else to PR this code under the repo's license?)
Added with #148 , checkout dev builds or wait for next release