use of net.minecraft.util.hit.HitResult in project wildmod by Osmiooo.
the class ChestBoatItem method use.
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack itemStack = user.getStackInHand(hand);
HitResult hitResult = raycast(world, user, RaycastContext.FluidHandling.ANY);
if (hitResult.getType() == net.minecraft.util.hit.HitResult.Type.MISS) {
return TypedActionResult.pass(itemStack);
} else {
Vec3d vec3d = user.getRotationVec(1.0F);
double d = 5.0D;
List<Entity> list = world.getOtherEntities(user, user.getBoundingBox().stretch(vec3d.multiply(5.0D)).expand(1.0D), RIDERS);
if (!list.isEmpty()) {
Vec3d vec3d2 = user.getEyePos();
Iterator var11 = list.iterator();
while (var11.hasNext()) {
Entity entity = (Entity) var11.next();
Box box = entity.getBoundingBox().expand((double) entity.getTargetingMargin());
if (box.contains(vec3d2)) {
return TypedActionResult.pass(itemStack);
}
}
}
if (hitResult.getType() == net.minecraft.util.hit.HitResult.Type.BLOCK) {
ChestBoatEntity vec3d2 = new ChestBoatEntity(world, hitResult.getPos().x, hitResult.getPos().y, hitResult.getPos().z);
vec3d2.setBoatType(this.type);
vec3d2.setYaw(user.getYaw());
if (!world.isSpaceEmpty(vec3d2, vec3d2.getBoundingBox())) {
return TypedActionResult.fail(itemStack);
} else {
if (!world.isClient) {
world.spawnEntity(vec3d2);
world.emitGameEvent(user, GameEvent.ENTITY_PLACE, new BlockPos(hitResult.getPos()));
if (!user.getAbilities().creativeMode) {
itemStack.decrement(1);
}
}
user.incrementStat(Stats.USED.getOrCreateStat(this));
return TypedActionResult.success(itemStack, world.isClient());
}
} else {
return TypedActionResult.pass(itemStack);
}
}
}
use of net.minecraft.util.hit.HitResult in project wildmod by Osmiooo.
the class MangroveBoatItem method use.
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack itemStack = user.getStackInHand(hand);
HitResult hitResult = raycast(world, user, RaycastContext.FluidHandling.ANY);
if (hitResult.getType() == net.minecraft.util.hit.HitResult.Type.MISS) {
return TypedActionResult.pass(itemStack);
} else {
Vec3d vec3d = user.getRotationVec(1.0F);
double d = 5.0D;
List<Entity> list = world.getOtherEntities(user, user.getBoundingBox().stretch(vec3d.multiply(5.0D)).expand(1.0D), RIDERS);
if (!list.isEmpty()) {
Vec3d vec3d2 = user.getEyePos();
Iterator var11 = list.iterator();
while (var11.hasNext()) {
Entity entity = (Entity) var11.next();
Box box = entity.getBoundingBox().expand((double) entity.getTargetingMargin());
if (box.contains(vec3d2)) {
return TypedActionResult.pass(itemStack);
}
}
}
if (hitResult.getType() == net.minecraft.util.hit.HitResult.Type.BLOCK) {
MangroveBoatEntity vec3d2 = new MangroveBoatEntity(world, hitResult.getPos().x, hitResult.getPos().y, hitResult.getPos().z);
vec3d2.setYaw(user.getYaw());
if (!world.isSpaceEmpty(vec3d2, vec3d2.getBoundingBox())) {
return TypedActionResult.fail(itemStack);
} else {
if (!world.isClient) {
world.spawnEntity(vec3d2);
world.emitGameEvent(user, GameEvent.ENTITY_PLACE, new BlockPos(hitResult.getPos()));
if (!user.getAbilities().creativeMode) {
itemStack.decrement(1);
}
}
user.incrementStat(Stats.USED.getOrCreateStat(this));
return TypedActionResult.success(itemStack, world.isClient());
}
} else {
return TypedActionResult.pass(itemStack);
}
}
}
use of net.minecraft.util.hit.HitResult in project KiwiClient by TangyKiwi.
the class Dupe method build.
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
HitResult hr = MinecraftClient.getInstance().crosshairTarget;
if (hr instanceof BlockHitResult) {
BlockHitResult bhr = (BlockHitResult) hr;
BlockState bs = MinecraftClient.getInstance().world.getBlockState(bhr.getBlockPos());
if (bs.getBlock() instanceof ShulkerBoxBlock) {
MinecraftClient.getInstance().interactionManager.interactBlock(MinecraftClient.getInstance().player, MinecraftClient.getInstance().world, Hand.MAIN_HAND, bhr);
preDoDupe = true;
}
} else {
Utils.mc.inGameHud.getChatHud().addMessage(new LiteralText("Please look at a shulker box"));
}
return SINGLE_SUCCESS;
});
}
use of net.minecraft.util.hit.HitResult in project Client by MatHax.
the class ClickTP method onTick.
@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.player.isUsingItem())
return;
if (mc.options.useKey.isPressed()) {
HitResult hitResult = mc.player.raycast(maxDistance.get(), 1f / 20f, false);
if (hitResult.getType() == HitResult.Type.ENTITY && mc.player.interact(((EntityHitResult) hitResult).getEntity(), Hand.MAIN_HAND) != ActionResult.PASS)
return;
if (hitResult.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) hitResult).getBlockPos();
Direction side = ((BlockHitResult) hitResult).getSide();
if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, Hand.MAIN_HAND, (BlockHitResult) hitResult) != ActionResult.PASS)
return;
BlockState state = mc.world.getBlockState(pos);
VoxelShape shape = state.getCollisionShape(mc.world, pos);
if (shape.isEmpty())
shape = state.getOutlineShape(mc.world, pos);
double height = shape.isEmpty() ? 1 : shape.getMax(Direction.Axis.Y);
mc.player.setPosition(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + height, pos.getZ() + 0.5 + side.getOffsetZ());
}
}
}
use of net.minecraft.util.hit.HitResult in project MCDungeonsWeapons by chronosacaria.
the class CombatEventHandler method checkForOffHandAttack.
public static void checkForOffHandAttack() {
MinecraftClient mc = MinecraftClient.getInstance();
PlayerEntity player = mc.player;
HitResult hitResult = mc.crosshairTarget;
if (MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().currentScreen == null && !MinecraftClient.getInstance().isPaused() && player != null && !player.isBlocking()) {
ItemStack offhand = player.getOffHandStack();
if (offhand.getItem() instanceof IOffhandAttack) {
if (hitResult instanceof EntityHitResult) {
if (mc.crosshairTarget != null && mc.interactionManager != null) {
mc.interactionManager.attackEntity(player, ((EntityHitResult) mc.crosshairTarget).getEntity());
}
}
}
}
}
Aggregations