Compare commits

...

2 commits

2 changed files with 63 additions and 23 deletions

View file

@ -11,12 +11,20 @@
package de.ellpeck.actuallyadditions.mod.inventory.gui; package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor; import net.minecraft.util.FastColor;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluid;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.api.distmarker.OnlyIn;
@ -39,7 +47,7 @@ public class FluidDisplay {
private int y; private int y;
private boolean outline; private boolean outline;
private ResourceLocation resLoc; private TextureAtlasSprite sprite;
private boolean drawTextNextTo; private boolean drawTextNextTo;
@ -96,21 +104,38 @@ public class FluidDisplay {
float green = (float)(FastColor.ARGB32.green(color) / 255.0); float green = (float)(FastColor.ARGB32.green(color) / 255.0);
float blue = (float)(FastColor.ARGB32.blue(color) / 255.0); float blue = (float)(FastColor.ARGB32.blue(color) / 255.0);
float alpha = (float)(FastColor.ARGB32.alpha(color) / 255.0); float alpha = (float)(FastColor.ARGB32.alpha(color) / 255.0);
ResourceLocation stillTexture = fluidTypeExtension.getStillTexture();
if (this.resLoc == null || this.oldFluid != stack.getFluid()) { if (this.sprite == null || this.oldFluid != fluid) {
this.oldFluid = stack.getFluid(); this.oldFluid = stack.getFluid();
if (fluidTypeExtension.getStillTexture() != null) { AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(InventoryMenu.BLOCK_ATLAS);
this.resLoc = new ResourceLocation(fluidTypeExtension.getStillTexture().getNamespace(), "textures/" + IClientFluidTypeExtensions.of(fluid).getStillTexture().getPath() + ".png"); if (texture instanceof TextureAtlas) {
TextureAtlasSprite sprite = ((TextureAtlas) texture).getSprite(stillTexture);
if (sprite != null) {
this.sprite = sprite;
}
} }
} }
if (this.resLoc != null) { if (this.sprite != null) {
float minU = sprite.getU0();
float maxU = sprite.getU1();
float minV = sprite.getV0();
float maxV = sprite.getV1();
float deltaV = maxV - minV;
double tankLevel = ((float) this.fluidReference.getFluidAmount() / (float) fluidReference.getCapacity()) * 83;
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
RenderSystem.setShaderColor(red, green, blue, alpha); RenderSystem.setShaderColor(red, green, blue, alpha);
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(770, 771, 1, 0); int count = 1 + ((int) Math.ceil(tankLevel)) / 16;
int i = this.fluidReference.getFluid().getAmount() * 83 / this.fluidReference.getCapacity(); for (int i = 0; i < count; i++) {
guiGraphics.blit(this.resLoc, barX + 1, barY + 84 - i, 0, 0, 16, i, 16, 512); double subHeight = Math.min(16.0, tankLevel - (16.0 * i));
double offsetY = 84 - 16.0 * i - subHeight;
drawQuad(barX + 1, barY + offsetY, 16, subHeight, minU, (float) (maxV - deltaV * (subHeight / 16.0)), maxU, maxV);
}
RenderSystem.disableBlend(); RenderSystem.disableBlend();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
} }
@ -121,6 +146,17 @@ public class FluidDisplay {
} }
} }
private void drawQuad(double x, double y, double width, double height, float minU, float minV, float maxU, float maxV) {
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder buffer = tesselator.getBuilder();
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
buffer.vertex(x, y + height, 0).uv(minU, maxV).endVertex();
buffer.vertex(x + width, y + height, 0).uv(maxU, maxV).endVertex();
buffer.vertex(x + width, y, 0).uv(maxU, minV).endVertex();
buffer.vertex(x, y, 0).uv(minU, minV).endVertex();
tesselator.end();
}
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) { public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
if (mouseX >= this.x && mouseY >= this.y && mouseX < this.x + (this.outline if (mouseX >= this.x && mouseY >= this.y && mouseX < this.x + (this.outline
? 26 ? 26

View file

@ -175,27 +175,31 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing
public static <T extends BlockEntity> void serverTick(Level level, BlockPos pos, BlockState state, T t) { public static <T extends BlockEntity> void serverTick(Level level, BlockPos pos, BlockState state, T t) {
if (t instanceof TileEntityFluidCollector tile) { if (t instanceof TileEntityFluidCollector tile) {
tile.serverTick(); tile.serverTick();
}
}
if (!tile.isRedstonePowered && !tile.isPulseMode) { @Override
if (tile.currentTime > 0) { protected void serverTick() {
tile.currentTime--; super.serverTick();
if (tile.currentTime <= 0) { if (!isRedstonePowered && !isPulseMode) {
tile.doWork(); if (currentTime > 0) {
} currentTime--;
} else { if (currentTime <= 0) {
tile.currentTime = 15; doWork();
} }
} else {
currentTime = 15;
} }
}
if (tile.lastCompare != tile.getComparatorStrength()) { if (lastCompare != getComparatorStrength()) {
tile.lastCompare = tile.getComparatorStrength(); lastCompare = getComparatorStrength();
tile.setChanged(); setChanged();
} }
if (tile.lastTankAmount != tile.tank.getFluidAmount() && tile.sendUpdateWithInterval()) { if (lastTankAmount != tank.getFluidAmount() && sendUpdateWithInterval()) {
tile.lastTankAmount = tile.tank.getFluidAmount(); lastTankAmount = tank.getFluidAmount();
}
} }
} }