use of net.minecraft.util.hit.BlockHitResult 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.hit.BlockHitResult in project MasaGadget by plusls.
the class MixinWorldUtils method checkInventory.
@Inject(method = "handleEasyPlace", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/util/InfoUtils;showGuiOrInGameMessage(Lfi/dy/masa/malilib/gui/Message$MessageType;Ljava/lang/String;[Ljava/lang/Object;)V", ordinal = 0), cancellable = true)
private static void checkInventory(MinecraftClient mc, CallbackInfoReturnable<Boolean> cir) {
if (!Configs.Litematica.BETTER_EASY_PLACE_MODE.getBooleanValue() || mc.world == null) {
return;
}
HitResult trace = mc.crosshairTarget;
if (trace != null && trace.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockHitResult = (BlockHitResult) trace;
BlockPos pos = blockHitResult.getBlockPos();
Block block = mc.world.getBlockState(pos).getBlock();
if (block == Blocks.BEACON || mc.world.getBlockEntity(pos) instanceof Inventory) {
cir.setReturnValue(false);
}
}
}
use of net.minecraft.util.hit.BlockHitResult in project meteor-rejects by AntiCope.
the class Confuse method onTick.
@EventHandler
private void onTick(TickEvent.Pre event) {
// Delay
delayWaited++;
if (delayWaited < delay.get())
return;
delayWaited = 0;
// Targetting
target = TargetUtils.getPlayerTarget(range.get(), priority.get());
if (target == null)
return;
Vec3d entityPos = target.getPos();
Vec3d playerPos = mc.player.getPos();
Random r = new Random();
BlockHitResult hit;
int halfRange = range.get() / 2;
switch(mode.get()) {
case RandomTP:
double x = r.nextDouble() * range.get() - halfRange;
double y = 0;
double z = r.nextDouble() * range.get() - halfRange;
Vec3d addend = new Vec3d(x, y, z);
Vec3d goal = entityPos.add(addend);
if (mc.world.getBlockState(new BlockPos(goal.x, goal.y, goal.z)).getBlock() != Blocks.AIR) {
goal = new Vec3d(x, playerPos.y, z);
}
if (mc.world.getBlockState(new BlockPos(goal.x, goal.y, goal.z)).getBlock() == Blocks.AIR) {
hit = mc.world.raycast(new RaycastContext(mc.player.getPos(), goal, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
if (!moveThroughBlocks.get() && hit.isInsideBlock()) {
delayWaited = (int) (delay.get() - 1);
break;
}
mc.player.updatePosition(goal.x, goal.y, goal.z);
} else {
delayWaited = (int) (delay.get() - 1);
}
break;
case Switch:
Vec3d diff = entityPos.subtract(playerPos);
Vec3d diff1 = new Vec3d(Utils.clamp(diff.x, -halfRange, halfRange), Utils.clamp(diff.y, -halfRange, halfRange), Utils.clamp(diff.z, -halfRange, halfRange));
Vec3d goal2 = entityPos.add(diff1);
hit = mc.world.raycast(new RaycastContext(mc.player.getPos(), goal2, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
if (!moveThroughBlocks.get() && hit.isInsideBlock()) {
delayWaited = (int) (delay.get() - 1);
break;
}
mc.player.updatePosition(goal2.x, goal2.y, goal2.z);
break;
case Circle:
delay.set(0);
circleProgress += circleSpeed.get();
if (circleProgress > 360)
circleProgress -= 360;
double rad = Math.toRadians(circleProgress);
double sin = Math.sin(rad) * 3;
double cos = Math.cos(rad) * 3;
Vec3d current = new Vec3d(entityPos.x + sin, playerPos.y, entityPos.z + cos);
hit = mc.world.raycast(new RaycastContext(mc.player.getPos(), current, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
if (!moveThroughBlocks.get() && hit.isInsideBlock())
break;
mc.player.updatePosition(current.x, current.y, current.z);
break;
}
}
use of net.minecraft.util.hit.BlockHitResult in project meteor-rejects by AntiCope.
the class AutoTNT method ignite.
private void ignite(BlockPos pos, FindItemResult item) {
InvUtils.swap(item.slot(), true);
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
InvUtils.swapBack();
}
use of net.minecraft.util.hit.BlockHitResult in project BlockMeter by ModProg.
the class BlockMeterClient method onInitializeClient.
@Override
public void onInitializeClient() {
final KeyBinding keyBinding = new KeyBinding("key.blockmeter.assign", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_M, "category.blockmeter.key");
final KeyBinding keyBindingMenu = new KeyBinding("key.blockmeter.menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_ALT, "category.blockmeter.key");
KeyBindingHelper.registerKeyBinding(keyBinding);
KeyBindingHelper.registerKeyBinding(keyBindingMenu);
// This is ugly I know, but I did not find something better
// (Issue in AutoConfig https://github.com/shedaniel/AutoConfig/issues/13)
confMgr = (ConfigManager<ModConfig>) AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
ClientTickEvents.START_CLIENT_TICK.register(e -> {
if (keyBinding.wasPressed()) {
if (Screen.hasShiftDown()) {
if (undo())
e.player.sendMessage(new TranslatableText("blockmeter.clearLast"), true);
} else if (Screen.hasControlDown()) {
if (clear())
e.player.sendMessage(new TranslatableText("blockmeter.clearAll"), true);
} else if (this.active) {
disable();
e.player.sendMessage(new TranslatableText("blockmeter.toggle.off", new Object[0]), true);
} else {
active = true;
ItemStack itemStack = e.player.getMainHandStack();
currentItem = itemStack.getItem();
e.player.sendMessage(new TranslatableText("blockmeter.toggle.on", new Object[] { new TranslatableText(itemStack.getTranslationKey(), new Object[0]) }), true);
}
}
if (keyBindingMenu.wasPressed() && active && MinecraftClient.getInstance().player.getMainHandStack().getItem() == this.currentItem) {
MinecraftClient.getInstance().setScreen((Screen) this.quickMenu);
}
// Updates Selection preview
if (this.active && this.boxes.size() > 0) {
final ClientMeasureBox currentBox = getCurrentBox();
if (currentBox != null) {
final HitResult rayHit = e.player.raycast((double) e.interactionManager.getReachDistance(), 1.0f, false);
if (rayHit.getType() == HitResult.Type.BLOCK) {
final BlockHitResult blockHitResult = (BlockHitResult) rayHit;
currentBox.setBlockEnd(new BlockPos(blockHitResult.getBlockPos()));
}
}
}
});
UseBlockCallback.EVENT.register((playerEntity, world, hand, hitResult) -> this.onBlockMeterClick(playerEntity, hitResult));
}
Aggregations