mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-28 01:38:34 +01:00
Compare commits
No commits in common. "50b5209e845f1c9632bf3de0660c3e68551a635f" and "fd92ee851486c4303063f89b8a1dfbbf8e8b418e" have entirely different histories.
50b5209e84
...
fd92ee8514
2 changed files with 23 additions and 63 deletions
|
@ -11,20 +11,12 @@
|
||||||
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;
|
||||||
|
@ -47,7 +39,7 @@ public class FluidDisplay {
|
||||||
private int y;
|
private int y;
|
||||||
private boolean outline;
|
private boolean outline;
|
||||||
|
|
||||||
private TextureAtlasSprite sprite;
|
private ResourceLocation resLoc;
|
||||||
|
|
||||||
private boolean drawTextNextTo;
|
private boolean drawTextNextTo;
|
||||||
|
|
||||||
|
@ -104,38 +96,21 @@ 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.sprite == null || this.oldFluid != fluid) {
|
if (this.resLoc == null || this.oldFluid != stack.getFluid()) {
|
||||||
this.oldFluid = stack.getFluid();
|
this.oldFluid = stack.getFluid();
|
||||||
|
|
||||||
AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(InventoryMenu.BLOCK_ATLAS);
|
if (fluidTypeExtension.getStillTexture() != null) {
|
||||||
if (texture instanceof TextureAtlas) {
|
this.resLoc = new ResourceLocation(fluidTypeExtension.getStillTexture().getNamespace(), "textures/" + IClientFluidTypeExtensions.of(fluid).getStillTexture().getPath() + ".png");
|
||||||
TextureAtlasSprite sprite = ((TextureAtlas) texture).getSprite(stillTexture);
|
|
||||||
if (sprite != null) {
|
|
||||||
this.sprite = sprite;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sprite != null) {
|
if (this.resLoc != 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();
|
||||||
int count = 1 + ((int) Math.ceil(tankLevel)) / 16;
|
RenderSystem.blendFuncSeparate(770, 771, 1, 0);
|
||||||
for (int i = 0; i < count; i++) {
|
int i = this.fluidReference.getFluid().getAmount() * 83 / this.fluidReference.getCapacity();
|
||||||
double subHeight = Math.min(16.0, tankLevel - (16.0 * i));
|
guiGraphics.blit(this.resLoc, barX + 1, barY + 84 - i, 0, 0, 16, i, 16, 512);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -146,17 +121,6 @@ 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
|
||||||
|
|
|
@ -175,31 +175,27 @@ 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();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (!tile.isRedstonePowered && !tile.isPulseMode) {
|
||||||
protected void serverTick() {
|
if (tile.currentTime > 0) {
|
||||||
super.serverTick();
|
tile.currentTime--;
|
||||||
if (!isRedstonePowered && !isPulseMode) {
|
if (tile.currentTime <= 0) {
|
||||||
if (currentTime > 0) {
|
tile.doWork();
|
||||||
currentTime--;
|
}
|
||||||
if (currentTime <= 0) {
|
} else {
|
||||||
doWork();
|
tile.currentTime = 15;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
currentTime = 15;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (lastCompare != getComparatorStrength()) {
|
if (tile.lastCompare != tile.getComparatorStrength()) {
|
||||||
lastCompare = getComparatorStrength();
|
tile.lastCompare = tile.getComparatorStrength();
|
||||||
|
|
||||||
setChanged();
|
tile.setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastTankAmount != tank.getFluidAmount() && sendUpdateWithInterval()) {
|
if (tile.lastTankAmount != tile.tank.getFluidAmount() && tile.sendUpdateWithInterval()) {
|
||||||
lastTankAmount = tank.getFluidAmount();
|
tile.lastTankAmount = tile.tank.getFluidAmount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue