Skip to content

Commit

Permalink
Fix some issues with iron buttons and levers
Browse files Browse the repository at this point in the history
  • Loading branch information
legobmw99 committed Jan 15, 2024
1 parent 9852105 commit fdd9dca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import net.minecraft.world.level.block.ButtonBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockSetType;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

import javax.annotation.Nullable;
import java.util.List;
Expand All @@ -40,10 +43,12 @@ public boolean useAllomantically(BlockState state, Level level, BlockPos pos, Pl
ExtrasSetup.ALLOMANTICALLY_ACTIVATED_BLOCK_TRIGGER.get().trigger(sp, pos, isPush);
}

if (state.getValue(POWERED) || level.isClientSide) {
if (state.getValue(POWERED) || level.isClientSide()) {
return true;
} else if (isPush == this.activatedOnPush) {
this.press(state, level, pos);
this.playSound(null, level, pos, true);
level.gameEvent(player, GameEvent.BLOCK_ACTIVATE, pos);
return true;
} else {
return false;
Expand All @@ -60,6 +65,14 @@ public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Play
}


@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
if (!this.activatedOnPush) {
return super.getShape(pState.cycle(POWERED), pLevel, pPos, pContext);
}
return super.getShape(pState, pLevel, pPos, pContext);
}

@Override
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
super.appendHoverText(stack, worldIn, tooltip, flagIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LeverBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.BlockHitResult;

import javax.annotation.Nullable;
Expand All @@ -31,21 +32,18 @@ public IronLeverBlock() {
}

@Override
public boolean useAllomantically(BlockState state, Level world, BlockPos pos, Player player, boolean isPush) {
public boolean useAllomantically(BlockState state, Level level, BlockPos pos, Player player, boolean isPush) {
if (player instanceof ServerPlayer sp) {
ExtrasSetup.ALLOMANTICALLY_ACTIVATED_BLOCK_TRIGGER.get().trigger(sp, pos, isPush);
}

state = state.cycle(POWERED);
if (world.isClientSide) {
if (level.isClientSide()) {
return true;
}
if ((!isPush && state.getValue(POWERED)) || (isPush && !state.getValue(POWERED))) {

world.setBlock(pos, state, 3);
float f = state.getValue(POWERED) ? 0.6F : 0.5F;
world.playSound(null, pos, SoundEvents.LEVER_CLICK, SoundSource.BLOCKS, 0.3F, f);
this.updateNeighbors(state, world, pos);
if (isPush == state.getValue(POWERED)) {
BlockState blockstate = this.pull(state, level, pos);
float f = blockstate.getValue(POWERED) ? 0.6F : 0.5F;
level.playSound(null, pos, SoundEvents.LEVER_CLICK, SoundSource.BLOCKS, 0.3F, f);
level.gameEvent(player, blockstate.getValue(POWERED) ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, pos);
return true;

}
Expand Down

0 comments on commit fdd9dca

Please sign in to comment.