Skip to content

Commit

Permalink
it works, hooray
Browse files Browse the repository at this point in the history
  • Loading branch information
RealRTTV committed Dec 1, 2024
1 parent d5bbb5a commit fdb5e7b
Showing 1 changed file with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static void setTargetVillager(@Nullable Villager villager) {

ClientLevel level = Minecraft.getInstance().level;

if (level != null && level.getDayTime() % 24000 < 12000) { // todo, double check this works
if (level != null && level.getDayTime() % 24000 < 12000) {
simulator.onBadRNG("day");
ClientCommandHelper.sendHelp(Component.translatable("commands.cvillager.help.day"));
}
Expand Down Expand Up @@ -257,41 +257,38 @@ private static void checkVillagerSetup() {
simulator.onBadRNG("itemInMainHand");
} else {
Level level = targetVillager.level();
Vec3 pos = targetVillager.position();
BlockPos blockPos = targetVillager.blockPosition();

{
Vec3 pos = targetVillager.position();
int villagersNearVillager = level.getEntities(EntityTypeTest.forExactClass(Villager.class), AABB.ofSize(pos, 10.0, 10.0, 10.0), entity -> entity.position().distanceToSqr(pos) <= 5.0 * 5.0).size();
if (villagersNearVillager > 1) {
simulator.onBadRNG("gossip");
return;
}
int villagersNearVillager = level.getEntities(EntityTypeTest.forExactClass(Villager.class), AABB.ofSize(pos, 10.0, 10.0, 10.0), entity -> entity.position().distanceToSqr(pos) <= 5.0 * 5.0).size();
if (villagersNearVillager > 1) {
simulator.onBadRNG("gossip");
return;
}

{
BlockPos pos = targetVillager.blockPosition();
List<BlockPos> validBedHeadPositions = List.of(pos.north(3), pos.east(3), pos.south(3), pos.west(3));
List<BlockPos> bedPartPositions = BlockPos.withinManhattanStream(pos, 15, 7, 15).map(BlockPos::new).filter(p -> level.getBlockState(p).is(BlockTags.BEDS) && level.getBlockState(p).getValue(BedBlock.OCCUPIED) == Boolean.FALSE && level.getBlockState(p).getValue(BedBlock.PART) == BedPart.HEAD).toList();
Direction bedDirection;
if (bedPartPositions.size() == 1 && validBedHeadPositions.contains(bedPartPositions.getFirst())) {
bedDirection = Direction.Plane.HORIZONTAL.stream().skip(validBedHeadPositions.indexOf(bedPartPositions.getFirst())).findAny().orElse(null);
} else {
simulator.onBadRNG("invalidBedPosition");
List<BlockPos> validBedHeadPositions = List.of(blockPos.north(3), blockPos.east(3), blockPos.south(3), blockPos.west(3));
List<BlockPos> bedHeadPositions = BlockPos.withinManhattanStream(blockPos, 15, 7, 15).map(BlockPos::new).filter(p -> level.getBlockState(p).is(BlockTags.BEDS) && level.getBlockState(p).getValue(BedBlock.OCCUPIED) == Boolean.FALSE && level.getBlockState(p).getValue(BedBlock.PART) == BedPart.HEAD).toList();
Direction bedDirection;
if (bedHeadPositions.size() == 1 && validBedHeadPositions.contains(bedHeadPositions.getFirst())) {
bedDirection = Direction.Plane.HORIZONTAL.stream().skip(validBedHeadPositions.indexOf(bedHeadPositions.getFirst())).findAny().orElse(null);
} else {
simulator.onBadRNG("invalidBedPosition");
sendInvalidSetupHelp();
return;
}

for (Direction direction : Direction.Plane.HORIZONTAL) {
BlockPos airPos = blockPos.relative(direction);
BlockPos trapdoorPos = airPos.above();
BlockState airPosState = level.getBlockState(airPos);
BlockState trapdoorPosState = level.getBlockState(trapdoorPos);
if (!((airPosState.isAir() || direction != bedDirection) && trapdoorPosState.is(BlockTags.TRAPDOORS) && trapdoorPosState.getValue(TrapDoorBlock.HALF) == Half.TOP && trapdoorPosState.getValue(TrapDoorBlock.HALF) == Half.TOP && trapdoorPosState.getValue(TrapDoorBlock.OPEN) == Boolean.FALSE)) {
simulator.onBadRNG("invalidCage");
sendInvalidSetupHelp();
return;
}

for (Direction direction : Direction.Plane.HORIZONTAL) {
BlockPos airPos = pos.relative(direction);
BlockPos trapdoorPos = airPos.above();
BlockState airPosState = level.getBlockState(airPos);
BlockState trapdoorPosState = level.getBlockState(trapdoorPos);
if (!((airPosState.isAir() || direction != bedDirection) && trapdoorPosState.is(BlockTags.TRAPDOORS) && trapdoorPosState.getValue(TrapDoorBlock.HALF) == Half.TOP && trapdoorPosState.getValue(TrapDoorBlock.HALF) == Half.TOP && trapdoorPosState.getValue(TrapDoorBlock.OPEN) == Boolean.FALSE)) {
simulator.onBadRNG("invalidCage");
sendInvalidSetupHelp();
return;
}
}
}

}
}

Expand Down

0 comments on commit fdb5e7b

Please sign in to comment.