use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.
the class SchematicToolBase method updateTargetPos.
public void updateTargetPos() {
LocalPlayer player = Minecraft.getInstance().player;
// Select Blueprint
if (schematicHandler.isDeployed()) {
SchematicTransformation transformation = schematicHandler.getTransformation();
AABB localBounds = schematicHandler.getBounds();
Vec3 traceOrigin = RaycastHelper.getTraceOrigin(player);
Vec3 start = transformation.toLocalSpace(traceOrigin);
Vec3 end = transformation.toLocalSpace(RaycastHelper.getTraceTarget(player, 70, traceOrigin));
PredicateTraceResult result = RaycastHelper.rayTraceUntil(start, end, pos -> localBounds.contains(VecHelper.getCenterOf(pos)));
schematicSelected = !result.missed();
selectedFace = schematicSelected ? result.getFacing() : null;
}
boolean snap = this.selectedPos == null;
// Select location at distance
if (selectIgnoreBlocks) {
float pt = AnimationTickHolder.getPartialTicks();
selectedPos = new BlockPos(player.getEyePosition(pt).add(player.getLookAngle().scale(selectionRange)));
if (snap)
lastChasingSelectedPos = chasingSelectedPos = Vec3.atLowerCornerOf(selectedPos);
return;
}
// Select targeted Block
selectedPos = null;
BlockHitResult trace = RaycastHelper.rayTraceRange(player.level, player, 75);
if (trace == null || trace.getType() != Type.BLOCK)
return;
BlockPos hit = new BlockPos(trace.getLocation());
boolean replaceable = player.level.getBlockState(hit).getMaterial().isReplaceable();
if (trace.getDirection().getAxis().isVertical() && !replaceable)
hit = hit.relative(trace.getDirection());
selectedPos = hit;
if (snap)
lastChasingSelectedPos = chasingSelectedPos = Vec3.atLowerCornerOf(selectedPos);
}
use of net.minecraft.world.phys.BlockHitResult in project fabric-carpet by gnembon.
the class ServerGamePacketListenerImpl_scarpetEventsMixin method onBlockInteracted.
@Inject(method = "handleUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayerGameMode;useItemOn(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;"))
private void onBlockInteracted(ServerboundUseItemOnPacket playerInteractBlockC2SPacket_1, CallbackInfo ci) {
if (PLAYER_RIGHT_CLICKS_BLOCK.isNeeded()) {
InteractionHand hand = playerInteractBlockC2SPacket_1.getHand();
BlockHitResult hitRes = playerInteractBlockC2SPacket_1.getHitResult();
PLAYER_RIGHT_CLICKS_BLOCK.onBlockHit(player, hand, hitRes);
}
}
use of net.minecraft.world.phys.BlockHitResult in project RayTraceAntiXray by stonar96.
the class RayTraceAntiXray method getMaxZoom.
private double getMaxZoom(Entity entity, Location location, Vector direction, double maxZoom) {
Vec3 position = new Vec3(location.getX(), location.getY(), location.getZ());
for (int i = 0; i < 8; i++) {
float edgeX = (float) ((i & 1) * 2 - 1);
float edgeY = (float) ((i >> 1 & 1) * 2 - 1);
float edgeZ = (float) ((i >> 2 & 1) * 2 - 1);
edgeX = edgeX * 0.1f;
edgeY = edgeY * 0.1f;
edgeZ = edgeZ * 0.1f;
Vec3 edge = position.add(edgeX, edgeY, edgeZ);
Vec3 edgeMoved = new Vec3(position.x - direction.getX() * maxZoom + (double) edgeX + (double) edgeZ, position.y - direction.getY() * maxZoom + (double) edgeY, position.z - direction.getZ() * maxZoom + (double) edgeZ);
BlockHitResult result = ((CraftWorld) location.getWorld()).getHandle().clip(new ClipContext(edge, edgeMoved, ClipContext.Block.VISUAL, ClipContext.Fluid.NONE, ((CraftEntity) entity).getHandle()));
if (result.getType() != HitResult.Type.MISS) {
double zoom = result.getLocation().distanceTo(position);
if (zoom < maxZoom) {
maxZoom = zoom;
}
}
}
return maxZoom;
}
use of net.minecraft.world.phys.BlockHitResult in project Mohist by MohistMC.
the class CraftRayTraceResult method fromNMS.
public static RayTraceResult fromNMS(World world, HitResult nmsHitResult) {
if (nmsHitResult == null || nmsHitResult.getType() == Type.MISS)
return null;
Vec3 nmsHitPos = nmsHitResult.getLocation();
Vector hitPosition = new Vector(nmsHitPos.x, nmsHitPos.y, nmsHitPos.z);
BlockFace hitBlockFace = null;
if (nmsHitResult.getType() == Type.ENTITY) {
Entity hitEntity = ((EntityHitResult) nmsHitResult).getEntity().getBukkitEntity();
return new RayTraceResult(hitPosition, hitEntity, null);
}
Block hitBlock = null;
BlockPos nmsBlockPos = null;
if (nmsHitResult.getType() == Type.BLOCK) {
BlockHitResult blockHitResult = (BlockHitResult) nmsHitResult;
hitBlockFace = CraftBlock.notchToBlockFace(blockHitResult.getDirection());
nmsBlockPos = blockHitResult.getBlockPos();
}
if (nmsBlockPos != null && world != null) {
hitBlock = world.getBlockAt(nmsBlockPos.getX(), nmsBlockPos.getY(), nmsBlockPos.getZ());
}
return new RayTraceResult(hitPosition, hitBlock, hitBlockFace);
}
use of net.minecraft.world.phys.BlockHitResult in project AkashicTome by VazkiiMods.
the class HUDHandler method onDrawScreen.
@SubscribeEvent
public void onDrawScreen(RenderGameOverlayEvent.Post event) {
if (event.getType() != ElementType.ALL)
return;
Minecraft mc = Minecraft.getInstance();
HitResult pos = mc.hitResult;
Window res = event.getWindow();
if (pos != null && pos instanceof BlockHitResult) {
BlockHitResult bpos = (BlockHitResult) pos;
ItemStack tomeStack = mc.player.getMainHandItem();
boolean hasTome = !tomeStack.isEmpty() && tomeStack.getItem() == ModItems.tome;
if (!hasTome) {
tomeStack = mc.player.getOffhandItem();
hasTome = !tomeStack.isEmpty() && tomeStack.getItem() == ModItems.tome;
}
if (!hasTome)
return;
tomeStack = tomeStack.copy();
BlockState state = mc.level.getBlockState(bpos.getBlockPos());
if (!state.isAir()) {
ItemStack drawStack = ItemStack.EMPTY;
String line1 = "";
String line2 = "";
String mod = MorphingHandler.getModFromState(state);
ItemStack morphStack = MorphingHandler.getShiftStackForMod(tomeStack, mod);
if (!morphStack.isEmpty() && !ItemStack.isSame(morphStack, tomeStack)) {
drawStack = morphStack;
line1 = ItemNBTHelper.getCompound(morphStack, MorphingHandler.TAG_TOME_DISPLAY_NAME, false).getString("text");
line2 = ChatFormatting.GRAY + I18n.get("akashictome.click_morph");
}
if (!drawStack.isEmpty()) {
RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
int sx = res.getGuiScaledWidth() / 2 - 17;
int sy = res.getGuiScaledHeight() / 2 + 2;
mc.getItemRenderer().renderGuiItem(drawStack, sx, sy);
mc.font.drawShadow(event.getMatrixStack(), line1, sx + 20, sy + 4, 0xFFFFFFFF);
mc.font.drawShadow(event.getMatrixStack(), line2, sx + 25, sy + 14, 0xFFFFFFFF);
}
}
}
}
Aggregations