Skip to content

Commit

Permalink
Update mod to 1.20.5/1.20.6 codebase.
Browse files Browse the repository at this point in the history
This includes another rework to how the text particles work. The mod API has been updated to work with the fact that EntityGroups have been removed from the code.
  • Loading branch information
Provismet committed May 9, 2024
1 parent c2596f9 commit 3570cdd
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 206 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ To access the settings menu you will need:
This mod can be used as a dependency via [Jitpack](https://jitpack.io/#Provismet/ProviHealth).

Example entrypoint usage:
This entrypoint initialiser is what the mod uses to set its own values for the vanilla Entity Groups.
This entrypoint initialiser is what the mod uses to set its own values for vanilla entity tags.
```java
public class SelfApiHook implements ProviHealthApi {
@Override
public void onInitialize () {
this.registerIcon(EntityGroup.AQUATIC, Items.COD);
this.registerIcon(EntityGroup.ARTHROPOD, Items.COBWEB);
this.registerIcon(EntityGroup.ILLAGER, Items.IRON_AXE);
this.registerIcon(EntityGroup.UNDEAD, Items.ROTTEN_FLESH);

this.registerPortrait(EntityGroup.AQUATIC, ProviHealthClient.identifier("textures/gui/healthbars/aquatic.png"));
this.registerPortrait(EntityGroup.ARTHROPOD, ProviHealthClient.identifier("textures/gui/healthbars/arthropod.png"));
this.registerPortrait(EntityGroup.ILLAGER, ProviHealthClient.identifier("textures/gui/healthbars/illager.png"));
this.registerPortrait(EntityGroup.UNDEAD, ProviHealthClient.identifier("textures/gui/healthbars/undead.png"));
this.registerIcon(EntityTypeTags.AQUATIC, Items.COD, DEFAULT_PRIORITY + 1);
this.registerIcon(EntityTypeTags.ARTHROPOD, Items.COBWEB, DEFAULT_PRIORITY + 2);
this.registerIcon(EntityTypeTags.ILLAGER, Items.IRON_AXE, DEFAULT_PRIORITY);
this.registerIcon(EntityTypeTags.UNDEAD, Items.ROTTEN_FLESH, DEFAULT_PRIORITY + 3);

this.registerPortrait(EntityTypeTags.AQUATIC, ProviHealthClient.identifier("textures/gui/healthbars/aquatic.png"), DEFAULT_PRIORITY + 1);
this.registerPortrait(EntityTypeTags.ARTHROPOD, ProviHealthClient.identifier("textures/gui/healthbars/arthropod.png"), DEFAULT_PRIORITY + 2);
this.registerPortrait(EntityTypeTags.ILLAGER, ProviHealthClient.identifier("textures/gui/healthbars/illager.png"), DEFAULT_PRIORITY);
this.registerPortrait(EntityTypeTags.UNDEAD, ProviHealthClient.identifier("textures/gui/healthbars/undead.png"), DEFAULT_PRIORITY + 3);
}

}
Expand Down
84 changes: 42 additions & 42 deletions src/main/java/com/provismet/provihealth/api/ProviHealthApi.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.provismet.provihealth.api;

import net.minecraft.registry.tag.TagKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.provismet.provihealth.hud.BorderRegistry;

import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -20,12 +20,12 @@ public interface ProviHealthApi {
*
* The icon takes the form of an item.
*
* @param entityGroup The entity group.
* @param tag The entity type tag.
* @param item The item to serve as the icon.
* @return Whether or not the registry succeeded. This is false if the entity group already has an icon.
* @return Whether or not the registry succeeded. This is false if a higher priority icon already exists.
*/
public default boolean registerIcon (EntityGroup entityGroup, @NotNull Item item) {
return this.registerIcon(entityGroup, item, false);
public default boolean registerIcon (TagKey<EntityType<?>> tag, @NotNull Item item) {
return this.registerIcon(tag, item, 0);
}

/**
Expand All @@ -34,12 +34,12 @@ public default boolean registerIcon (EntityGroup entityGroup, @NotNull Item item
*
* The icon takes the form of an item.
*
* @param entityGroup The entity group.
* @param tag The entity type tag.
* @param item The item to serve as the icon.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
* @return Whether or not the registry succeeded. This is false if a higher priority icon already exists.
*/
public default boolean registerIcon (EntityGroup entityGroup, @NotNull Item item, boolean force) {
return BorderRegistry.registerItem(entityGroup, item.getDefaultStack(), force);
public default boolean registerIcon (TagKey<EntityType<?>> tag, @NotNull Item item, int priority) {
return BorderRegistry.registerItem(tag, item.getDefaultStack(), priority);
}

/**
Expand All @@ -50,10 +50,10 @@ public default boolean registerIcon (EntityGroup entityGroup, @NotNull Item item
*
* @param type The entity type.
* @param item The item that will act as the icon for this entity type.
* @return Whether or not the registry succeeded. This is false if the entity type already has an icon.
* @return Whether or not the registry succeeded. This is false if a higher priority icon already exists.
*/
public default boolean registerIcon (EntityType<?> type, @NotNull Item item) {
return this.registerIcon(type, item, false);
return this.registerIcon(type, item, 0);
}

/**
Expand All @@ -64,11 +64,11 @@ public default boolean registerIcon (EntityType<?> type, @NotNull Item item) {
*
* @param type The entity type.
* @param item The item that will act as the icon for this entity type.
* @param force Whether or not this registration should override any pre-existing icon for the same entity type.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
* @param priority The priority level of this registration. Higher priority icons will override lower priority icons.
* @return Whether or not the registry succeeded. This is false if a higher priority icon already exists.
*/
public default boolean registerIcon (EntityType<?> type, @NotNull Item item, boolean force) {
return BorderRegistry.registerItem(type, item.getDefaultStack(), force);
public default boolean registerIcon (EntityType<?> type, @NotNull Item item, int priority) {
return BorderRegistry.registerItem(type, item.getDefaultStack(), priority);
}


Expand All @@ -82,10 +82,10 @@ public default boolean registerIcon (EntityType<?> type, @NotNull Item item, boo
*
* @param type The entity type.
* @param item The item stack that will act as the icon for this entity type.
* @return Whether or not the registry succeeded. This is false if the entity type already has an icon.
* @return Whether or not the registry succeeded. This is false if a higher priority icon already exists.
*/
public default boolean registerIconStack (EntityType<?> type, @Nullable ItemStack item) {
return this.registerIconStack(type, item, false);
return this.registerIconStack(type, item, 0);
}

/**
Expand All @@ -98,11 +98,11 @@ public default boolean registerIconStack (EntityType<?> type, @Nullable ItemStac
*
* @param type The entity type.
* @param item The item stack that will act as the icon for this entity type.
* @param force Whether or not this registration should override any pre-existing icon for the same entity type.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
* @param priority The priority level of this registration. Higher priority icons will override lower priority icons.
* @return Whether or not the registry succeeded. This is false if a higher priority icon already exists.
*/
public default boolean registerIconStack (EntityType<?> type, @Nullable ItemStack item, boolean force) {
return BorderRegistry.registerItem(type, item, force);
public default boolean registerIconStack (EntityType<?> type, @Nullable ItemStack item, int priority) {
return BorderRegistry.registerItem(type, item, priority);
}

/**
Expand All @@ -115,10 +115,10 @@ public default boolean registerIconStack (EntityType<?> type, @Nullable ItemStac
*
* @param type The entity group.
* @param item The item stack that will act as the icon for this entity group.
* @return Whether or not the registry succeeded. This is false if the entity group already has an icon.
* @return Whether or not the registry succeeded. This is false if a higher priority icon already exists.
*/
public default boolean registerIconStack (EntityGroup type, @Nullable ItemStack item) {
return this.registerIconStack(type, item, false);
public default boolean registerIconStack (TagKey<EntityType<?>> type, @Nullable ItemStack item) {
return this.registerIconStack(type, item, 0);
}

/**
Expand All @@ -131,11 +131,11 @@ public default boolean registerIconStack (EntityGroup type, @Nullable ItemStack
*
* @param type The entity group.
* @param item The item stack that will act as the icon for this entity group.
* @param force Whether or not this registration should override any pre-existing icon for the same entity group.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
* @param priority The priority level of this registration. Higher priority icons will override lower priority icons.
* @return Whether or not the registry succeeded. This is false if a higher priority icon already exists.
*/
public default boolean registerIconStack (EntityGroup type, @Nullable ItemStack item, boolean force) {
return BorderRegistry.registerItem(type, item, force);
public default boolean registerIconStack (TagKey<EntityType<?>> type, @Nullable ItemStack item, int priority) {
return BorderRegistry.registerItem(type, item, priority);
}

/**
Expand All @@ -147,12 +147,12 @@ public default boolean registerIconStack (EntityGroup type, @Nullable ItemStack
* If your mod introduces new entity groups, use this method to define a portrait for them.
* The image for the frame must be 96x48 in size. With the foreground (48x48) on the left and the background (48x48) on the right.
*
* @param entityGroup The entity group.
* @param tag The entity group.
* @param resource A full resource path (modid:textures/gui/etc/file.png) to the texture.
* @return Whether or not the registry succeeded. This is false if the entity group already has a portrait.
* @return Whether or not the registry succeeded. This is false if a higher priority portrait already exists.
*/
public default boolean registerPortrait (EntityGroup entityGroup, @Nullable Identifier resource) {
return this.registerPortrait(entityGroup, resource, false);
public default boolean registerPortrait (TagKey<EntityType<?>> tag, @Nullable Identifier resource) {
return this.registerPortrait(tag, resource, 0);
}

/**
Expand All @@ -166,11 +166,11 @@ public default boolean registerPortrait (EntityGroup entityGroup, @Nullable Iden
*
* @param entityGroup The entity group.
* @param resource A full resource path (modid:textures/gui/etc/file.png) to the texture.
* @param force Whether or not this registration should override any pre-existing portrait for the same entity group.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
* @param priority The priority level of this registration. Higher priority portraits will override lower priority portraits.
* @return Whether or not the registry succeeded. This is false if a higher priority portrait already exists.
*/
public default boolean registerPortrait (EntityGroup entityGroup, @Nullable Identifier resource, boolean force) {
return BorderRegistry.registerBorder(entityGroup, resource, force);
public default boolean registerPortrait (TagKey<EntityType<?>> entityGroup, @Nullable Identifier resource, int priority) {
return BorderRegistry.registerBorder(entityGroup, resource, priority);
}

/**
Expand All @@ -185,10 +185,10 @@ public default boolean registerPortrait (EntityGroup entityGroup, @Nullable Iden
*
* @param type The entity type.
* @param resource A full resource path (modid:textures/gui/etc/file.png) to the texture.
* @return Whether or not the registry succeeded. This is false if the entity type already has a portrait.
* @return Whether or not the registry succeeded. This is false if a higher priority portrait already exists.
*/
public default boolean registerPortrait (EntityType<?> type, @Nullable Identifier resource) {
return this.registerPortrait(type, resource, false);
return this.registerPortrait(type, resource, 0);
}

/**
Expand All @@ -203,10 +203,10 @@ public default boolean registerPortrait (EntityType<?> type, @Nullable Identifie
*
* @param type The entity type.
* @param resource A full resource path (modid:textures/gui/etc/file.png) to the texture.
* @param force Whether or not this registration should override any pre-existing portrait for the same entity type.
* @return Whether or not the registry succeeded. Expect this to be true when force = true.
* @param priority The priority level of this registration. Higher priority portraits will override lower priority portraits.
* @return Whether or not the registry succeeded. This is false if a higher priority portrait already exists.
*/
public default boolean registerPortrait (EntityType<?> type, @Nullable Identifier resource, boolean force) {
return BorderRegistry.registerBorder(type, resource, force);
public default boolean registerPortrait (EntityType<?> type, @Nullable Identifier resource, int priority) {
return BorderRegistry.registerBorder(type, resource, priority);
}
}
22 changes: 12 additions & 10 deletions src/main/java/com/provismet/provihealth/compat/SelfApiHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
import com.provismet.provihealth.ProviHealthClient;
import com.provismet.provihealth.api.ProviHealthApi;

import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Items;
import net.minecraft.registry.tag.EntityTypeTags;

public class SelfApiHook implements ProviHealthApi {
private static final int DEFAULT_PRIORITY = -999;

@Override
public void onInitialize () {
this.registerIcon(EntityGroup.AQUATIC, Items.COD);
this.registerIcon(EntityGroup.ARTHROPOD, Items.COBWEB);
this.registerIcon(EntityGroup.ILLAGER, Items.IRON_AXE);
this.registerIcon(EntityGroup.UNDEAD, Items.ROTTEN_FLESH);
this.registerIcon(EntityTypeTags.AQUATIC, Items.COD, DEFAULT_PRIORITY + 1);
this.registerIcon(EntityTypeTags.ARTHROPOD, Items.COBWEB, DEFAULT_PRIORITY + 2);
this.registerIcon(EntityTypeTags.ILLAGER, Items.IRON_AXE, DEFAULT_PRIORITY);
this.registerIcon(EntityTypeTags.UNDEAD, Items.ROTTEN_FLESH, DEFAULT_PRIORITY + 3);

this.registerPortrait(EntityGroup.AQUATIC, ProviHealthClient.identifier("textures/gui/healthbars/aquatic.png"));
this.registerPortrait(EntityGroup.ARTHROPOD, ProviHealthClient.identifier("textures/gui/healthbars/arthropod.png"));
this.registerPortrait(EntityGroup.ILLAGER, ProviHealthClient.identifier("textures/gui/healthbars/illager.png"));
this.registerPortrait(EntityGroup.UNDEAD, ProviHealthClient.identifier("textures/gui/healthbars/undead.png"));
this.registerPortrait(EntityTypeTags.AQUATIC, ProviHealthClient.identifier("textures/gui/healthbars/aquatic.png"), DEFAULT_PRIORITY + 1);
this.registerPortrait(EntityTypeTags.ARTHROPOD, ProviHealthClient.identifier("textures/gui/healthbars/arthropod.png"), DEFAULT_PRIORITY + 2);
this.registerPortrait(EntityTypeTags.ILLAGER, ProviHealthClient.identifier("textures/gui/healthbars/illager.png"), DEFAULT_PRIORITY);
this.registerPortrait(EntityTypeTags.UNDEAD, ProviHealthClient.identifier("textures/gui/healthbars/undead.png"), DEFAULT_PRIORITY + 3);
}

}
5 changes: 1 addition & 4 deletions src/main/java/com/provismet/provihealth/config/Options.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.provismet.provihealth.config;

import net.fabricmc.fabric.api.tag.convention.v1.ConventionalEntityTypeTags;
import net.fabricmc.fabric.api.tag.convention.v2.ConventionalEntityTypeTags;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
Expand Down Expand Up @@ -91,7 +91,6 @@ public class Options {
public static boolean compatInHUD = false;
public static HUDPortraitCompatMode HUDCompat = HUDPortraitCompatMode.STANDARD;

@SuppressWarnings("resource")
public static boolean shouldRenderHealthFor (LivingEntity livingEntity) {
if (blacklist.contains(EntityType.getId(livingEntity.getType()).toString())) return false;
if (livingEntity.distanceTo(MinecraftClient.getInstance().player) > Options.maxRenderDistance) return false;
Expand Down Expand Up @@ -454,8 +453,6 @@ else if (livingEntity.hasVehicle()) {
return false;

case ALWAYS_SHOW:
return true;

default:
return true;
}
Expand Down
Loading

0 comments on commit 3570cdd

Please sign in to comment.