use of net.minecraft.util.hit.BlockHitResult in project fabric by FabricMC.
the class PickBlockEventModClient method onInitializeClient.
@Override
public void onInitializeClient() {
ClientPickBlockGatherCallback.EVENT.register((player, result) -> {
if (result instanceof BlockHitResult) {
BlockView view = player.getEntityWorld();
BlockPos pos = ((BlockHitResult) result).getBlockPos();
BlockState state = view.getBlockState(pos);
if (state.getBlock() == Blocks.STONE) {
return new ItemStack(Blocks.OAK_WOOD);
}
}
return ItemStack.EMPTY;
});
ClientPickBlockApplyCallback.EVENT.register((player, result, stack) -> {
if (stack.getItem() == Item.getItemFromBlock(Blocks.OAK_WOOD)) {
return new ItemStack(Blocks.ACACIA_WOOD);
} else {
return stack;
}
});
}
use of net.minecraft.util.hit.BlockHitResult in project KahzerxMod by otakucraft.
the class GuiPlayer method tick.
public void tick() {
if (isOpen && shouldClose()) {
closePanel();
}
if (scrolled > 0) {
scrolled--;
}
if (isOpen) {
if (gui != null && gui.shouldRender(this)) {
gui.render(this);
gui.setReRender(false);
}
BlockHitResult hit = Box.raycast(List.of(panelBox), player.getCameraPosVec(1f), player.getCameraPosVec(1f).add(player.getRotationVec(1f).multiply(20)), new BlockPos(0, 0, 0));
int newX;
int newY;
if (hit != null && hit.getSide() == panelFacingSide) {
double dx = panelCorner1.getX() - hit.getPos().getX();
double dy = panelCorner1.getY() - hit.getPos().getY() + 1;
double dz = panelCorner1.getZ() - hit.getPos().getZ();
if (panelFacingSide != Direction.NORTH) {
dx = -dx;
} else {
dx += 1;
}
if (panelFacingSide != Direction.EAST) {
dz = -dz;
} else {
dz += 1;
}
newX = (int) ((panelFacingSide.getAxis() == Direction.Axis.Z ? dx : dz) * MapGui.MAP_WIDTH);
newY = (int) (dy * MapGui.MAP_HEIGHT);
if (newX != oldX || newY != oldY) {
onMouseChange(newX, newY, oldX, oldY);
oldX = newX;
oldY = newY;
}
for (int i = 0; i < panelSize; i++) {
MapGui g = maps.get(i);
if (g.shouldUpdate()) {
g.sendData();
}
}
}
}
}
use of net.minecraft.util.hit.BlockHitResult in project orion by AntiCope.
the class AutoBedCraft method openCraftingTable.
private void openCraftingTable(BlockPos tablePos) {
Vec3d tableVec = new Vec3d(tablePos.getX(), tablePos.getY(), tablePos.getZ());
BlockHitResult table = new BlockHitResult(tableVec, Direction.UP, tablePos, false);
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, table);
}
use of net.minecraft.util.hit.BlockHitResult in project orion by AntiCope.
the class AutoCityPlus method getDirection.
private Direction getDirection(BlockPos pos) {
// stolen from supakeks ez
Vec3d eyesPos = new Vec3d(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
for (Direction direction : Direction.values()) {
RaycastContext raycastContext = new RaycastContext(eyesPos, new Vec3d(pos.getX() + 0.5 + direction.getVector().getX() * 0.5, pos.getY() + 0.5 + direction.getVector().getY() * 0.5, pos.getZ() + 0.5 + direction.getVector().getZ() * 0.5), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
BlockHitResult result = mc.world.raycast(raycastContext);
if (result != null && result.getType() == HitResult.Type.BLOCK && result.getBlockPos().equals(pos)) {
return direction;
}
}
if ((double) pos.getY() > eyesPos.y) {
// The player can never see the top of a block if they are under it
return Direction.DOWN;
}
return Direction.UP;
}
use of net.minecraft.util.hit.BlockHitResult in project wildmod by Osmiooo.
the class FrogSpawnItem method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
BlockHitResult blockHitResult = FrogSpawnItem.raycast(world, user, RaycastContext.FluidHandling.SOURCE_ONLY);
BlockHitResult blockHitResult2 = blockHitResult.withBlockPos(blockHitResult.getBlockPos().up());
ActionResult actionResult = super.useOnBlock(new ItemUsageContext(user, hand, blockHitResult2));
return new TypedActionResult<ItemStack>(actionResult, user.getStackInHand(hand));
}
Aggregations