use of net.minecraft.util.hit.HitResult 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.HitResult 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));
}
use of net.minecraft.util.hit.HitResult in project FallingAttackFabric by hamusuke0323.
the class FallingAttackShockWave method getEntitiesStruckByShockWave.
public List<LivingEntity> getEntitiesStruckByShockWave() {
return this.world.getEntitiesByClass(LivingEntity.class, this.box, livingEntity -> {
double d = distanceTo2D(livingEntity.getPos(), this.pos);
boolean flag = !this.exceptEntities.contains(livingEntity) && !livingEntity.isSpectator() && livingEntity != this.owner && d >= this.secondary.getRadius() && this.primary.getRadius() >= d;
for (int i = 0; i < 2 && flag; i++) {
Vec3d vec3d = new Vec3d(livingEntity.getX(), livingEntity.getBodyY(0.5D * (double) i), livingEntity.getZ());
HitResult hitResult = this.world.raycast(new RaycastContext(this.pos, vec3d, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, this.owner));
if (hitResult.getType() == HitResult.Type.MISS) {
return true;
}
}
return false;
});
}
use of net.minecraft.util.hit.HitResult in project CustomHUD by Minenash.
the class ComplexData method update.
@SuppressWarnings("ConstantConditions")
public static void update(Profile profile) {
if (profile.enabled.serverWorld) {
IntegratedServer integratedServer = client.getServer();
serverWorld = integratedServer != null ? integratedServer.getWorld(client.world.getRegistryKey()) : null;
}
if (profile.enabled.clientChunk) {
ChunkPos newPos = new ChunkPos(client.getCameraEntity().getBlockPos());
if (!Objects.equals(ComplexData.pos, newPos)) {
pos = newPos;
chunkFuture = null;
clientChunk = null;
}
if (clientChunk == null)
clientChunk = client.world.getChunk(pos.x, pos.z);
}
if (profile.enabled.serverChunk) {
if (chunkFuture == null) {
if (serverWorld != null)
chunkFuture = serverWorld.getChunkManager().getChunkFutureSyncOnMainThread(pos.x, pos.z, ChunkStatus.FULL, false).thenApply((either) -> either.map((chunk) -> (WorldChunk) chunk, (unloaded) -> null));
if (chunkFuture == null)
chunkFuture = CompletableFuture.completedFuture(clientChunk);
}
serverChunk = chunkFuture.getNow(null);
}
if (profile.enabled.targetBlock) {
HitResult hit = client.cameraEntity.raycast(profile.targetDistance, 0.0F, false);
targetBlockPos = hit.getType() == HitResult.Type.BLOCK ? ((BlockHitResult) hit).getBlockPos() : null;
}
if (profile.enabled.world)
world = DataFixUtils.orElse(Optional.ofNullable(client.getServer()).flatMap((integratedServer) -> Optional.ofNullable(integratedServer.getWorld(client.world.getRegistryKey()))), client.world);
if (profile.enabled.localDifficulty)
localDifficulty = new LocalDifficulty(world.getDifficulty(), world.getTimeOfDay(), serverChunk == null ? 0 : serverChunk.getInhabitedTime(), world.getMoonSize());
if (profile.enabled.sound)
sounds = client.getSoundManager().getDebugString().substring(8).replace(" + ", "/").split("/");
if (profile.enabled.clientChunkCache)
clientChunkCache = client.worldRenderer.getChunksDebugString().substring(20).split(", ");
if (profile.enabled.time) {
timeOfDay = (int) ((client.world.getTimeOfDay() + 6000) % 24000);
}
if (profile.enabled.velocity) {
if (velocityWaitCounter > 0) {
velocityWaitCounter--;
return;
}
velocityWaitCounter = 4;
ClientPlayerEntity p = client.player;
final double changeXZ = Math.sqrt(Math.pow(Math.abs(p.getX() - x1), 2) + Math.pow(Math.abs(p.getZ() - z1), 2));
final double changeY = Math.abs(p.getY() - y1);
final double changeXYZ = Math.sqrt(changeXZ * changeXZ + changeY * changeY);
x1 = p.getX();
y1 = p.getY();
z1 = p.getZ();
velocityXZ = ((int) (changeXZ * 40)) / 10.0;
velocityY = ((int) (changeY * 40)) / 10.0;
velocityXYZ = ((int) (changeXYZ * 40)) / 10.0;
}
}
use of net.minecraft.util.hit.HitResult in project BleachHack by BleachDrinker420.
the class CmdNBT method getNbt.
private NbtCompound getNbt(String arg) {
if (arg.equalsIgnoreCase("hand")) {
return mc.player.getMainHandStack().getOrCreateNbt();
} else if (arg.equalsIgnoreCase("block")) {
HitResult target = mc.crosshairTarget;
if (target.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) target).getBlockPos();
BlockEntity be = mc.world.getBlockEntity(pos);
if (be != null) {
return be.writeNbt(new NbtCompound());
} else {
return new NbtCompound();
}
}
BleachLogger.error("Not looking at a block.");
return null;
} else if (arg.equalsIgnoreCase("entity")) {
HitResult target = mc.crosshairTarget;
if (target.getType() == HitResult.Type.ENTITY) {
return ((EntityHitResult) target).getEntity().writeNbt(new NbtCompound());
}
BleachLogger.error("Not looking at an entity.");
return null;
}
throw new CmdSyntaxException();
}
Aggregations