Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drastically reduce memory allocations from custom doors #14

Merged
merged 10 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empty to disable.
# LOCAL to test local config updates.
gtnh.settings.blowdryerTag = 0.2.0
gtnh.settings.blowdryerTag = 0.2.2

# Human-readable mod name, available for mcmod.info population.
modName = Malisis' Doors
Expand Down Expand Up @@ -41,19 +41,19 @@ developmentEnvironmentUserName = Developer

# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true

# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
enableGenericInjection = false
enableGenericInjection = true

# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
# If gradleTokenVersion is empty or missing, the field will not be present in the class.
generateGradleTokenClass =
generateGradleTokenClass = net.malisis.doors.Tags

# Name of the token containing the project's current version to generate/replace.
gradleTokenVersion = GRADLETOKEN_VERSION
gradleTokenVersion = VERSION

# [DEPRECATED] Mod ID replacement token.
gradleTokenModId =
Expand All @@ -70,7 +70,7 @@ gradleTokenGroupName =
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...]).
# Leave these properties empty to skip individual token replacements.
replaceGradleTokenInFile = MalisisDoors.java
replaceGradleTokenInFile =

# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/malisis/core/MalisisCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public boolean isUsernameIndex(String[] astring, int i) {
* @param params the params
*/
public void configCommand(ICommandSender sender, String[] params) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
if (FMLCommonHandler.instance()
.getEffectiveSide() == Side.SERVER) {
MalisisCore.log.warn("Can't open configuration GUI on a dedicated server.");
return;
}
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/net/malisis/core/MalisisCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package net.malisis.core;

import static net.malisis.doors.Tags.VERSION;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -27,7 +29,6 @@
import net.malisis.core.util.finiteliquid.FiniteLiquidRenderer;
import net.malisis.core.util.replacement.ReplacementTool;
import net.malisis.core.util.syncer.Syncer;
import net.malisis.doors.MalisisDoors;
import net.minecraft.client.Minecraft;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -55,18 +56,18 @@
* The Class MalisisCore.
*/
@Mod(
modid = MalisisCore.modid,
name = MalisisCore.modname,
version = MalisisCore.version,
dependencies = "required-after:gtnhlib@[0.2.4,)")
modid = MalisisCore.modid,
name = MalisisCore.modname,
version = MalisisCore.version,
dependencies = "required-after:gtnhlib@[0.2.4,)")
public class MalisisCore implements IMalisisMod {

/** Mod ID. */
public static final String modid = "malisiscore";
/** Mod name. */
public static final String modname = "Malisis Core";
/** Current version. */
public static final String version = MalisisDoors.version;
public static final String version = VERSION;
/** Url for the mod. */
public static final String url = "";
/** Path for the mod. */
Expand Down Expand Up @@ -159,7 +160,8 @@ public void preInit(FMLPreInitializationEvent event) {
GameRegistry.registerTileEntity(MultiBlockTileEntity.class, "MalisisCoreMultiBlockTileEntity");

MalisisNetwork.createMessages(event.getAsmData());
Syncer.get().discover(event.getAsmData());
Syncer.get()
.discover(event.getAsmData());
}

/**
Expand All @@ -171,8 +173,8 @@ public void preInit(FMLPreInitializationEvent event) {
public void init(FMLInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new MalisisCommand());

if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
new FiniteLiquidRenderer().registerFor(FiniteLiquid.class);
if (FMLCommonHandler.instance()
.getSide() == Side.CLIENT) new FiniteLiquidRenderer().registerFor(FiniteLiquid.class);
}

/**
Expand Down Expand Up @@ -229,10 +231,12 @@ public static void message(Object text, Object... data) {
String txt = text.toString();
if (text instanceof Object[]) txt = Arrays.deepToString((Object[]) text);
ChatComponentText msg = new ChatComponentText(StatCollector.translateToLocalFormatted(txt, data));
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
if (FMLCommonHandler.instance()
.getEffectiveSide() == Side.SERVER) {
MinecraftServer server = MinecraftServer.getServer();

if (server != null) server.getConfigurationManager().sendChatMsg(msg);
if (server != null) server.getConfigurationManager()
.sendChatMsg(msg);
} else {
if (Minecraft.getMinecraft() == null || Minecraft.getMinecraft().thePlayer == null) return;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/malisis/core/block/MalisisBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public AxisAlignedBB[] getBoundingBox(IBlockAccess world, int x, int y, int z, B

@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB mask, List list,
Entity entity) {
Entity entity) {
for (AxisAlignedBB aabb : getBoundingBox(world, x, y, z, BoundingBoxType.COLLISION)) {
if (aabb != null && mask.intersectsWith(aabb.offset(x, y, z))) list.add(aabb);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/malisis/core/client/gui/ClipArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public ClipArea(IClipable container, int clipPadding) {

public ClipArea(IClipable container, int clipPadding, boolean intersect) {
this(
container,
container.screenX() + clipPadding,
container.screenY() + clipPadding,
container.screenX() + container.getWidth() - clipPadding,
container.screenY() + container.getHeight() - clipPadding,
intersect);
container,
container.screenX() + clipPadding,
container.screenY() + clipPadding,
container.screenX() + container.getWidth() - clipPadding,
container.screenY() + container.getHeight() - clipPadding,
intersect);
}

public ClipArea(IClipable container, int x, int y, int X, int Y, boolean intersect) {
Expand Down
49 changes: 27 additions & 22 deletions src/main/java/net/malisis/core/client/gui/GuiRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ public void next() {
public void bindTexture(GuiTexture texture) {
if (texture == null || texture == currentTexture) return;

Minecraft.getMinecraft().getTextureManager().bindTexture(texture.getResourceLocation());
Minecraft.getMinecraft()
.getTextureManager()
.bindTexture(texture.getResourceLocation());
currentTexture = texture;
}

Expand Down Expand Up @@ -258,7 +260,7 @@ public void drawRectangle(int x, int y, int z, int width, int height, int color,
}

public void drawRectangle(float x, float y, float z, float width, float height, int color, int alpha,
boolean relative) {
boolean relative) {
if (relative && currentComponent != null) {
x += currentComponent.screenX();
y += currentComponent.screenY();
Expand Down Expand Up @@ -359,7 +361,7 @@ public void drawText(MalisisFont font, String text, float x, float y, float z, F
* @param relative true if the coordinates are relative to current component
*/
public void drawText(MalisisFont font, String text, float x, float y, float z, FontRenderOptions fro,
boolean relative) {
boolean relative) {
if (relative && currentComponent != null) {
x += currentComponent.screenX();
y += currentComponent.screenY();
Expand Down Expand Up @@ -427,15 +429,16 @@ public void drawItemStack(ItemStack itemStack, int x, int y, String label) {
* @param relative if true, coordinates are relative to current component
*/
public void drawItemStack(ItemStack itemStack, int x, int y, String label, EnumChatFormatting format,
boolean relative) {
boolean relative) {
if (itemStack == null) return;

if (relative && currentComponent != null) {
x += currentComponent.screenX();
y += currentComponent.screenY();
}

FontRenderer fontRenderer = itemStack.getItem().getFontRenderer(itemStack);
FontRenderer fontRenderer = itemStack.getItem()
.getFontRenderer(itemStack);
if (fontRenderer == null) fontRenderer = Minecraft.getMinecraft().fontRenderer;

if (label == null && (itemStack.stackSize > 1 || format != null)) label = Integer.toString(itemStack.stackSize);
Expand All @@ -447,18 +450,20 @@ public void drawItemStack(ItemStack itemStack, int x, int y, String label, EnumC
GL11.glEnable(GL12.GL_RESCALE_NORMAL);

itemRenderer.renderItemAndEffectIntoGUI(
fontRenderer,
Minecraft.getMinecraft().getTextureManager(),
itemStack,
x,
y);
fontRenderer,
Minecraft.getMinecraft()
.getTextureManager(),
itemStack,
x,
y);
itemRenderer.renderItemOverlayIntoGUI(
fontRenderer,
Minecraft.getMinecraft().getTextureManager(),
itemStack,
x,
y,
label);
fontRenderer,
Minecraft.getMinecraft()
.getTextureManager(),
itemStack,
x,
y,
label);

RenderHelper.disableStandardItemLighting();
GL11.glColor4f(1, 1, 1, 1);
Expand All @@ -480,12 +485,12 @@ public void renderPickedItemStack(ItemStack itemStack) {
itemRenderer.zLevel = 100;
t.startDrawingQuads();
drawItemStack(
itemStack,
mouseX - 8,
mouseY - 8,
null,
itemStack.stackSize == 0 ? EnumChatFormatting.YELLOW : null,
false);
itemStack,
mouseX - 8,
mouseY - 8,
null,
itemStack.stackSize == 0 ? EnumChatFormatting.YELLOW : null,
false);
t.draw();
itemRenderer.zLevel = 0;
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/malisis/core/client/gui/GuiTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public GuiTexture(BufferedImage image, String name) {
DynamicTexture dynTex = new DynamicTexture(image);
width = image.getWidth();
height = image.getHeight();
resourceLocation = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation(name, dynTex);
resourceLocation = Minecraft.getMinecraft()
.getTextureManager()
.getDynamicTextureLocation(name, dynTex);
}

/**
Expand Down Expand Up @@ -204,7 +206,9 @@ public GuiIcon getXResizableIcon(int x, int y, int width, int height, int side)
}

public void delete() {
Minecraft.getMinecraft().getTextureManager().deleteTexture(resourceLocation);
Minecraft.getMinecraft()
.getTextureManager()
.deleteTexture(resourceLocation);
}

@Override
Expand Down
Loading