Skip to content

Commit

Permalink
Working on Migrating Info Lines data out of a giant singleton Function
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Jan 30, 2025
1 parent d4eab0f commit 79bdbc4
Show file tree
Hide file tree
Showing 12 changed files with 999 additions and 746 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod_file_name = minihud-fabric
mod_version = 0.34.999-dev

# Required malilib version
malilib_version = d41bb20e57
malilib_version = c475e7106a

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 25w05a
Expand Down
247 changes: 138 additions & 109 deletions src/main/java/fi/dy/masa/minihud/config/InfoToggle.java

Large diffs are not rendered by default.

407 changes: 55 additions & 352 deletions src/main/java/fi/dy/masa/minihud/event/RenderHandler.java

Large diffs are not rendered by default.

111 changes: 106 additions & 5 deletions src/main/java/fi/dy/masa/minihud/info/InfoLine.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,109 @@
package fi.dy.masa.minihud.info;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import fi.dy.masa.malilib.util.StringUtils;
import fi.dy.masa.minihud.Reference;
import fi.dy.masa.minihud.config.InfoToggle;
import fi.dy.masa.minihud.data.EntitiesDataManager;
import fi.dy.masa.minihud.data.HudDataManager;
import fi.dy.masa.minihud.util.DataStorage;

public abstract class InfoLine
{
public @Nullable Text parse(@Nonnull Context ctx)
protected static final String REMAINING_KEY = Reference.MOD_ID+".info_line.remaining";
private final InfoToggle type;

public InfoLine(InfoToggle type)
{
this.type = type;
}

public InfoToggle getType()
{
return this.type;
}

public HudDataManager getHudData() { return HudDataManager.getInstance(); }

public EntitiesDataManager getEntData() { return EntitiesDataManager.getInstance(); }

public DataStorage getData() { return DataStorage.getInstance(); }

public @Nullable Entry parse(@Nonnull Context ctx)
{
return null;
}

public @Nullable Entry parseNbt(@Nonnull World world, @Nonnull EntityType<?> entityType, @Nonnull NbtCompound nbt)
{
return null;
}

public @Nullable Entry parseNbt(@Nonnull World world, @Nonnull BlockEntityType<?> beType, @Nonnull NbtCompound nbt)
{
return null;
}

public @Nullable Entry parseEnt(@Nonnull World world, @Nonnull Entity ent)
{
return null;
}

public @Nullable Entry parseBlockEnt(@Nonnull World world, @Nonnull BlockEntity be)
{
return null;
}

public @Nullable Entry parseBlock(@Nonnull World world, @Nonnull Block block)
{
return null;
}

public @Nullable Entry format(@Nonnull String str, Object... args)
{
return new Entry(str, args);
}

public @Nullable Entry translate(@Nonnull String str, Object... args)
{
Entry ent = new Entry(StringUtils.translate(str, args));
ent.setTranslated();
return ent;
}

public record Context(@Nonnull World world, @Nullable Entity ent, @Nullable BlockEntity be, @Nullable Block block, NbtCompound nbt)
{
public boolean hasLivingEntity()
public boolean hasEntity()
{
return this.ent != null && this.ent instanceof Entity;
}

public boolean hasLiving()
{
return this.ent != null && this.ent instanceof LivingEntity;
}

public @Nullable LivingEntity living()
{
if (this.hasLiving())
{
return (LivingEntity) this.ent;
}

return null;
}

public boolean hasBlockEntity()
{
return this.be != null && this.be instanceof BlockEntity;
Expand All @@ -40,7 +120,28 @@ public boolean hasNbt()
}
}

public record Text(@Nonnull String format, @Nullable Object... args)
public record Entry(@Nonnull String format, @Nullable Object... args)
{
private static boolean translated = false;

void setTranslated()
{
translated = true;
}

public boolean isEmpty()
{
return this.format.isEmpty();
}

public boolean hasArgs()
{
return this.args != null && this.args.length > 0;
}

public boolean isTranslated()
{
return translated;
}
}
}
Loading

0 comments on commit 79bdbc4

Please sign in to comment.