mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-27 17:28:34 +01:00
Compare commits
2 commits
fd92ee8514
...
50b5209e84
Author | SHA1 | Date | |
---|---|---|---|
|
50b5209e84 | ||
|
e4fdc6d7da |
2 changed files with 63 additions and 23 deletions
|
@ -11,12 +11,20 @@
|
|||
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
||||
|
||||
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 net.minecraft.client.Minecraft;
|
||||
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.resources.ResourceLocation;
|
||||
import net.minecraft.util.FastColor;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
@ -39,7 +47,7 @@ public class FluidDisplay {
|
|||
private int y;
|
||||
private boolean outline;
|
||||
|
||||
private ResourceLocation resLoc;
|
||||
private TextureAtlasSprite sprite;
|
||||
|
||||
private boolean drawTextNextTo;
|
||||
|
||||
|
@ -96,21 +104,38 @@ public class FluidDisplay {
|
|||
float green = (float)(FastColor.ARGB32.green(color) / 255.0);
|
||||
float blue = (float)(FastColor.ARGB32.blue(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();
|
||||
|
||||
if (fluidTypeExtension.getStillTexture() != null) {
|
||||
this.resLoc = new ResourceLocation(fluidTypeExtension.getStillTexture().getNamespace(), "textures/" + IClientFluidTypeExtensions.of(fluid).getStillTexture().getPath() + ".png");
|
||||
AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(InventoryMenu.BLOCK_ATLAS);
|
||||
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.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(770, 771, 1, 0);
|
||||
int i = this.fluidReference.getFluid().getAmount() * 83 / this.fluidReference.getCapacity();
|
||||
guiGraphics.blit(this.resLoc, barX + 1, barY + 84 - i, 0, 0, 16, i, 16, 512);
|
||||
int count = 1 + ((int) Math.ceil(tankLevel)) / 16;
|
||||
for (int i = 0; i < count; i++) {
|
||||
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.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) {
|
||||
if (mouseX >= this.x && mouseY >= this.y && mouseX < this.x + (this.outline
|
||||
? 26
|
||||
|
|
|
@ -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) {
|
||||
if (t instanceof TileEntityFluidCollector tile) {
|
||||
tile.serverTick();
|
||||
}
|
||||
}
|
||||
|
||||
if (!tile.isRedstonePowered && !tile.isPulseMode) {
|
||||
if (tile.currentTime > 0) {
|
||||
tile.currentTime--;
|
||||
if (tile.currentTime <= 0) {
|
||||
tile.doWork();
|
||||
}
|
||||
} else {
|
||||
tile.currentTime = 15;
|
||||
@Override
|
||||
protected void serverTick() {
|
||||
super.serverTick();
|
||||
if (!isRedstonePowered && !isPulseMode) {
|
||||
if (currentTime > 0) {
|
||||
currentTime--;
|
||||
if (currentTime <= 0) {
|
||||
doWork();
|
||||
}
|
||||
} else {
|
||||
currentTime = 15;
|
||||
}
|
||||
}
|
||||
|
||||
if (tile.lastCompare != tile.getComparatorStrength()) {
|
||||
tile.lastCompare = tile.getComparatorStrength();
|
||||
if (lastCompare != getComparatorStrength()) {
|
||||
lastCompare = getComparatorStrength();
|
||||
|
||||
tile.setChanged();
|
||||
}
|
||||
setChanged();
|
||||
}
|
||||
|
||||
if (tile.lastTankAmount != tile.tank.getFluidAmount() && tile.sendUpdateWithInterval()) {
|
||||
tile.lastTankAmount = tile.tank.getFluidAmount();
|
||||
}
|
||||
if (lastTankAmount != tank.getFluidAmount() && sendUpdateWithInterval()) {
|
||||
lastTankAmount = tank.getFluidAmount();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue