Skip to content

Commit

Permalink
[Fabric] Bug fixes (#63)
Browse files Browse the repository at this point in the history
- RedRouter Blocks can't conduct outside redstone signals anymore & now will emit strong redstone signals when one side is powered.
- Scroller Panes now can be used in Adventure mode as well.
  - They also won't push a `"scroller_changed"` event anymore, when a Computer changes the value.
- Create dependency's version got updated to something that makes more sense
  • Loading branch information
SammyForReal authored Aug 6, 2023
1 parent 2a7943d commit 7b29c96
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 18 deletions.
4 changes: 2 additions & 2 deletions fabric/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx2G

# Mod Properties
mod_version=1.6.0
mod_version=1.6.1
maven_group=cc.tweaked_programs
archives_base_name=cccbridge

Expand All @@ -19,7 +19,7 @@ parchment_version=2023.07.16
# Dependencies
fabric_version=0.86.0
cc_version=1.106.1
create_version=0.5.1-c-build.1113
create_version=0.5.1-d-build.1130
create_version_production=0.5.1-c

# Mod Menu - https://modrinth.com/mod/modmenu/versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ public final int getValue() {
@LuaFunction
public final void setValue(int value) {
ScrollerBlockEntity be = getTarget();
if (be != null)
if (be != null) {
be.nextChangeQuietly();
be.setValue(value);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.jetbrains.annotations.NotNull;

public class RedRouterBlock extends HorizontalDirectionalBlock implements EntityBlock, IWrenchable {
public static final Properties REDROUTER_BLOCK_PROPERTIES = FabricBlockSettings.create().strength(1.3f).sound(SoundType.STONE).noOcclusion();
public static final Properties REDROUTER_BLOCK_PROPERTIES = FabricBlockSettings.create().strength(1.3f).sound(SoundType.STONE).noOcclusion().isRedstoneConductor((state, view, pos) -> false);
public static final int FACE_AMOUNT = 16;
public static final IntegerProperty FACE = IntegerProperty.create("face", 0, FACE_AMOUNT);
public RedRouterBlock(Properties properties) {
Expand Down Expand Up @@ -73,6 +73,11 @@ public int getSignal(@NotNull BlockState state, BlockGetter world, @NotNull Bloc
return redrouter.getPower(dir);
}

@Override
public int getDirectSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
return getSignal(state, level, pos, direction);
}

@Override
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
BlockEntity tileentity = context.getLevel().getBlockEntity(context.getClickedPos());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
public class ScrollerBlockEntity extends SmartBlockEntity implements PeripheralBlockEntity {
private ScrollerBlockPeripheral peripheral;
private boolean locked = false;
private boolean quietly = false;
private boolean updateLock = false;
private boolean playTickSound = false;
private LuaScrollValueBehaviour scroller;

public ScrollerBlockEntity(BlockPos pos, BlockState state) {
Expand All @@ -54,8 +54,16 @@ public void setValue(int value) {
scroller.setValue(value);
}

public void nextChangeQuietly() {
quietly = true;
}

public void fireUpdateValueEvent() {
if (peripheral != null)
if (quietly) {
quietly = false;
return;
}
if (peripheral != null )
peripheral.sendEvent("scroller_changed", scroller.getValue());
}

Expand All @@ -74,16 +82,6 @@ public static void tick(Level world, BlockPos blockPos, BlockState state, BlockE
world.setBlock(blockPos, state.setValue(BlockStateProperties.LOCKED, scroller.locked), 19); // 19 = BLOCK_UPDATE_FLAGS
scroller.updateLock = false;
}
if (scroller.playTickSound) {
world.playSound(
null,
blockPos,
AllSoundEvents.SCROLL_VALUE.getMainEvent(),
SoundSource.BLOCKS,
0.25f,
1.5f);
scroller.playTickSound = false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cc.tweaked_programs.cccbridge.common.mixin;

import cc.tweaked_programs.cccbridge.common.minecraft.blockEntity.ScrollerBlockEntity;
import com.simibubi.create.foundation.utility.AdventureUtil;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
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(AdventureUtil.class)
public abstract class MixinAdventureUtil {
@Inject(method = "isAdventure", at = @At("HEAD"), cancellable = true, remap = false)
private static void cccbridge$isAdventure(Player player, CallbackInfoReturnable<Boolean> cir) {
if (player.isSpectator())
return;

Level level = player.level();
HitResult hitResult = player.pick(5, 1, false);

if (hitResult instanceof BlockHitResult blockHit) {
BlockEntity blockEntity = level.getBlockEntity(blockHit.getBlockPos());

if (blockEntity instanceof ScrollerBlockEntity)
cir.setReturnValue(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.List;

@Mixin(CarriageContraption.class)
public abstract class CarriageContraptionMixin extends Contraption {
public abstract class MixinCarriageContraption extends Contraption {
@Shadow
private List<BlockPos> assembledBlazeBurners;

Expand Down
3 changes: 2 additions & 1 deletion fabric/src/main/resources/cccbridge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"package": "cc.tweaked_programs.cccbridge.common.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"CarriageContraptionMixin"
"MixinCarriageContraption",
"MixinAdventureUtil"
],
"client": [
],
Expand Down

0 comments on commit 7b29c96

Please sign in to comment.