Skip to content

Commit

Permalink
ehnanced ladders now check quark:ladders tag. Narrator module keybind…
Browse files Browse the repository at this point in the history
… fix
  • Loading branch information
MehVahdJukaar committed Jun 5, 2024
1 parent b341459 commit c304952
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
7 changes: 5 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
- Fixed a crash when middle clicking a block and having Variant Selector module off
- Middle clicking a variant block while NOT having its parent variant in hand will now make you select the latter
- Magnets can now push multiple blocks at once
- Magnets can now pull blocks through semi transparent blocks, including other moveable ones like rails
- Variant selector will properly delegate method calls to the selected block placement logic
- Enhanced ladders features will now only be applied to blocks in the quark:ladders tag
- Fixed an issue with NarratorReaduout module and its keybinds not being registered if module is turned off
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public static class Client extends NarratorReadoutModule {

@LoadEvent
public void registerKeybinds(ZKeyMapping event) {
if(enabled) {
keybind = event.init("quark.keybind.narrator_readout", null, QuarkClient.MISC_GROUP);
keybindFull = event.init("quark.keybind.narrator_full_readout", null, QuarkClient.MISC_GROUP);
}
keybind = event.init("quark.keybind.narrator_readout", null, QuarkClient.MISC_GROUP);
keybindFull = event.init("quark.keybind.narrator_full_readout", null, QuarkClient.MISC_GROUP);
}

@PlayEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -65,10 +66,12 @@ public class EnhancedLaddersModule extends ZetaModule {

private static boolean staticEnabled;
private static TagKey<Item> laddersTag;
private static TagKey<Block> laddersBlockTag;

@LoadEvent
public final void setup(ZCommonSetup event) {
laddersTag = ItemTags.create(new ResourceLocation(Quark.MOD_ID, "ladders"));
laddersBlockTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "ladders"));
}

@LoadEvent
Expand Down Expand Up @@ -116,31 +119,26 @@ private static boolean canAttachTo(BlockState state, Block ladder, LevelReader w
return false;
}

// replaces ladder survives logic
public static boolean canLadderSurvive(BlockState state, LevelReader world, BlockPos pos) {
if(!staticEnabled || !allowFreestanding)
return false;
if(!state.is(laddersBlockTag))return false;

Direction facing = state.getValue(LadderBlock.FACING);
Direction opposite = facing.getOpposite();
BlockPos oppositePos = pos.relative(opposite);
BlockState oppositeState = world.getBlockState(oppositePos);

boolean solid = facing.getAxis() != Axis.Y && oppositeState.isFaceSturdy(world, oppositePos, facing) && !(oppositeState.getBlock() instanceof LadderBlock);
boolean solid = oppositeState.isFaceSturdy(world, oppositePos, facing) && !(oppositeState.getBlock() instanceof LadderBlock);
BlockState topState = world.getBlockState(pos.above());
return solid || (topState.getBlock() instanceof LadderBlock && (facing.getAxis() == Axis.Y || topState.getValue(LadderBlock.FACING) == facing));
}

public static boolean updateLadder(BlockState state, Direction facing, BlockState facingState, LevelAccessor world, BlockPos currentPos, BlockPos facingPos) {
if(!staticEnabled || !allowFreestanding)
return true;

return canLadderSurvive(state, world, currentPos);
}

@PlayEvent
public void onInteract(ZRightClickBlock event) {
if(!allowDroppingDown)
return;
if(!allowDroppingDown) return;

Player player = event.getPlayer();
InteractionHand hand = event.getHand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@Mixin(LadderBlock.class)
public class LadderBlockMixin {


@Inject(method = "canSurvive", at = @At("HEAD"), cancellable = true)
private void canSurvive(BlockState state, LevelReader level, BlockPos pos, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if(EnhancedLaddersModule.canLadderSurvive(state, level, pos)) {
Expand All @@ -26,12 +27,4 @@ private void canSurvive(BlockState state, LevelReader level, BlockPos pos, Callb
}
}

@Inject(method = "updateShape", at = @At("HEAD"), cancellable = true)
private void updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor world, BlockPos currentPos, BlockPos facingPos, CallbackInfoReturnable<BlockState> callbackInfoReturnable) {
if(!EnhancedLaddersModule.updateLadder(state, facing, facingState, world, currentPos, facingPos)) {
callbackInfoReturnable.setReturnValue(Blocks.AIR.defaultBlockState());
callbackInfoReturnable.cancel();
}
}

}

0 comments on commit c304952

Please sign in to comment.