Skip to content

Commit

Permalink
Open double
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarokIce committed Jun 10, 2024
1 parent edce300 commit e65de34
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/main/java/ho/artisan/bdo/event/BDOPlayerEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ho.artisan.bdo.BurstDoorOpen;
import ho.artisan.bdo.BurstDoorOpenConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.BlockTags;
Expand All @@ -13,6 +14,7 @@
import net.minecraft.world.level.block.DoorBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DoorHingeSide;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -44,23 +46,35 @@ public static void playerTick(TickEvent.PlayerTickEvent event) {
if (euclidean(doorTruePos, player.position()) > 0.65) return;

if (state.is(BlockTags.WOODEN_DOORS)) {
openDoor(level, pos, state, player);
openDoor(level, pos, state, player, blockFace);
level.playSound(null, pos, SoundEvents.ZOMBIE_ATTACK_WOODEN_DOOR, SoundSource.BLOCKS, 1.0F, 1.0F);
return;
}

level.playSound(null, pos, SoundEvents.ZOMBIE_ATTACK_IRON_DOOR, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!BurstDoorOpenConfig.IRON_DOOR_BREAK_FLAG.get()) return;
openDoor(level, pos, state, player, blockFace);
}

openDoor(level, pos, state, player);
level.playSound(null, pos, SoundEvents.ZOMBIE_ATTACK_IRON_DOOR, SoundSource.BLOCKS, 1.0F, 1.0F);
private static void openDoor(Level level, BlockPos pos, BlockState state, Player player, Direction face) {
state = state.cycle(DoorBlock.OPEN);
level.setBlock(pos, state, 10);
level.gameEvent(player, GameEvent.BLOCK_OPEN, pos);

}
var side = state.getValue(DoorBlock.HINGE);
pos = side == DoorHingeSide.RIGHT
? pos.offset(-face.getStepZ(), face.getStepY(), -face.getStepX())
: pos.offset(face.getStepZ(), face.getStepY(), face.getStepX());

state = level.getBlockState(pos);
if (!state.is(BlockTags.DOORS)) return;
if (state.getValue(BlockStateProperties.OPEN)) return;

private static void openDoor(Level level, BlockPos pos, BlockState state, Player player) {
state = state.cycle(DoorBlock.OPEN);
level.setBlock(pos, state, 10);
level.gameEvent(player, GameEvent.BLOCK_OPEN, pos);
}
}


@SuppressWarnings("unused")
private static double manhattanDistance(Vec3 pos1, Vec3 pos2) {
Expand Down

0 comments on commit e65de34

Please sign in to comment.