Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Modifications to Chaos Islands of DraconicEvolution are consistent with later versions【Remove this if StellarCore's pr merges】
Added HUD energy display
  • Loading branch information
sddsd2332 committed Dec 31, 2024
1 parent 6abd773 commit fa8e478
Show file tree
Hide file tree
Showing 22 changed files with 802 additions and 53 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mixin_booter_version = 9.1
# Each config can only have one and only one package root.
# Generate missing configs, obtain from mixin_configs and generate file base on name convention: "mixins.config_name.json"
# You should change package root once they are generated
generate_mixins_json = true
generate_mixins_json = false
# Delimit configs with spaces. Should only put configs name instead of full file name
mixin_configs = ${mod_id}
# A refmap is a json that denotes mapping conversions, this json is generated automatically, with the name `mixins.mod_id.refmap.json`
Expand Down
170 changes: 170 additions & 0 deletions src/main/java/mekanism/client/gui/element/GuiUtils.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
package mekanism.client.gui.element;

import com.google.common.annotations.VisibleForTesting;
import it.unimi.dsi.fastutil.ints.IntIterator;
import mekanism.api.gas.GasStack;
import mekanism.client.render.MekanismRenderer;
import mekanism.common.InfuseStorage;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.profiler.Profiler;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.NoSuchElementException;

import static mekanism.client.gui.element.GuiElement.mc;


@SideOnly(Side.CLIENT)
public class GuiUtils {

public static void renderExtendedTexture(ResourceLocation resource, int sideWidth, int sideHeight, int left, int top, int width, int height) {
int textureWidth = 2 * sideWidth + 1;
int textureHeight = 2 * sideHeight + 1;
blitNineSlicedSized(resource, left, top, width, height, sideWidth, sideHeight, textureWidth, textureHeight, 0, 0, textureWidth, textureHeight);
}

public static void drawBarSprite(int xPos, int yPos, int sizeX, int sizeY, int displayInt, TextureAtlasSprite textureSprite, boolean vertical) {
if (displayInt > 0) {
if (textureSprite != null) {
Expand Down Expand Up @@ -162,4 +175,161 @@ public enum TilingDirection {
this.right = right;
}
}

public static void blitNineSlicedSized(ResourceLocation texture, int x, int y, int width, int height, int sliceWidth, int sliceHeight, int uWidth, int vHeight, int uOffset, int vOffset, int textureWidth, int textureHeight) {
Minecraft mc = Minecraft.getMinecraft();
Profiler profiler = mc.profiler;
mc.renderEngine.bindTexture(texture);
profiler.startSection("blitting");
profiler.endSection();

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);

profiler.startSection("blitting");

int cornerWidth = sliceWidth;
int cornerHeight = sliceHeight;
int edgeWidth = sliceWidth;
int edgeHeight = sliceHeight;
cornerWidth = Math.min(cornerWidth, width / 2);
edgeWidth = Math.min(edgeWidth, width / 2);
cornerHeight = Math.min(cornerHeight, height / 2);
edgeHeight = Math.min(edgeHeight, height / 2);
if (width == uWidth && height == vHeight) {
blit(bufferbuilder, x, y, uOffset, vOffset, width, height, textureWidth, textureHeight);
} else if (height == vHeight) {
blit(bufferbuilder, x, y, uOffset, vOffset, cornerWidth, height, textureWidth, textureHeight);
blitRepeating(bufferbuilder, x + cornerWidth, y, width - edgeWidth - cornerWidth, height, uOffset + cornerWidth, vOffset, uWidth - edgeWidth - cornerWidth, vHeight, textureWidth, textureHeight);
blit(bufferbuilder, x + width - edgeWidth, y, uOffset + uWidth - edgeWidth, vOffset, edgeWidth, height, textureWidth, textureHeight);
} else if (width == uWidth) {
blit(bufferbuilder, x, y, uOffset, vOffset, width, cornerHeight, textureWidth, textureHeight);
blitRepeating(bufferbuilder, x, y + cornerHeight, width, height - edgeHeight - cornerHeight, uOffset, vOffset + cornerHeight, uWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight);
blit(bufferbuilder, x, y + height - edgeHeight, uOffset, vOffset + vHeight - edgeHeight, width, edgeHeight, textureWidth, textureHeight);
} else {
blit(bufferbuilder, x, y, uOffset, vOffset, cornerWidth, cornerHeight, textureWidth, textureHeight);
blitRepeating(bufferbuilder, x + cornerWidth, y, width - edgeWidth - cornerWidth, cornerHeight, uOffset + cornerWidth, vOffset, uWidth - edgeWidth - cornerWidth, cornerHeight, textureWidth, textureHeight);
blit(bufferbuilder, x + width - edgeWidth, y, uOffset + uWidth - edgeWidth, vOffset, edgeWidth, cornerHeight, textureWidth, textureHeight);
blit(bufferbuilder, x, y + height - edgeHeight, uOffset, vOffset + vHeight - edgeHeight, cornerWidth, edgeHeight, textureWidth, textureHeight);
blitRepeating(bufferbuilder, x + cornerWidth, y + height - edgeHeight, width - edgeWidth - cornerWidth, edgeHeight, uOffset + cornerWidth, vOffset + vHeight - edgeHeight, uWidth - edgeWidth - cornerWidth, edgeHeight, textureWidth, textureHeight);
blit(bufferbuilder, x + width - edgeWidth, y + height - edgeHeight, uOffset + uWidth - edgeWidth, vOffset + vHeight - edgeHeight, edgeWidth, edgeHeight, textureWidth, textureHeight);
blitRepeating(bufferbuilder, x, y + cornerHeight, cornerWidth, height - edgeHeight - cornerHeight, uOffset, vOffset + cornerHeight, cornerWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight);
blitRepeating(bufferbuilder, x + cornerWidth, y + cornerHeight, width - edgeWidth - cornerWidth, height - edgeHeight - cornerHeight, uOffset + cornerWidth, vOffset + cornerHeight, uWidth - edgeWidth - cornerWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight);
blitRepeating(bufferbuilder, x + width - edgeWidth, y + cornerHeight, cornerWidth, height - edgeHeight - cornerHeight, uOffset + uWidth - edgeWidth, vOffset + cornerHeight, edgeWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight);
}
profiler.endSection();

profiler.startSection("drawing");
tessellator.draw();

profiler.endSection();
}

private static void blit(BufferBuilder bufferbuilder, int pX, int pY, float pUOffset, float pVOffset, int pWidth, int pHeight, int pTextureWidth, int pTextureHeight) {
bufferbuilder.pos((float) pX, (float) pY, (float) 0).tex((pUOffset + 0.0F) / (float) pTextureWidth, (pVOffset + 0.0F) / (float) pTextureHeight).endVertex();
bufferbuilder.pos((float) pX, (float) (pY + pHeight), (float) 0).tex((pUOffset + 0.0F) / (float) pTextureWidth, (pVOffset + (float) pHeight) / (float) pTextureHeight).endVertex();
bufferbuilder.pos((float) (pX + pWidth), (float) (pY + pHeight), (float) 0).tex((pUOffset + (float) pWidth) / (float) pTextureWidth, (pVOffset + (float) pHeight) / (float) pTextureHeight).endVertex();
bufferbuilder.pos((float) (pX + pWidth), (float) pY, (float) 0).tex((pUOffset + (float) pWidth) / (float) pTextureWidth, (pVOffset + 0.0F) / (float) pTextureHeight).endVertex();
}

private static void blitRepeating(BufferBuilder bufferbuilder, int pX, int pY, int pWidth, int pHeight, int pUOffset, int pVOffset, int pSourceWidth, int pSourceHeight, int textureWidth, int textureHeight) {
int i = pX;

int j;
for (IntIterator intiterator = slices(pWidth, pSourceWidth); intiterator.hasNext(); i += j) {
j = intiterator.nextInt();
int k = (pSourceWidth - j) / 2;
int l = pY;

int i1;
for (IntIterator intiterator1 = slices(pHeight, pSourceHeight); intiterator1.hasNext(); l += i1) {
i1 = intiterator1.nextInt();
int j1 = (pSourceHeight - i1) / 2;
blit(bufferbuilder, i, l, pUOffset + k, pVOffset + j1, j, i1, textureWidth, textureHeight);
}
}
}


/**
* Returns an iterator for dividing a value into slices of a specified size.
* <p>
*
* @param pTarget the value to be divided.
* @param pTotal the size of each slice.
*
* @return An iterator for iterating over the slices.
*/
private static IntIterator slices(int pTarget, int pTotal) {
int i = -Math.floorDiv(-pTarget, pTotal);
return new Divisor(pTarget, i);
}

public static class Divisor implements IntIterator {
private final int denominator;
private final int quotient;
private final int mod;
private int returnedParts;
private int remainder;

public Divisor(int pNumerator, int pDenominator) {
this.denominator = pDenominator;
if (pDenominator > 0) {
this.quotient = pNumerator / pDenominator;
this.mod = pNumerator % pDenominator;
} else {
this.quotient = 0;
this.mod = 0;
}

}

public boolean hasNext() {
return this.returnedParts < this.denominator;
}

@Override
public Integer next() {
return this.nextInt();
}

public int nextInt() {
if (!this.hasNext()) {
throw new NoSuchElementException();
} else {
int i = this.quotient;
this.remainder += this.mod;
if (this.remainder >= this.denominator) {
this.remainder -= this.denominator;
++i;
}

++this.returnedParts;
return i;
}
}

@Override
public int skip(int n) {
if (n < 0) {
throw new IllegalArgumentException("Argument must be nonnegative: " + n);
} else {
int i = n;

while (i-- != 0 && this.hasNext()) {
this.nextInt();
}

return n - i - 1;
}
}

@VisibleForTesting
public static Iterable<Integer> asIterable(int pNumerator, int pDenominator) {
return () -> new Divisor(pNumerator, pDenominator);
}
}


}
67 changes: 67 additions & 0 deletions src/main/java/mekanism/client/render/hud/MekaSuitEnergyLevel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package mekanism.client.render.hud;

import mekanism.client.gui.element.GuiUtils;
import mekanism.common.item.armor.ItemMekaSuitArmor;
import mekanism.common.util.MekanismUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class MekaSuitEnergyLevel {

private static final ResourceLocation BAR = MekanismUtils.getResource(MekanismUtils.ResourceType.GUI_BAR, "Base2.png");
private static final ResourceLocation POWER_BAR = MekanismUtils.getResource(MekanismUtils.ResourceType.GUI_BAR, "horizontal_power_long.png");

public static void onDrawScreenPre(RenderGameOverlayEvent.Pre event) {
Minecraft mc = Minecraft.getMinecraft();
if (event.getType() == RenderGameOverlayEvent.ElementType.ARMOR) {
double capacity = 0, stored = 0;
for (ItemStack stack : mc.player.getArmorInventoryList()) {
if (stack.getItem() instanceof ItemMekaSuitArmor armor) {
capacity += armor.getMaxEnergy(stack);
stored += armor.getEnergy(stack);
}
}
if (capacity != 0) {
int x = event.getResolution().getScaledWidth() / 2 - 91;
int y = event.getResolution().getScaledHeight() - 59;
int length = (int) Math.round((stored / capacity) * 79);
GuiUtils.renderExtendedTexture(BAR, 2, 2, x, y, 81, 6);
blit(POWER_BAR, x + 1, y + 1, length, 4, 0, 0, length, 4, 79, 4);
mc.renderEngine.bindTexture(Gui.ICONS);
}
}
}

public static void blit(ResourceLocation pAtlasLocation, int pX, int pY, int pWidth, int pHeight, float pUOffset, float pVOffset, int pUWidth, int pVHeight, int pTextureWidth, int pTextureHeight) {
blit(pAtlasLocation, pX, pX + pWidth, pY, pY + pHeight, 0, pUWidth, pVHeight, pUOffset, pVOffset, pTextureWidth, pTextureHeight);
}


static void blit(ResourceLocation pAtlasLocation, int pX1, int pX2, int pY1, int pY2, int pBlitOffset, int pUWidth, int pVHeight, float pUOffset, float pVOffset, int pTextureWidth, int pTextureHeight) {
innerBlit(pAtlasLocation, pX1, pX2, pY1, pY2, pBlitOffset, (pUOffset + 0.0F) / (float) pTextureWidth, (pUOffset + (float) pUWidth) / (float) pTextureWidth, (pVOffset + 0.0F) / (float) pTextureHeight, (pVOffset + (float) pVHeight) / (float) pTextureHeight);
}

static void innerBlit(ResourceLocation pAtlasLocation, int pX1, int pX2, int pY1, int pY2, int pBlitOffset, float pMinU, float pMaxU, float pMinV, float pMaxV) {
Minecraft mc = Minecraft.getMinecraft();
mc.renderEngine.bindTexture(pAtlasLocation);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((float) pX1, (float) pY1, (float) pBlitOffset).tex(pMinU, pMinV).endVertex();
bufferbuilder.pos((float) pX1, (float) pY2, (float) pBlitOffset).tex(pMinU, pMaxV).endVertex();
bufferbuilder.pos((float) pX2, (float) pY2, (float) pBlitOffset).tex(pMaxU, pMaxV).endVertex();
bufferbuilder.pos((float) pX2, (float) pY1, (float) pBlitOffset).tex(pMaxU, pMinV).endVertex();
tessellator.draw();
}


}
12 changes: 10 additions & 2 deletions src/main/java/mekanism/common/Mekanism.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import mekanism.api.transmitters.DynamicNetwork.TransmittersAddedEvent;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.client.ClientTickHandler;
import mekanism.client.render.hud.MekaSuitEnergyLevel;
import mekanism.common.base.IModule;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.chunkloading.ChunkManager;
Expand Down Expand Up @@ -76,6 +77,7 @@
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeProvider;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
Expand Down Expand Up @@ -241,7 +243,7 @@ public static void registerSounds(RegistryEvent.Register<SoundEvent> event) {

@SubscribeEvent
public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
if (!MekanismConfig.current().mekce.BinRecipeClosed.val()){
if (!MekanismConfig.current().mekce.BinRecipeClosed.val()) {
event.getRegistry().register(new BinRecipe());
}
MekanismRecipe.addRecipes();
Expand Down Expand Up @@ -433,7 +435,7 @@ public void preInit(FMLPreInitializationEvent event) {

//Load configuration
proxy.loadConfiguration();
if (Loader.isModLoaded("mixinbooter") && Loader.isModLoaded("extrabotany")){
if (Loader.isModLoaded("mixinbooter") && Loader.isModLoaded("extrabotany")) {
MixinConfig.initConfig(configurationMixin.getConfigFile());
}

Expand Down Expand Up @@ -704,4 +706,10 @@ public void onWorldUnload(WorldEvent.Unload event) {
MekFakePlayer.releaseInstance(event.getWorld());
}
}

@SubscribeEvent
public static void onDrawScreenPre(RenderGameOverlayEvent.Pre event) {
MekaSuitEnergyLevel.onDrawScreenPre(event);
}

}
5 changes: 4 additions & 1 deletion src/main/java/mekanism/common/config/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ public class ClientConfig extends BaseConfig {

public final BooleanOption largeWindGeneratorisGlobalRenderer = new BooleanOption(this,"client","largeWindGeneratorisGlobalRenderer",true);

public final BooleanOption GasTOP = new BooleanOption(this, "mekce", "GasTop", true, "If true, the shutdown requires The One Probe item to sneak up to display the amount inside the gas tank");
public final BooleanOption GasTOP = new BooleanOption(this, "client", "GasTop", true, "If true, the shutdown requires The One Probe item to sneak up to display the amount inside the gas tank");

public final BooleanOption windGeneratorItem = new BooleanOption(this, "client", "WindGenerator", true, "Wind turbine blade rotation [item]");

public final BooleanOption windGeneratorRotating = new BooleanOption(this, "client", "windGeneratorRotating", true, "Wind turbine blade rotation [block]");
@Override
public void write(ByteBuf config) {
throw new UnsupportedOperationException("Client config shouldn't be synced");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mekanism/common/config/GeneratorsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class GeneratorsConfig extends BaseConfig {

public final IntOption reactorGeneratorInjectionRate = new IntOption(this, "generation",
"reactorGeneratorInjectionRate", 100, "The maximum injection rate of the fusion reactor needs to be set to a multiple of 2",2,Integer.MAX_VALUE);
public final BooleanOption windGeneratorItem = new BooleanOption(this, "generation", "WindGenerator", true, "Causes the item's wind turbine to rotate the blades");


public final IntOption ItemHohlraumMaxGas = new IntOption(this, "generation", "ItemHohlraumMaxGas", 10, "How many gases can be added to Hohlraum",1,Integer.MAX_VALUE);

Expand Down
Loading

0 comments on commit fa8e478

Please sign in to comment.