use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.
the class Ghosthand method onTick.
@BleachSubscribe
public void onTick(EventTick event) {
if (!mc.options.keyUse.isPressed() || mc.player.isSneaking())
return;
// Return if we are looking at any block entities
BlockPos lookingPos = new BlockPos(mc.player.raycast(4.25, mc.getTickDelta(), false).getPos());
for (BlockEntity b : WorldUtils.getBlockEntities()) {
if (lookingPos.equals(b.getPos())) {
return;
}
}
Set<BlockPos> posList = new HashSet<>();
Vec3d nextPos = new Vec3d(0, 0, 0.1).rotateX(-(float) Math.toRadians(mc.player.getPitch())).rotateY(-(float) Math.toRadians(mc.player.getYaw()));
for (int i = 1; i < 50; i++) {
BlockPos curPos = new BlockPos(mc.player.getCameraPosVec(mc.getTickDelta()).add(nextPos.multiply(i)));
if (!posList.contains(curPos)) {
posList.add(curPos);
for (BlockEntity b : WorldUtils.getBlockEntities()) {
if (b.getPos().equals(curPos)) {
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), Direction.UP, curPos, true));
return;
}
}
}
}
}
use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.
the class MixinChunkRebuildTask method newRender.
private Set<BlockEntity> newRender(float cameraX, float cameraY, float cameraZ, ChunkData data, BlockBufferBuilderStorage buffers) {
BlockPos blockPos = field_20839.getOrigin().toImmutable();
BlockPos blockPos2 = blockPos.add(15, 15, 15);
ChunkOcclusionDataBuilder chunkOcclusionDataBuilder = new ChunkOcclusionDataBuilder();
Set<BlockEntity> set = new HashSet<>();
ChunkRendererRegion chunkRendererRegion = this.region;
this.region = null;
MatrixStack matrixStack = new MatrixStack();
if (chunkRendererRegion != null) {
BlockModelRenderer.enableBrightnessCache();
Random random = new Random();
BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
for (BlockPos blockPos3 : BlockPos.iterate(blockPos, blockPos2)) {
BlockState blockState = chunkRendererRegion.getBlockState(blockPos3);
if (blockState.isOpaqueFullCube(chunkRendererRegion, blockPos3)) {
chunkOcclusionDataBuilder.markClosed(blockPos3);
}
if (blockState.hasBlockEntity()) {
BlockEntity blockEntityx = chunkRendererRegion.getBlockEntity(blockPos3, WorldChunk.CreationType.CHECK);
if (blockEntityx != null) {
this.addBlockEntity(data, set, blockEntityx);
}
}
FluidState fluid = chunkRendererRegion.getFluidState(blockPos3);
if (!fluid.isEmpty()) {
RenderLayer renderLayer = RenderLayers.getFluidLayer(fluid);
BufferBuilder bufferBuilder = buffers.get(renderLayer);
if (data.initializedLayers.add(renderLayer)) {
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
}
EventRenderFluid event = new EventRenderFluid(fluid, blockPos3, bufferBuilder);
BleachHack.eventBus.post(event);
if (event.isCancelled())
continue;
if (blockRenderManager.renderFluid(blockPos3, chunkRendererRegion, bufferBuilder, fluid)) {
data.empty = false;
data.nonEmptyLayers.add(renderLayer);
}
}
if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
RenderLayer renderLayer = RenderLayers.getBlockLayer(blockState);
BufferBuilder bufferBuilder = buffers.get(renderLayer);
if (data.initializedLayers.add(renderLayer)) {
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
}
EventRenderBlock.Tesselate event = new EventRenderBlock.Tesselate(blockState, blockPos3, matrixStack, bufferBuilder);
BleachHack.eventBus.post(event);
if (event.isCancelled())
continue;
matrixStack.push();
matrixStack.translate(blockPos3.getX() & 15, blockPos3.getY() & 15, blockPos3.getZ() & 15);
if (blockRenderManager.renderBlock(blockState, blockPos3, chunkRendererRegion, matrixStack, bufferBuilder, true, random)) {
data.empty = false;
data.nonEmptyLayers.add(renderLayer);
}
bufferBuilder.unfixColor();
matrixStack.pop();
}
}
if (data.nonEmptyLayers.contains(RenderLayer.getTranslucent())) {
BufferBuilder bufferBuilder2 = buffers.get(RenderLayer.getTranslucent());
bufferBuilder2.setCameraPosition(cameraX - (float) blockPos.getX(), cameraY - (float) blockPos.getY(), cameraZ - (float) blockPos.getZ());
data.bufferState = bufferBuilder2.popState();
}
Stream<RenderLayer> var10000 = data.initializedLayers.stream();
Objects.requireNonNull(buffers);
var10000.map(buffers::get).forEach(BufferBuilder::end);
BlockModelRenderer.disableBrightnessCache();
}
data.occlusionGraph = chunkOcclusionDataBuilder.build();
return set;
}
use of net.minecraft.block.entity.BlockEntity 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();
}
use of net.minecraft.block.entity.BlockEntity in project fabric by FabricMC.
the class MixinMinecraftClient method fabric_doItemPickWrapper.
@Inject(at = @At("HEAD"), method = "doItemPick", cancellable = true)
private void fabric_doItemPickWrapper(CallbackInfo info) {
MinecraftClient client = (MinecraftClient) (Object) this;
// Do a "best effort" emulation of the old events.
ItemStack stack = ClientPickBlockGatherCallback.EVENT.invoker().pick(client.player, client.hitResult);
// TODO: Remove in 0.3.0
if (stack.isEmpty()) {
stack = fabric_emulateOldPick();
}
if (stack.isEmpty()) {
// fall through
} else {
info.cancel();
// I don't like that we clone vanilla logic here, but it's our best bet for now.
PlayerInventory playerInventory = client.player.inventory;
if (client.player.abilities.creativeMode && Screen.hasControlDown() && client.hitResult.getType() == HitResult.Type.BLOCK) {
BlockEntity be = client.world.getBlockEntity(((BlockHitResult) client.hitResult).getBlockPos());
if (be != null) {
stack = addBlockEntityNbt(stack, be);
}
}
stack = ClientPickBlockApplyCallback.EVENT.invoker().pick(client.player, client.hitResult, stack);
if (stack.isEmpty()) {
return;
}
if (client.player.abilities.creativeMode) {
playerInventory.addPickBlock(stack);
client.interactionManager.clickCreativeStack(client.player.getStackInHand(Hand.MAIN_HAND), 36 + playerInventory.selectedSlot);
} else {
int slot = playerInventory.getSlotWithStack(stack);
if (slot >= 0) {
if (PlayerInventory.isValidHotbarIndex(slot)) {
playerInventory.selectedSlot = slot;
} else {
client.interactionManager.pickFromInventory(slot);
}
}
}
}
}
use of net.minecraft.block.entity.BlockEntity in project VeinMining by TheIllusiveC4.
the class VeinMiningLogic method harvest.
public static boolean harvest(ServerPlayerEntity player, BlockPos pos, BlockPos originPos) {
ServerWorld world = player.getWorld();
BlockState blockState = world.getBlockState(pos);
GameMode gameMode = player.interactionManager.getGameMode();
if (!player.getMainHandStack().getItem().canMine(blockState, world, pos, player)) {
return false;
} else {
BlockEntity blockEntity = world.getBlockEntity(pos);
Block block = blockState.getBlock();
if ((block instanceof CommandBlock || block instanceof StructureBlock || block instanceof JigsawBlock) && !player.isCreativeLevelTwoOp()) {
world.updateListeners(pos, blockState, blockState, 3);
return false;
} else if (player.isBlockBreakingRestricted(world, pos, gameMode)) {
return false;
} else {
block.onBreak(world, pos, blockState, player);
boolean bl = world.removeBlock(pos, false);
if (bl) {
block.onBroken(world, pos, blockState);
}
if (gameMode != GameMode.CREATIVE) {
ItemStack itemStack = player.getMainHandStack();
ItemStack itemStack2 = itemStack.copy();
boolean bl2 = player.canHarvest(blockState);
if (VeinMiningConfig.VeinMining.addToolDamage) {
postMine(itemStack, world, blockState, pos, player);
}
BlockPos spawnPos = VeinMiningConfig.VeinMining.relocateDrops ? originPos : pos;
if (bl && bl2) {
afterBreak(block, world, player, pos, spawnPos, blockState, blockEntity, itemStack2);
}
}
return true;
}
}
}
Aggregations