use of net.minecraft.client.render.model.BakedModel 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.client.render.model.BakedModel in project CITResewn by SHsuperCM.
the class ModelLoaderMixin method linkBakedCITItemModels.
@Inject(method = "upload", at = @At("RETURN"))
public void linkBakedCITItemModels(TextureManager textureManager, Profiler profiler, CallbackInfoReturnable<SpriteAtlasManager> cir) {
if (CITResewn.INSTANCE.activeCITs == null)
return;
profiler.push("citresewn_linking");
info("Linking baked models to CITItems...");
if (CITResewn.INSTANCE.activeCITs != null) {
for (CITItem citItem : CITResewn.INSTANCE.activeCITs.citItems.values().stream().flatMap(Collection::stream).distinct().collect(Collectors.toList())) {
for (Map.Entry<List<ModelOverride.Condition>, JsonUnbakedModel> citModelEntry : citItem.unbakedAssets.entrySet()) {
if (citModelEntry.getKey() == null) {
citItem.bakedModel = this.bakedModels.get(new ResewnItemModelIdentifier(citModelEntry.getValue().id));
} else {
BakedModel bakedModel = bakedModels.get(new ResewnItemModelIdentifier(citModelEntry.getValue().id));
if (bakedModel == null)
CITResewn.logWarnLoading("Skipping sub cit: Failed loading model for \"" + citModelEntry.getValue().id + "\" in " + citItem.pack.resourcePack.getName() + " -> " + citItem.propertiesIdentifier.getPath());
else
citItem.bakedSubModels.override(citModelEntry.getKey(), bakedModel);
}
}
citItem.unbakedAssets = null;
}
}
profiler.pop();
}
use of net.minecraft.client.render.model.BakedModel in project sodium-fabric by CaffeineMC.
the class MixinMultipartBakedModel method getQuads.
/**
* @author JellySquid
*/
@Overwrite
public List<BakedQuad> getQuads(BlockState state, Direction face, Random random) {
if (state == null) {
return Collections.emptyList();
}
List<BakedModel> models = this.stateCacheFast.get(state);
if (models == null) {
models = new ArrayList<>(this.components.size());
for (Pair<Predicate<BlockState>, BakedModel> pair : this.components) {
if ((pair.getLeft()).test(state)) {
models.add(pair.getRight());
}
}
this.stateCacheFast.put(state, models);
}
List<BakedQuad> list = new ArrayList<>();
long seed = random.nextLong();
for (BakedModel model : models) {
random.setSeed(seed);
list.addAll(model.getQuads(state, face, random));
}
return list;
}
use of net.minecraft.client.render.model.BakedModel 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.client.render.model.BakedModel in project RPG-Hud by KurodaAkira.
the class HudElementDetailsVanilla method renderGuiItemModel.
protected void renderGuiItemModel(ItemStack stack, int x, int y, boolean halfSize) {
BakedModel model = this.mc.getItemRenderer().getModel(stack, null, null, 0);
RenderSystem.setShaderTexture(0, PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
if (halfSize)
matrixStack.translate(x * 0.5f - 4, y * 0.5f - 4, (100.0F));
else
matrixStack.translate(x, y, (100.0F));
matrixStack.translate(8.0D, 8.0D, 0.0D);
matrixStack.scale(1.0F, -1.0F, 1.0F);
if (halfSize)
matrixStack.scale(0.5f, 0.5f, 0.5f);
matrixStack.scale(16.0F, 16.0F, 16.0F);
RenderSystem.applyModelViewMatrix();
MatrixStack matrixStack2 = new MatrixStack();
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
boolean bl = !model.isSideLit();
if (bl)
DiffuseLighting.disableGuiDepthLighting();
this.mc.getItemRenderer().renderItem(stack, ModelTransformation.Mode.GUI, false, matrixStack2, (VertexConsumerProvider) immediate, LightmapTextureManager.MAX_LIGHT_COORDINATE, OverlayTexture.DEFAULT_UV, model);
immediate.draw();
RenderSystem.enableDepthTest();
if (bl)
DiffuseLighting.enableGuiDepthLighting();
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
}
Aggregations