use of net.minecraft.util.shape.VoxelShape in project meteor-client by MeteorDevelopment.
the class SBlock method render.
public void render(Render3DEvent event) {
double x1 = x;
double y1 = y;
double z1 = z;
double x2 = x + 1;
double y2 = y + 1;
double z2 = z + 1;
VoxelShape shape = state.getOutlineShape(mc.world, blockPos);
if (!shape.isEmpty()) {
x1 = x + shape.getMin(Direction.Axis.X);
y1 = y + shape.getMin(Direction.Axis.Y);
z1 = z + shape.getMin(Direction.Axis.Z);
x2 = x + shape.getMax(Direction.Axis.X);
y2 = y + shape.getMax(Direction.Axis.Y);
z2 = z + shape.getMax(Direction.Axis.Z);
}
SBlockData blockData = search.getBlockData(state.getBlock());
ShapeMode shapeMode = blockData.shapeMode;
Color lineColor = blockData.lineColor;
Color sideColor = blockData.sideColor;
if (neighbours == 0) {
event.renderer.box(x1, y1, z1, x2, y2, z2, sideColor, lineColor, shapeMode, 0);
} else {
// Lines
if (shapeMode.lines()) {
// Vertical, BA_LE
if (((neighbours & LE) != LE && (neighbours & BA) != BA) || ((neighbours & LE) == LE && (neighbours & BA) == BA && (neighbours & BA_LE) != BA_LE)) {
event.renderer.line(x1, y1, z1, x1, y2, z1, lineColor);
}
// Vertical, FO_LE
if (((neighbours & LE) != LE && (neighbours & FO) != FO) || ((neighbours & LE) == LE && (neighbours & FO) == FO && (neighbours & FO_LE) != FO_LE)) {
event.renderer.line(x1, y1, z2, x1, y2, z2, lineColor);
}
// Vertical, BA_RI
if (((neighbours & RI) != RI && (neighbours & BA) != BA) || ((neighbours & RI) == RI && (neighbours & BA) == BA && (neighbours & BA_RI) != BA_RI)) {
event.renderer.line(x2, y1, z1, x2, y2, z1, lineColor);
}
// Vertical, FO_RI
if (((neighbours & RI) != RI && (neighbours & FO) != FO) || ((neighbours & RI) == RI && (neighbours & FO) == FO && (neighbours & FO_RI) != FO_RI)) {
event.renderer.line(x2, y1, z2, x2, y2, z2, lineColor);
}
// Horizontal bottom, BA_LE - BA_RI
if (((neighbours & BA) != BA && (neighbours & BO) != BO) || ((neighbours & BA) != BA && (neighbours & BO_BA) == BO_BA)) {
event.renderer.line(x1, y1, z1, x2, y1, z1, lineColor);
}
// Horizontal bottom, FO_LE - FO_RI
if (((neighbours & FO) != FO && (neighbours & BO) != BO) || ((neighbours & FO) != FO && (neighbours & BO_FO) == BO_FO)) {
event.renderer.line(x1, y1, z2, x2, y1, z2, lineColor);
}
// Horizontal top, BA_LE - BA_RI
if (((neighbours & BA) != BA && (neighbours & TO) != TO) || ((neighbours & BA) != BA && (neighbours & TO_BA) == TO_BA)) {
event.renderer.line(x1, y2, z1, x2, y2, z1, lineColor);
}
// Horizontal top, FO_LE - FO_RI
if (((neighbours & FO) != FO && (neighbours & TO) != TO) || ((neighbours & FO) != FO && (neighbours & TO_FO) == TO_FO)) {
event.renderer.line(x1, y2, z2, x2, y2, z2, lineColor);
}
// Horizontal bottom, BA_LE - FO_LE
if (((neighbours & LE) != LE && (neighbours & BO) != BO) || ((neighbours & LE) != LE && (neighbours & BO_LE) == BO_LE)) {
event.renderer.line(x1, y1, z1, x1, y1, z2, lineColor);
}
// Horizontal bottom, BA_RI - FO_RI
if (((neighbours & RI) != RI && (neighbours & BO) != BO) || ((neighbours & RI) != RI && (neighbours & BO_RI) == BO_RI)) {
event.renderer.line(x2, y1, z1, x2, y1, z2, lineColor);
}
// Horizontal top, BA_LE - FO_LE
if (((neighbours & LE) != LE && (neighbours & TO) != TO) || ((neighbours & LE) != LE && (neighbours & TO_LE) == TO_LE)) {
event.renderer.line(x1, y2, z1, x1, y2, z2, lineColor);
}
// Horizontal top, BA_RI - FO_RI
if (((neighbours & RI) != RI && (neighbours & TO) != TO) || ((neighbours & RI) != RI && (neighbours & TO_RI) == TO_RI)) {
event.renderer.line(x2, y2, z1, x2, y2, z2, lineColor);
}
}
// Sides
if (shapeMode.sides()) {
// Bottom
if ((neighbours & BO) != BO) {
event.renderer.quadHorizontal(x1, y1, z1, x2, z2, sideColor);
}
// Top
if ((neighbours & TO) != TO) {
event.renderer.quadHorizontal(x1, y2, z1, x2, z2, sideColor);
}
// Front
if ((neighbours & FO) != FO) {
event.renderer.quadVertical(x1, y1, z2, x2, y2, z2, sideColor);
}
// Back
if ((neighbours & BA) != BA) {
event.renderer.quadVertical(x1, y1, z1, x2, y2, z1, sideColor);
}
// Right
if ((neighbours & RI) != RI) {
event.renderer.quadVertical(x2, y1, z1, x2, y2, z2, sideColor);
}
// Left
if ((neighbours & LE) != LE) {
event.renderer.quadVertical(x1, y1, z1, x1, y2, z2, sideColor);
}
}
}
}
use of net.minecraft.util.shape.VoxelShape in project meteor-client by MeteorDevelopment.
the class ItemPhysics method onRenderItemEntity.
@EventHandler
private void onRenderItemEntity(RenderItemEntityEvent event) {
ItemStack itemStack = event.itemEntity.getStack();
int seed = itemStack.isEmpty() ? 187 : Item.getRawId(itemStack.getItem()) + itemStack.getDamage();
event.random.setSeed(seed);
event.matrixStack.push();
BakedModel bakedModel = event.itemRenderer.getModel(itemStack, event.itemEntity.world, null, 0);
boolean hasDepthInGui = bakedModel.hasDepth();
int renderCount = getRenderedAmount(itemStack);
IItemEntity rotator = (IItemEntity) event.itemEntity;
boolean renderBlockFlat = false;
if (event.itemEntity.getStack().getItem() instanceof BlockItem && !(event.itemEntity.getStack().getItem() instanceof AliasedBlockItem)) {
Block b = ((BlockItem) event.itemEntity.getStack().getItem()).getBlock();
VoxelShape shape = b.getOutlineShape(b.getDefaultState(), event.itemEntity.world, event.itemEntity.getBlockPos(), ShapeContext.absent());
if (shape.getMax(Direction.Axis.Y) <= .5)
renderBlockFlat = true;
}
Item item = event.itemEntity.getStack().getItem();
if (item instanceof BlockItem && !(item instanceof AliasedBlockItem) && !renderBlockFlat) {
event.matrixStack.translate(0, -0.06, 0);
}
if (!renderBlockFlat) {
event.matrixStack.translate(0, .185, .0);
event.matrixStack.multiply(Vec3f.POSITIVE_X.getRadialQuaternion(1.571F));
event.matrixStack.translate(0, -.185, -.0);
}
boolean isAboveWater = event.itemEntity.world.getBlockState(event.itemEntity.getBlockPos()).getFluidState().getFluid().isIn(FluidTags.WATER);
if (!event.itemEntity.isOnGround() && (!event.itemEntity.isSubmergedInWater() && !isAboveWater)) {
// calculate rotation based on age and ticks
float rotation = ((float) event.itemEntity.getItemAge() + event.tickDelta) / 20.0F + event.itemEntity.uniqueOffset;
if (!renderBlockFlat) {
event.matrixStack.translate(0, .185, .0);
event.matrixStack.multiply(Vec3f.POSITIVE_Z.getRadialQuaternion(rotation));
event.matrixStack.translate(0, -.185, .0);
rotator.setRotation(new Vec3d(0, 0, rotation));
} else {
event.matrixStack.multiply(Vec3f.POSITIVE_Y.getRadialQuaternion(rotation));
rotator.setRotation(new Vec3d(0, rotation, 0));
event.matrixStack.translate(0, -.065, 0);
}
if (event.itemEntity.getStack().getItem() instanceof AliasedBlockItem) {
event.matrixStack.translate(0, 0, .195);
} else if (!(event.itemEntity.getStack().getItem() instanceof BlockItem)) {
event.matrixStack.translate(0, 0, .195);
}
} else if (event.itemEntity.getStack().getItem() instanceof AliasedBlockItem) {
event.matrixStack.translate(0, .185, .0);
event.matrixStack.multiply(Vec3f.POSITIVE_Z.getRadialQuaternion((float) rotator.getRotation().z));
event.matrixStack.translate(0, -.185, .0);
event.matrixStack.translate(0, 0, .195);
} else if (renderBlockFlat) {
event.matrixStack.multiply(Vec3f.POSITIVE_Y.getRadialQuaternion((float) rotator.getRotation().y));
event.matrixStack.translate(0, -.065, 0);
} else {
if (!(event.itemEntity.getStack().getItem() instanceof BlockItem)) {
event.matrixStack.translate(0, 0, .195);
}
event.matrixStack.translate(0, .185, .0);
event.matrixStack.multiply(Vec3f.POSITIVE_Z.getRadialQuaternion((float) rotator.getRotation().z));
event.matrixStack.translate(0, -.185, .0);
}
if (event.itemEntity.world.getBlockState(event.itemEntity.getBlockPos()).getBlock().equals(Blocks.SOUL_SAND)) {
event.matrixStack.translate(0, 0, -.1);
}
if (event.itemEntity.getStack().getItem() instanceof BlockItem) {
if (((BlockItem) event.itemEntity.getStack().getItem()).getBlock() instanceof SkullBlock) {
event.matrixStack.translate(0, .11, 0);
}
}
float scaleX = bakedModel.getTransformation().ground.scale.getX();
float scaleY = bakedModel.getTransformation().ground.scale.getY();
float scaleZ = bakedModel.getTransformation().ground.scale.getZ();
float x;
float y;
if (!hasDepthInGui) {
float r = -0.0F * (float) (renderCount) * 0.5F * scaleX;
x = -0.0F * (float) (renderCount) * 0.5F * scaleY;
y = -0.09375F * (float) (renderCount) * 0.5F * scaleZ;
event.matrixStack.translate(r, x, y);
}
for (int u = 0; u < renderCount; ++u) {
event.matrixStack.push();
if (u > 0) {
if (hasDepthInGui) {
x = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
y = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
float z = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F;
event.matrixStack.translate(x, y, z);
} else {
x = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F * 0.5F;
y = (event.random.nextFloat() * 2.0F - 1.0F) * 0.15F * 0.5F;
event.matrixStack.translate(x, y, 0.0D);
event.matrixStack.multiply(Vec3f.POSITIVE_Z.getRadialQuaternion(event.random.nextFloat()));
}
}
event.itemRenderer.renderItem(itemStack, ModelTransformation.Mode.GROUND, false, event.matrixStack, event.vertexConsumerProvider, event.light, OverlayTexture.DEFAULT_UV, bakedModel);
event.matrixStack.pop();
if (!hasDepthInGui) {
event.matrixStack.translate(0.0F * scaleX, 0.0F * scaleY, 0.0625F * scaleZ);
}
}
event.matrixStack.pop();
event.setCancelled(true);
}
use of net.minecraft.util.shape.VoxelShape in project meteor-client by MeteorDevelopment.
the class BreakIndicators method renderNormal.
private void renderNormal(Render3DEvent event) {
Map<Integer, BlockBreakingInfo> blocks = ((WorldRendererAccessor) mc.worldRenderer).getBlockBreakingInfos();
float ownBreakingStage = ((ClientPlayerInteractionManagerAccessor) mc.interactionManager).getBreakingProgress();
BlockPos ownBreakingPos = ((ClientPlayerInteractionManagerAccessor) mc.interactionManager).getCurrentBreakingBlockPos();
if (ownBreakingPos != null && mc.interactionManager.isBreakingBlock()) {
BlockState state = mc.world.getBlockState(ownBreakingPos);
VoxelShape shape = state.getOutlineShape(mc.world, ownBreakingPos);
if (shape.isEmpty() || shape == null)
return;
Box orig = shape.getBoundingBox();
Box box = orig;
double shrinkFactor = 1d - ownBreakingStage;
double progress = 1d - shrinkFactor;
renderBlock(event, box, orig, ownBreakingPos, shrinkFactor, progress);
}
blocks.values().forEach(info -> {
BlockPos pos = info.getPos();
int stage = info.getStage();
if (pos.equals(ownBreakingPos))
return;
BlockState state = mc.world.getBlockState(pos);
VoxelShape shape = state.getOutlineShape(mc.world, pos);
if (shape.isEmpty())
return;
Box orig = shape.getBoundingBox();
Box box = orig;
double shrinkFactor = (9 - (stage + 1)) / 9d;
double progress = 1d - shrinkFactor;
renderBlock(event, box, orig, pos, shrinkFactor, progress);
});
}
use of net.minecraft.util.shape.VoxelShape in project meteor-client by MeteorDevelopment.
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.shape.VoxelShape in project roadrunner by MaxNeedsSnacks.
the class ChunkAwareBlockCollisionSweeper method getNextBlockCollision.
/**
* Advances the sweep forward until finding a block with a box-colliding VoxelShape<br>
* cf VoxelShapes#calculatePushVelocity (?)
*
* @return null if no VoxelShape is left in the area, otherwise the next VoxelShape
*/
private VoxelShape getNextBlockCollision() {
while (true) {
if (this.cIterated >= this.cTotalSize) {
if (!this.nextSection()) {
break;
}
}
this.cIterated++;
final int x = this.cX;
final int y = this.cY;
final int z = this.cZ;
// This code hasn't been benchmarked in comparison to another access order.
if (this.cX < this.cEndX) {
this.cX++;
} else if (this.cZ < this.cEndZ) {
this.cX = this.cStartX;
this.cZ++;
} else {
this.cX = this.cStartX;
this.cZ = this.cStartZ;
this.cY++;
// stop condition was already checked using this.cIterated at the start of the method
}
// using < minX and > maxX instead of <= and >= in vanilla, because minX, maxX are the coordinates
// of the box that wasn't extended for oversized blocks yet.
final int edgesHit = this.sectionOversizedBlocks ? (x < this.minX || x > this.maxX ? 1 : 0) + (y < this.minY || y > this.maxY ? 1 : 0) + (z < this.minZ || z > this.maxZ ? 1 : 0) : 0;
if (edgesHit == 3) {
continue;
}
final BlockState state;
if (this.cachedChunkSection != null) {
state = this.cachedChunkSection.getBlockState(x & 15, y & 15, z & 15);
} else {
state = this.cachedChunk.getBlockState(new BlockPos(x, y, z));
}
if (!canInteractWithBlock(state, edgesHit)) {
continue;
}
this.pos.set(x, y, z);
if (!this.collisionPredicate.test(this.view, this.pos, state)) {
continue;
}
VoxelShape collisionShape = state.getCollisionShape(this.view, this.pos, this.context);
if (collisionShape != VoxelShapes.empty()) {
VoxelShape collidedShape = getCollidedShape(this.box, this.shape, collisionShape, x, y, z);
if (collidedShape != null) {
return collidedShape;
}
}
}
return null;
}
Aggregations