use of net.minecraft.world.phys.BlockHitResult in project refinedstorage by refinedmods.
the class ConstructorNetworkNode method extractAndPlaceBlock.
private void extractAndPlaceBlock(ItemStack stack) {
ItemStack took = network.extractItem(stack, 1, compare, Action.SIMULATE);
if (!took.isEmpty()) {
BlockPlaceContext ctx = new ConstructorBlockItemUseContext(level, LevelUtils.getFakePlayer((ServerLevel) level, getOwner()), InteractionHand.MAIN_HAND, took, new BlockHitResult(Vec3.ZERO, getDirection(), pos, false));
InteractionResult result = ForgeHooks.onPlaceItemIntoWorld(ctx);
if (result.consumesAction()) {
network.extractItem(stack, 1, Action.PERFORM);
}
} else if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
ItemStack craft = itemFilters.getStackInSlot(0);
network.getCraftingManager().request(this, craft, 1);
}
}
use of net.minecraft.world.phys.BlockHitResult in project refinedstorage by refinedmods.
the class DestructorNetworkNode method breakBlock.
private void breakBlock() {
BlockPos front = pos.relative(getDirection());
BlockState frontBlockState = level.getBlockState(front);
Block frontBlock = frontBlockState.getBlock();
ItemStack frontStack = frontBlock.getCloneItemStack(frontBlockState, new BlockHitResult(Vec3.ZERO, getDirection().getOpposite(), front, false), level, front, LevelUtils.getFakePlayer((ServerLevel) level, getOwner()));
if (!frontStack.isEmpty() && IWhitelistBlacklist.acceptsItem(itemFilters, mode, compare, frontStack) && frontBlockState.getDestroySpeed(level, front) != -1.0) {
List<ItemStack> drops = Block.getDrops(frontBlockState, (ServerLevel) level, front, level.getBlockEntity(front), LevelUtils.getFakePlayer((ServerLevel) level, getOwner()), tool);
for (ItemStack drop : drops) {
if (!network.insertItem(drop, drop.getCount(), Action.SIMULATE).isEmpty()) {
return;
}
}
BlockEvent.BreakEvent e = new BlockEvent.BreakEvent(level, front, frontBlockState, LevelUtils.getFakePlayer((ServerLevel) level, getOwner()));
if (!MinecraftForge.EVENT_BUS.post(e)) {
frontBlock.playerWillDestroy(level, front, frontBlockState, LevelUtils.getFakePlayer((ServerLevel) level, getOwner()));
level.removeBlock(front, false);
for (ItemStack drop : drops) {
// it will essentially remove this block itself from the network without knowing
if (network == null) {
Containers.dropItemStack(level, front.getX(), front.getY(), front.getZ(), drop);
} else {
network.insertItemTracked(drop, drop.getCount());
}
}
}
}
}
use of net.minecraft.world.phys.BlockHitResult in project Electrodynamics by aurilisdev.
the class ItemCanister method useCanister.
public void useCanister(Level world, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
HitResult trace = getPlayerPOVHitResult(world, player, net.minecraft.world.level.ClipContext.Fluid.ANY);
if (!world.isClientSide && trace.getType() != Type.MISS && trace.getType() != Type.ENTITY) {
BlockHitResult blockTrace = (BlockHitResult) trace;
BlockPos pos = blockTrace.getBlockPos();
BlockState state = world.getBlockState(pos);
if (state.getFluidState().isSource() && !state.getFluidState().getType().isSame(Fluids.EMPTY)) {
FluidStack sourceFluid = new FluidStack(state.getFluidState().getType(), 1000);
boolean validFluid = CapabilityUtils.canFillItemStack(stack, sourceFluid);
if (validFluid) {
int amtFilled = CapabilityUtils.simFill(stack, sourceFluid);
if (amtFilled >= 1000) {
CapabilityUtils.fill(stack, sourceFluid);
world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
world.playSound(null, player.blockPosition(), SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 1, 1);
}
}
}
}
}
use of net.minecraft.world.phys.BlockHitResult in project Supplementaries by MehVahdJukaar.
the class SlingshotRendererHelper method grabNewLookPos.
public static void grabNewLookPos(Player player) {
float blockRange = 40;
Level world = player.level;
Vec3 start = player.position().add(0, player.getEyeHeight(), 0);
Vec3 range = player.getLookAngle().scale(blockRange);
BlockHitResult raytrace = world.clip(new ClipContext(start, start.add(range), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
if (raytrace.getType() == HitResult.Type.BLOCK && start.distanceToSqr(raytrace.getLocation()) > Mth.square(Minecraft.getInstance().gameMode.getPickRange())) {
LOOK_POS = raytrace.getBlockPos().relative(raytrace.getDirection(), 0);
}
}
use of net.minecraft.world.phys.BlockHitResult in project Supplementaries by MehVahdJukaar.
the class BlackboardBlockTileRenderer method render.
@Override
public void render(BlackboardBlockTile tile, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
Direction dir = tile.getDirection();
float yaw = -dir.toYRot();
Vec3 cameraPos = camera.getPosition();
BlockPos pos = tile.getBlockPos();
if (LOD.isOutOfFocus(cameraPos, pos, yaw, 0, dir, WIDTH / 16f))
return;
// TODO: add glow ink support
matrixStackIn.pushPose();
matrixStackIn.translate(0.5, 0.5, 0.5);
matrixStackIn.mulPose(RotHlpr.rot(dir));
matrixStackIn.mulPose(RotHlpr.XN90);
matrixStackIn.translate(-0.5, -0.5, -0.1875);
int lu = combinedLightIn & '\uffff';
int lv = combinedLightIn >> 16 & '\uffff';
HitResult hit = MC.hitResult;
if (hit != null && hit.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockHit = (BlockHitResult) hit;
if (blockHit.getBlockPos().equals(pos) && tile.getDirection() == blockHit.getDirection()) {
Player player = MC.player;
if (player != null) {
if (BlackboardBlock.getStackChalkColor(player.getMainHandItem()) != null) {
Pair<Integer, Integer> pair = BlackboardBlock.getHitSubPixel(blockHit);
float p = 1 / 16f;
float x = pair.getFirst() * p;
float y = pair.getSecond() * p;
VertexConsumer builder2 = Materials.BLACKBOARD_OUTLINE.buffer(bufferIn, RenderType::entityCutout);
matrixStackIn.pushPose();
matrixStackIn.translate(x, 1 - y - p, 0.001);
RendererUtil.addQuadSide(builder2, matrixStackIn, 0, 0, 0, p, p, 0, 0, 0, 1, 1, 1, 1, 1, 1, lu, lv, 0, 0, 1, Materials.BLACKBOARD_OUTLINE.sprite());
matrixStackIn.popPose();
}
}
}
}
// VertexConsumer builder = bufferIn.getBuffer(BlackboardTextureManager.INSTANCE.getBlackboardInstance(tile).getRenderType());
// RendererUtil.addQuadSide(builder, matrixStackIn, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, lu, lv, 0, 0, 1);
matrixStackIn.popPose();
}
Aggregations