use of net.minecraft.util.shape.VoxelShape in project Client by MatHax.
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();
// TODO: Test
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 block = ((BlockItem) event.itemEntity.getStack().getItem()).getBlock();
VoxelShape shape = block.getOutlineShape(block.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 && ((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();
// mc.getEntityRenderDispatcher().getRenderer(event.itemEntity).render(event.itemEntity, event.f, event.tickDelta, event.matrixStack, event.vertexConsumerProvider, event.light);
event.setCancelled(true);
}
use of net.minecraft.util.shape.VoxelShape in project Client by MatHax.
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 Client by MatHax.
the class BreakIndicators method renderPacket.
private void renderPacket(Render3DEvent event, List<PacketMine.MyBlock> blocks) {
for (PacketMine.MyBlock block : blocks) {
if (block.mining && block.progress != Double.POSITIVE_INFINITY) {
VoxelShape shape = block.blockState.getOutlineShape(mc.world, block.blockPos);
if (shape.isEmpty())
return;
Box orig = shape.getBoundingBox();
Box box = orig;
double progressNormalised = block.progress > 1 ? 1 : block.progress;
double shrinkFactor = 1d - progressNormalised;
BlockPos pos = block.blockPos;
renderBlock(event, box, orig, pos, shrinkFactor, progressNormalised);
}
}
}
use of net.minecraft.util.shape.VoxelShape in project wildmod by Osmiooo.
the class MangroveBoatEntity method method_7548.
public float method_7548() {
Box box = this.getBoundingBox();
Box box2 = new Box(box.minX, box.minY - 0.001D, box.minZ, box.maxX, box.minY, box.maxZ);
int i = MathHelper.floor(box2.minX) - 1;
int j = MathHelper.ceil(box2.maxX) + 1;
int k = MathHelper.floor(box2.minY) - 1;
int l = MathHelper.ceil(box2.maxY) + 1;
int m = MathHelper.floor(box2.minZ) - 1;
int n = MathHelper.ceil(box2.maxZ) + 1;
VoxelShape voxelShape = VoxelShapes.cuboid(box2);
float f = 0.0F;
int o = 0;
BlockPos.Mutable mutable = new BlockPos.Mutable();
for (int p = i; p < j; ++p) {
for (int q = m; q < n; ++q) {
int r = (p != i && p != j - 1 ? 0 : 1) + (q != m && q != n - 1 ? 0 : 1);
if (r != 2) {
for (int s = k; s < l; ++s) {
if (r <= 0 || s != k && s != l - 1) {
mutable.set(p, s, q);
BlockState blockState = this.world.getBlockState(mutable);
if (!(blockState.getBlock() instanceof LilyPadBlock) && VoxelShapes.matchesAnywhere(blockState.getCollisionShape(this.world, mutable).offset((double) p, (double) s, (double) q), voxelShape, BooleanBiFunction.AND)) {
f += blockState.getBlock().getSlipperiness();
++o;
}
}
}
}
}
}
return f / (float) o;
}
use of net.minecraft.util.shape.VoxelShape in project sodium-fabric by CaffeineMC.
the class BlockOcclusionCache method shouldDrawSide.
public boolean shouldDrawSide(BlockState state, BlockView view, BlockPos pos, Direction facing) {
BlockPos adjPos = this.cpos.set(pos).setOffset(facing);
BlockState adjState = view.getBlockState(adjPos);
if (state.isSideInvisible(adjState, facing)) {
return false;
}
if (adjState.isOpaque()) {
NeighborGroup cache = this.cache;
cache.self = state;
cache.other = adjState;
cache.facing = facing;
Object2ByteOpenHashMap<NeighborGroup> map = this.map;
byte cached = map.getByte(cache);
if (cached != 127) {
return cached != 0;
}
VoxelShape selfShape = state.getCullingFace(view, pos, facing);
VoxelShape adjShape = adjState.getCullingFace(view, adjPos, facing.getOpposite());
boolean ret = VoxelShapes.matchesAnywhere(selfShape, adjShape, BooleanBiFunction.ONLY_FIRST);
map.put(cache.copy(), (byte) (ret ? 1 : 0));
return ret;
}
return true;
}
Aggregations