use of net.minecraft.client.texture.Sprite in project Primeval by devs-immortal.
the class PrimevalFluids method setupFluidRendering.
/*
* Fluid rendering setup from Spectrum,
* Made by DaFaqs, credit to him for this
* method
*/
@Environment(EnvType.CLIENT)
private static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, final int color) {
final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath());
final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
// If they're not already present, add the sprites to the block atlas
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
registry.register(stillSpriteId);
registry.register(flowingSpriteId);
});
final Identifier fluidId = Registry.FLUID.getId(still);
final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
final Sprite[] fluidSprites = { null, null };
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
/**
* Get the sprites from the block atlas when resources are reloaded
*/
@Override
public void reload(ResourceManager manager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillSpriteId);
fluidSprites[1] = atlas.apply(flowingSpriteId);
}
@Override
public Identifier getFabricId() {
return listenerId;
}
});
// The FluidRenderer gets the sprites and color from a FluidRenderHandler during rendering
final FluidRenderHandler renderHandler = new FluidRenderHandler() {
@Override
public Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState state) {
return fluidSprites;
}
@Override
public int getFluidColor(BlockRenderView view, BlockPos pos, FluidState state) {
return color;
}
};
FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
// FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler); // Temp removed because of flowing shenanigans
}
use of net.minecraft.client.texture.Sprite in project meteor-client by MeteorDevelopment.
the class SodiumBlockRendererMixin method whRenderQuad.
// https://github.com/CaffeineMC/sodium-fabric/blob/8b3015efe85be9336a150ff7c26085ea3d2d43d0/src/main/java/me/jellysquid/mods/sodium/client/render/pipeline/BlockRenderer.java#L119
// Copied from Sodium, for now, can't think of a better way, because of the nature of the locals, and for loop.
// Mixin seems to freak out when I try to do this the "right" way - Wala (sobbing)
private void whRenderQuad(BlockRenderView world, BlockState state, BlockPos pos, BlockPos origin, ModelVertexSink vertices, IndexBufferBuilder indices, Vec3d blockOffset, ColorSampler<BlockState> colorSampler, BakedQuad bakedQuad, QuadLightData light, ChunkModelBuilder model, int alpha) {
ModelQuadView src = (ModelQuadView) bakedQuad;
ModelQuadOrientation orientation = ModelQuadOrientation.orientByBrightness(light.br);
int[] colors = null;
if (bakedQuad.hasColor()) {
colors = this.colorBlender.getColors(world, pos, src, colorSampler, state);
}
int vertexStart = vertices.getVertexCount();
for (int i = 0; i < 4; i++) {
int j = orientation.getVertexIndex(i);
float x = src.getX(j) + (float) blockOffset.getX();
float y = src.getY(j) + (float) blockOffset.getY();
float z = src.getZ(j) + (float) blockOffset.getZ();
int color = ColorABGR.mul(colors != null ? colors[j] : 0xFFFFFFFF, light.br[j]);
int blue = ColorABGR.unpackBlue(color);
int green = ColorABGR.unpackGreen(color);
int red = ColorABGR.unpackRed(color);
color = ColorABGR.pack(red, green, blue, alpha);
float u = src.getTexU(j);
float v = src.getTexV(j);
int lm = light.lm[j];
vertices.writeVertex(origin, x, y, z, color, u, v, lm, model.getChunkId());
}
indices.add(vertexStart, ModelQuadWinding.CLOCKWISE);
Sprite sprite = src.getSprite();
if (sprite != null) {
model.addSprite(sprite);
}
}
use of net.minecraft.client.texture.Sprite in project Paradise-Lost by devs-immortal.
the class FluidRenderSetup method setupFluidRendering.
public static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, final int color) {
final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_still");
final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
// If they're not already present, add the sprites to the block atlas
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
registry.register(stillSpriteId);
registry.register(flowingSpriteId);
});
final Identifier fluidId = Registry.FLUID.getId(still);
final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
final Sprite[] fluidSprites = { null, null };
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return listenerId;
}
/**
* Get the sprites from the block atlas when resources are reloaded
*/
@Override
public void apply(ResourceManager resourceManager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillSpriteId);
fluidSprites[1] = atlas.apply(flowingSpriteId);
}
});
// The FluidRenderer gets the sprites and color from a FluidRenderHandler during rendering
final FluidRenderHandler renderHandler = new FluidRenderHandler() {
@Override
public Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState state) {
return fluidSprites;
}
@Override
public int getFluidColor(BlockRenderView view, BlockPos pos, FluidState state) {
return color;
}
};
FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler);
}
use of net.minecraft.client.texture.Sprite in project Neutrino by FrostWizard4.
the class NeutrinoModelLoader method renderElectricityOverlay.
public static void renderElectricityOverlay(MinecraftClient client, MatrixStack matrices) {
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
RenderSystem.setShader(GameRenderer::getPositionColorTexShader);
RenderSystem.depthFunc(519);
RenderSystem.depthMask(false);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableTexture();
Sprite sprite = ELECTRICITY.getSprite();
RenderSystem.setShaderTexture(0, sprite.getAtlas().getId());
float f = sprite.getMinU();
float g = sprite.getMaxU();
float h = (f + g) / 2.0f;
float i = sprite.getMinV();
float j = sprite.getMaxV();
float k = (i + j) / 2.0f;
float l = sprite.getAnimationFrameDelta();
float m = MathHelper.lerp(l, f, h);
float n = MathHelper.lerp(l, g, h);
float o = MathHelper.lerp(l, i, k);
float p = MathHelper.lerp(l, j, k);
float q = 1.0f;
for (int r = 0; r < 2; ++r) {
matrices.push();
float s = -0.5f;
float t = 0.5f;
float u = -0.5f;
float v = 0.5f;
float w = -0.5f;
matrices.translate((float) (-(r * 2 - 1)) * 0.24f, -0.3f, 0.0);
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion((float) (r * 2 - 1) * 10.0f));
Matrix4f matrix4f = matrices.peek().getPositionMatrix();
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE);
bufferBuilder.vertex(matrix4f, -0.4f, -0.4f, -0.4f).color(1.0f, 1.0f, 1.0f, 0.7f).texture(n, p).next();
bufferBuilder.vertex(matrix4f, 0.4f, -0.4f, -0.4f).color(1.0f, 1.0f, 1.0f, 0.7f).texture(m, p).next();
bufferBuilder.vertex(matrix4f, 0.4f, 0.4f, -0.4f).color(1.0f, 1.0f, 1.0f, 0.7f).texture(m, o).next();
bufferBuilder.vertex(matrix4f, -0.4f, 0.4f, -0.4f).color(1.0f, 1.0f, 1.0f, 0.7f).texture(n, o).next();
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
matrices.pop();
}
}
use of net.minecraft.client.texture.Sprite in project BedrockIfy by juancarloscp52.
the class InGameHudMixin method renderStatusEffectOverlay.
/**
* Render the status effect overlay with the screen border distance applied.
*/
@Inject(method = "renderStatusEffectOverlay", at = @At("HEAD"), cancellable = true)
public void renderStatusEffectOverlay(MatrixStack matrixStack, CallbackInfo info) {
Collection<StatusEffectInstance> collection = Objects.requireNonNull(this.client.player).getStatusEffects();
if (!collection.isEmpty()) {
RenderSystem.enableBlend();
int beneficialEffects = 0;
int harmfulEffects = 0;
StatusEffectSpriteManager statusEffectSpriteManager = this.client.getStatusEffectSpriteManager();
List<Runnable> list = Lists.newArrayListWithExpectedSize(collection.size());
this.client.getTextureManager().bindTexture(HandledScreen.BACKGROUND_TEXTURE);
for (StatusEffectInstance statusEffectInstance : Ordering.natural().reverse().sortedCopy(collection)) {
StatusEffect statusEffect = statusEffectInstance.getEffectType();
if (statusEffectInstance.shouldShowIcon()) {
int x = this.scaledWidth - screenBorder;
int y = 1 + screenBorder;
if (this.client.isDemo()) {
y += 15;
}
if (statusEffect.isBeneficial()) {
++beneficialEffects;
x -= 25 * beneficialEffects;
} else {
++harmfulEffects;
x -= 25 * harmfulEffects;
y += 26;
}
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
float spriteAlpha = 1.0F;
if (statusEffectInstance.isAmbient()) {
this.drawTexture(matrixStack, x, y, 165, 166, 24, 24);
} else {
this.drawTexture(matrixStack, x, y, 141, 166, 24, 24);
if (statusEffectInstance.getDuration() <= 200) {
int m = 10 - statusEffectInstance.getDuration() / 20;
spriteAlpha = MathHelper.clamp((float) statusEffectInstance.getDuration() / 10.0F / 5.0F * 0.5F, 0.0F, 0.5F) + MathHelper.cos((float) statusEffectInstance.getDuration() * 3.1415927F / 5.0F) * MathHelper.clamp((float) m / 10.0F * 0.25F, 0.0F, 0.25F);
}
}
Sprite sprite = statusEffectSpriteManager.getSprite(statusEffect);
int finalX = x + 3;
int finalY = y + 3;
float finalAlpha = spriteAlpha;
list.add(() -> {
this.client.getTextureManager().bindTexture(sprite.getAtlas().getId());
RenderSystem.color4f(1.0F, 1.0F, 1.0F, finalAlpha);
drawSprite(matrixStack, finalX, finalY, this.getZOffset(), 18, 18, sprite);
});
}
}
list.forEach(Runnable::run);
}
info.cancel();
}
Aggregations