use of net.minecraft.util.math.Direction in project MasaGadget by plusls.
the class MixinWorldUtils method fixDoEasyPlaceAction0.
// 修复 漏斗,原木放置问题
// 核心思路是修改玩家看的位置以及 side
@Inject(method = "doEasyPlaceAction", at = @At(value = "INVOKE", target = "Lfi/dy/masa/litematica/util/WorldUtils;cacheEasyPlacePosition(Lnet/minecraft/util/math/BlockPos;)V", ordinal = 0, remap = true), locals = LocalCapture.CAPTURE_FAILHARD)
private static void fixDoEasyPlaceAction0(MinecraftClient mc, CallbackInfoReturnable<ActionResult> cir, RayTraceUtils.RayTraceWrapper traceWrapper) {
if (!Configs.Litematica.FIX_ACCURATE_PROTOCOL.getBooleanValue()) {
return;
}
BlockHitResult trace = Objects.requireNonNull(traceWrapper).getBlockHitResult();
BlockPos pos = Objects.requireNonNull(trace).getBlockPos();
World world = Objects.requireNonNull(SchematicWorldHandler.getSchematicWorld());
BlockState stateSchematic = world.getBlockState(pos);
ItemStack stack = MaterialCache.getInstance().getRequiredBuildItemForState(stateSchematic);
Hand hand = EntityUtils.getUsedHandForItem(Objects.requireNonNull(mc.player), stack);
Vec3d hitPos = trace.getPos();
Direction newSide = BlockUtils.getFirstPropertyFacingValue(stateSchematic);
easyPlaceActionNewSide.set(newSide);
easyPlaceActionOldYaw.set(mc.player.getYaw());
if (newSide == null && stateSchematic.contains(Properties.AXIS)) {
// 原木之类的
newSide = Direction.from(stateSchematic.get(Properties.AXIS), Direction.AxisDirection.POSITIVE);
easyPlaceActionNewSide.set(newSide);
}
if (newSide != null && !(stateSchematic.getBlock() instanceof SlabBlock)) {
// fuck mojang
// 有时候放的东西是反向的,需要特判
mc.player.setYaw(newSide.asRotation());
ItemStack itemStack = new ItemStack(stateSchematic.getBlock().asItem());
ItemPlacementContext itemPlacementContext = new ItemPlacementContext(mc.player, hand, itemStack, new BlockHitResult(hitPos, newSide, pos, false));
BlockState testState = stateSchematic.getBlock().getPlacementState(itemPlacementContext);
if (testState != null) {
Direction testDirection = BlockUtils.getFirstPropertyFacingValue(testState);
if (testDirection != null && testDirection != newSide) {
newSide = newSide.getOpposite();
easyPlaceActionNewSide.set(newSide);
mc.player.setYaw(newSide.asRotation());
}
}
mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(mc.player.getYaw(), mc.player.getPitch(), mc.player.isOnGround()));
}
if (stateSchematic.getBlock() instanceof FenceGateBlock && stateSchematic.get(Properties.OPEN)) {
interactBlockCount.set(1);
}
}
use of net.minecraft.util.math.Direction in project MasaGadget by plusls.
the class MixinWorldUtils method preApplyCarpetProtocolHitVec.
@Inject(method = "applyCarpetProtocolHitVec", at = @At(value = "HEAD"), cancellable = true)
private static void preApplyCarpetProtocolHitVec(BlockPos pos, BlockState state, Vec3d hitVecIn, CallbackInfoReturnable<Vec3d> cir) {
if (!Configs.Litematica.FIX_ACCURATE_PROTOCOL.getBooleanValue()) {
return;
}
double x = hitVecIn.x;
double y = hitVecIn.y;
double z = hitVecIn.z;
Block block = state.getBlock();
Direction facing = fi.dy.masa.malilib.util.BlockUtils.getFirstPropertyFacingValue(state);
// 应该是 32 而不是 16
final int propertyIncrement = 32;
double relX = hitVecIn.x - pos.getX();
if (facing != null) {
x = pos.getX() + relX + 2 + (facing.getId() * 2);
}
if (block instanceof RepeaterBlock) {
// 这里也实现错了,不应该是 DELAY - 1
x += ((state.get(RepeaterBlock.DELAY))) * propertyIncrement;
} else if (block instanceof TrapdoorBlock && state.get(TrapdoorBlock.HALF) == BlockHalf.TOP) {
x += propertyIncrement;
} else if (block instanceof ComparatorBlock && state.get(ComparatorBlock.MODE) == ComparatorMode.SUBTRACT) {
x += propertyIncrement;
} else if (block instanceof StairsBlock && state.get(StairsBlock.HALF) == BlockHalf.TOP) {
x += propertyIncrement;
} else if (block instanceof SlabBlock && state.get(SlabBlock.TYPE) != SlabType.DOUBLE) {
// Do it via vanilla
if (state.get(SlabBlock.TYPE) == SlabType.TOP) {
y = pos.getY() + 0.9;
} else {
y = pos.getY();
}
}
ModInfo.LOGGER.debug("applyCarpetProtocolHitVec: {} -> {}", hitVecIn, new Vec3d(x, y, z).toString());
cir.setReturnValue(new Vec3d(x, y, z));
}
use of net.minecraft.util.math.Direction in project Blockus by Brandcraf06.
the class Barrier method method_24423.
private BlockState method_24423(WorldView worldView, BlockPos blockPos, BlockState blockState, BlockPos blockPos2, BlockState blockState2, Direction direction) {
Direction direction2 = direction.getOpposite();
boolean bl = direction == Direction.NORTH ? this.shouldConnectTo(blockState2, blockState2.isSideSolidFullSquare(worldView, blockPos2, direction2), direction2) : method_24424(blockState, NORTH_SHAPE);
boolean bl2 = direction == Direction.EAST ? this.shouldConnectTo(blockState2, blockState2.isSideSolidFullSquare(worldView, blockPos2, direction2), direction2) : method_24424(blockState, EAST_SHAPE);
boolean bl3 = direction == Direction.SOUTH ? this.shouldConnectTo(blockState2, blockState2.isSideSolidFullSquare(worldView, blockPos2, direction2), direction2) : method_24424(blockState, SOUTH_SHAPE);
boolean bl4 = direction == Direction.WEST ? this.shouldConnectTo(blockState2, blockState2.isSideSolidFullSquare(worldView, blockPos2, direction2), direction2) : method_24424(blockState, WEST_SHAPE);
BlockPos blockPos3 = blockPos.up();
BlockState blockState3 = worldView.getBlockState(blockPos3);
return this.method_24422(worldView, blockState, blockPos3, blockState3, bl, bl2, bl3, bl4);
}
use of net.minecraft.util.math.Direction in project Primeval by devs-immortal.
the class SemiSupportedBlock method supported.
protected boolean supported(World world, BlockPos pos, Random random) {
float fallPercent = 1.0f;
for (Direction sideDirection : Arrays.asList(Direction.UP, Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST)) {
if (world.getBlockState(pos.offset(sideDirection)).isSideSolidFullSquare(world, pos.offset(sideDirection), sideDirection.getOpposite())) {
fallPercent -= percentPerSide;
}
}
float rand = random.nextFloat();
return rand > fallPercent || super.supported(world, pos, random);
}
use of net.minecraft.util.math.Direction in project meteor-rejects by AntiCope.
the class AutoWither method onTick.
@EventHandler
private void onTick(TickEvent.Pre event) {
if (wither == null) {
// Delay
if (witherTicksWaited < witherDelay.get() - 1) {
return;
}
// Clear pool and list
for (Wither wither : withers) witherPool.free(wither);
withers.clear();
// Register
BlockIterator.register(horizontalRadius.get(), verticalRadius.get(), (blockPos, blockState) -> {
Direction dir = Direction.fromRotation(Rotations.getYaw(blockPos)).getOpposite();
if (isValidSpawn(blockPos, dir))
withers.add(witherPool.get().set(blockPos, dir));
});
}
}
Aggregations