use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.
the class LinkRenderer method tick.
public static void tick() {
Minecraft mc = Minecraft.getInstance();
HitResult target = mc.hitResult;
if (target == null || !(target instanceof BlockHitResult))
return;
BlockHitResult result = (BlockHitResult) target;
ClientLevel world = mc.level;
BlockPos pos = result.getBlockPos();
LinkBehaviour behaviour = TileEntityBehaviour.get(world, pos, LinkBehaviour.TYPE);
if (behaviour == null)
return;
Component freq1 = Lang.translate("logistics.firstFrequency");
Component freq2 = Lang.translate("logistics.secondFrequency");
for (boolean first : Iterate.trueAndFalse) {
AABB bb = new AABB(Vec3.ZERO, Vec3.ZERO).inflate(.25f);
Component label = first ? freq1 : freq2;
boolean hit = behaviour.testHit(first, target.getLocation());
ValueBoxTransform transform = first ? behaviour.firstSlot : behaviour.secondSlot;
ValueBox box = new ValueBox(label, bb, pos).withColors(0x601F18, 0xB73C2D).offsetLabel(behaviour.textShift).passive(!hit);
CreateClient.OUTLINER.showValueBox(Pair.of(Boolean.valueOf(first), pos), box.transform(transform)).lineWidth(1 / 64f).withFaceTexture(hit ? AllSpecialTextures.THIN_CHECKERED : null).highlightFace(result.getDirection());
}
}
use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.
the class ItemUseOverrides method onBlockActivated.
@SubscribeEvent
public static void onBlockActivated(PlayerInteractEvent.RightClickBlock event) {
if (AllItems.WRENCH.isIn(event.getItemStack()))
return;
BlockState state = event.getWorld().getBlockState(event.getPos());
ResourceLocation id = state.getBlock().getRegistryName();
if (!OVERRIDES.contains(id))
return;
BlockHitResult blockTrace = new BlockHitResult(VecHelper.getCenterOf(event.getPos()), event.getFace(), event.getPos(), true);
InteractionResult result = state.use(event.getWorld(), event.getPlayer(), event.getHand(), blockTrace);
if (!result.consumesAction())
return;
event.setCanceled(true);
event.setCancellationResult(result);
}
use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.
the class ScrollValueHandler method onScroll.
@OnlyIn(Dist.CLIENT)
public static boolean onScroll(double delta) {
Minecraft mc = Minecraft.getInstance();
HitResult objectMouseOver = mc.hitResult;
if (!(objectMouseOver instanceof BlockHitResult))
return false;
BlockHitResult result = (BlockHitResult) objectMouseOver;
ClientLevel world = mc.level;
BlockPos blockPos = result.getBlockPos();
ScrollValueBehaviour scrolling = TileEntityBehaviour.get(world, blockPos, ScrollValueBehaviour.TYPE);
if (scrolling == null)
return false;
if (!scrolling.isActive())
return false;
if (!mc.player.mayBuild())
return false;
if (scrolling.needsWrench && !AllItems.WRENCH.isIn(mc.player.getMainHandItem()))
return false;
passiveScrollDirection = (float) -delta;
wrenchCog.bump(3, -delta * 10);
int prev = scrolling.scrollableValue;
if (scrolling.slotPositioning instanceof Sided)
((Sided) scrolling.slotPositioning).fromSide(result.getDirection());
if (!scrolling.testHit(objectMouseOver.getLocation()))
return false;
if (scrolling instanceof BulkScrollValueBehaviour && AllKeys.ctrlDown()) {
BulkScrollValueBehaviour bulkScrolling = (BulkScrollValueBehaviour) scrolling;
for (SmartTileEntity te : bulkScrolling.getBulk()) {
ScrollValueBehaviour other = te.getBehaviour(ScrollValueBehaviour.TYPE);
if (other != null)
applyTo(delta, other);
}
} else
applyTo(delta, scrolling);
if (prev != scrolling.scrollableValue) {
float pitch = (scrolling.scrollableValue - scrolling.min) / (float) (scrolling.max - scrolling.min);
pitch = Mth.lerp(pitch, 1.5f, 2f);
AllSoundEvents.SCROLL_VALUE.play(world, mc.player, blockPos, 1, pitch);
}
return true;
}
use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.
the class BeltConnectorHandler method tick.
public static void tick() {
Player player = Minecraft.getInstance().player;
Level world = Minecraft.getInstance().level;
if (player == null || world == null)
return;
if (Minecraft.getInstance().screen != null)
return;
for (InteractionHand hand : InteractionHand.values()) {
ItemStack heldItem = player.getItemInHand(hand);
if (!AllItems.BELT_CONNECTOR.isIn(heldItem))
continue;
if (!heldItem.hasTag())
continue;
CompoundTag tag = heldItem.getTag();
if (!tag.contains("FirstPulley"))
continue;
BlockPos first = NbtUtils.readBlockPos(tag.getCompound("FirstPulley"));
if (!world.getBlockState(first).hasProperty(BlockStateProperties.AXIS))
continue;
Axis axis = world.getBlockState(first).getValue(BlockStateProperties.AXIS);
HitResult rayTrace = Minecraft.getInstance().hitResult;
if (rayTrace == null || !(rayTrace instanceof BlockHitResult)) {
if (r.nextInt(50) == 0) {
world.addParticle(new DustParticleOptions(new Vector3f(.3f, .9f, .5f), 1), first.getX() + .5f + randomOffset(.25f), first.getY() + .5f + randomOffset(.25f), first.getZ() + .5f + randomOffset(.25f), 0, 0, 0);
}
return;
}
BlockPos selected = ((BlockHitResult) rayTrace).getBlockPos();
if (world.getBlockState(selected).getMaterial().isReplaceable())
return;
if (!ShaftBlock.isShaft(world.getBlockState(selected)))
selected = selected.relative(((BlockHitResult) rayTrace).getDirection());
if (!selected.closerThan(first, AllConfigs.SERVER.kinetics.maxBeltLength.get()))
return;
boolean canConnect = BeltConnectorItem.validateAxis(world, selected) && BeltConnectorItem.canConnect(world, first, selected);
Vec3 start = Vec3.atLowerCornerOf(first);
Vec3 end = Vec3.atLowerCornerOf(selected);
Vec3 actualDiff = end.subtract(start);
end = end.subtract(axis.choose(actualDiff.x, 0, 0), axis.choose(0, actualDiff.y, 0), axis.choose(0, 0, actualDiff.z));
Vec3 diff = end.subtract(start);
double x = Math.abs(diff.x);
double y = Math.abs(diff.y);
double z = Math.abs(diff.z);
float length = (float) Math.max(x, Math.max(y, z));
Vec3 step = diff.normalize();
int sames = ((x == y) ? 1 : 0) + ((y == z) ? 1 : 0) + ((z == x) ? 1 : 0);
if (sames == 0) {
List<Vec3> validDiffs = new LinkedList<>();
for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) for (int k = -1; k <= 1; k++) {
if (axis.choose(i, j, k) != 0)
continue;
if (axis == Axis.Y && i != 0 && k != 0)
continue;
if (i == 0 && j == 0 && k == 0)
continue;
validDiffs.add(new Vec3(i, j, k));
}
int closestIndex = 0;
float closest = Float.MAX_VALUE;
for (Vec3 validDiff : validDiffs) {
double distanceTo = step.distanceTo(validDiff);
if (distanceTo < closest) {
closest = (float) distanceTo;
closestIndex = validDiffs.indexOf(validDiff);
}
}
step = validDiffs.get(closestIndex);
}
if (axis == Axis.Y && step.x != 0 && step.z != 0)
return;
step = new Vec3(Math.signum(step.x), Math.signum(step.y), Math.signum(step.z));
for (float f = 0; f < length; f += .0625f) {
Vec3 position = start.add(step.scale(f));
if (r.nextInt(10) == 0) {
world.addParticle(new DustParticleOptions(new Vector3f(canConnect ? .3f : .9f, canConnect ? .9f : .3f, .5f), 1), position.x + .5f, position.y + .5f, position.z + .5f, 0, 0, 0);
}
}
return;
}
}
use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.
the class SchematicHandler method onMouseInput.
public void onMouseInput(int button, boolean pressed) {
if (!active)
return;
if (!pressed || button != 1)
return;
Minecraft mc = Minecraft.getInstance();
if (mc.player.isShiftKeyDown())
return;
if (mc.hitResult instanceof BlockHitResult) {
BlockHitResult blockRayTraceResult = (BlockHitResult) mc.hitResult;
BlockState clickedBlock = mc.level.getBlockState(blockRayTraceResult.getBlockPos());
if (AllBlocks.SCHEMATICANNON.has(clickedBlock))
return;
if (AllBlocks.DEPLOYER.has(clickedBlock))
return;
}
currentTool.getTool().handleRightClick();
}
Aggregations