Skip to content

Commit

Permalink
Implement Extra Hearts
Browse files Browse the repository at this point in the history
Format code
  • Loading branch information
matthewperiut committed Nov 2, 2023
1 parent 90a061a commit 239133b
Show file tree
Hide file tree
Showing 46 changed files with 465 additions and 561 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ org.gradle.parallel=true
loader_version=0.14.19-babric.1

# Mod Properties
mod_version = 0.5.1
mod_version = 0.5.2
maven_group = com.matthewperiut
archives_base_name = accessoryapi
stapi_version=e14ac1d
stapi_version=dcfa3d8

# Test properties
# https://maven.glass-launcher.net/#/releases/net/glasslauncher/mods/GlassConfigAPI
gcapi_version=1.1.6
# https://maven.glass-launcher.net/#/snapshots/net/glasslauncher/HowManyItems-Fabric-Unofficial
howmanyitems_version=5.0.13
howmanyitems_version=5.0.14
# https://github.com/calmilamsy/ModMenu/
modmenu_version=v1.8.5-beta.3
jankson_version=1.2.1
# https://github.com/matthewperiut/spc-babric
spc_version=0.2.0
spc_version=da7666e06f
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
import net.fabricmc.api.ModInitializer;
import net.glasslauncher.mods.api.gcapi.api.GConfig;

public class AccessoryAPI implements ModInitializer
{
public class AccessoryAPI implements ModInitializer {
public static String MOD_ID = "accessoryapi";

@GConfig(value = "config", visibleName = "Accessory API Config")
public static AccessoryAPIConfigFields config = new AccessoryAPIConfigFields();

@Override
public void onInitialize()
{
public void onInitialize() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import net.fabricmc.api.ClientModInitializer;

public class AccessoryAPIClient implements ClientModInitializer
{
public class AccessoryAPIClient implements ClientModInitializer {
public static boolean capeEnabled;

@Override
public void onInitializeClient()
{
public void onInitializeClient() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import net.minecraft.entity.player.PlayerBase;
import net.minecraft.item.ItemInstance;

public interface Accessory extends TickableInArmorSlot
{
public interface Accessory extends TickableInArmorSlot {
/**
* Determines what accessory slots your item goes to
*
Expand All @@ -13,11 +12,9 @@ public interface Accessory extends TickableInArmorSlot
*/
String[] getAccessoryTypes(ItemInstance item);

default void onAccessoryAdded(PlayerBase player, ItemInstance accessory)
{
default void onAccessoryAdded(PlayerBase player, ItemInstance accessory) {
}

default void onAccessoryRemoved(PlayerBase player, ItemInstance accessory)
{
default void onAccessoryRemoved(PlayerBase player, ItemInstance accessory) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,49 @@
import java.util.HashMap;
import java.util.Map;

public class AccessoryRegister
{
private static final Map<String, Integer> defaultTextureMap = new HashMap<>()
{{
public class AccessoryRegister {
private static final Map<String, Integer> defaultTextureMap = new HashMap<>() {{
put("pendant", 0);
put("cape", 1);
put("shield", 2);
put("ring", 3);
put("gloves", 4);
put("misc", 5);
}};
private static final String defaultTexture = "/assets/accessoryapi/inventory.png";
private static final int DEFAULT_ACCESSORY_Y = 72;

private static int getDefaultTextureId(final String accessoryType)
{
private static int getDefaultTextureId(final String accessoryType) {
return defaultTextureMap.getOrDefault(accessoryType, -1);
}

private static final String defaultTexture = "/assets/accessoryapi/inventory.png";

private static final int DEFAULT_ACCESSORY_Y = 72;

public static void add(String accessoryType)
{
public static void add(String accessoryType) {
int d = getDefaultTextureId(accessoryType);
if (d != -1)
AccessorySlotStorage.slotInfo.add(new AccessorySlotInfo(accessoryType, defaultTexture, d * 16, DEFAULT_ACCESSORY_Y));
else
AccessorySlotStorage.slotInfo.add(new AccessorySlotInfo(accessoryType));
}

public static void add(String accessoryType, String texture, int texPosX, int texPosY)
{
public static void add(String accessoryType, String texture, int texPosX, int texPosY) {
AccessorySlotStorage.slotInfo.add(new AccessorySlotInfo(accessoryType, texture, texPosX, texPosY));
}

public static void add(String accessoryType, int h, int v)
{
public static void add(String accessoryType, int h, int v) {
int d = getDefaultTextureId(accessoryType);
if (d != -1)
AccessorySlotStorage.slotInfo.add(new AccessorySlotInfo(accessoryType, defaultTexture, d * 16, DEFAULT_ACCESSORY_Y, h, v));
else
AccessorySlotStorage.slotInfo.add(new AccessorySlotInfo(accessoryType, h, v));
}

public static void add(String accessoryType, String texture, int texPosX, int texPosY, int h, int v)
{
public static void add(String accessoryType, String texture, int texPosX, int texPosY, int h, int v) {
AccessorySlotStorage.slotInfo.add(new AccessorySlotInfo(accessoryType, texture, texPosX, texPosY, h, v));
}

public static int getNumberOfType(String accessoryType)
{
public static int getNumberOfType(String accessoryType) {
int count = 0;
for (AccessorySlotInfo slot : AccessorySlotStorage.slotInfo)
{
for (AccessorySlotInfo slot : AccessorySlotStorage.slotInfo) {
if (slot.type.equals(accessoryType))
count++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.matthewperiut.accessoryapi.api;

public interface PlayerExtraHP {
int getExtraHP();

void setExtraHP(int extraHP);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import net.minecraft.entity.player.PlayerBase;
import net.minecraft.item.ItemInstance;

public interface TickableInArmorSlot
{
default ItemInstance tickWhileWorn(PlayerBase player, ItemInstance itemInstance)
{
public interface TickableInArmorSlot {
default ItemInstance tickWhileWorn(PlayerBase player, ItemInstance itemInstance) {
return itemInstance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import java.util.ArrayList;
import java.util.Arrays;

public class AccessoryAccess
{
public class AccessoryAccess {

/**
* @param player The player you are checking.
* @return The full array of the player's accessories.
*/
public static ItemInstance[] getAccessories(PlayerBase player)
{
public static ItemInstance[] getAccessories(PlayerBase player) {
return Arrays.copyOfRange(player.inventory.armour, AccessoryAPI.config.armorOffset, player.inventory.armour.length);
}

Expand All @@ -26,8 +24,7 @@ public static ItemInstance[] getAccessories(PlayerBase player)
* @param slot The index of the accessory inventory you want to check, DO NOT offset for armour slots.
* @return The accessory in the specified slot.
*/
public static ItemInstance getAccessory(PlayerBase player, int slot)
{
public static ItemInstance getAccessory(PlayerBase player, int slot) {
return getAccessories(player)[slot];
}

Expand All @@ -36,8 +33,7 @@ public static ItemInstance getAccessory(PlayerBase player, int slot)
* @param slot The slot you are placing the accessory in.
* @param item The item you would like to place.
*/
public static void setAccessory(PlayerBase player, int slot, ItemInstance item)
{
public static void setAccessory(PlayerBase player, int slot, ItemInstance item) {
player.inventory.armour[slot + AccessoryAPI.config.armorOffset] = item;
}

Expand All @@ -46,15 +42,11 @@ public static void setAccessory(PlayerBase player, int slot, ItemInstance item)
* @param type The type of accessory you are looking for.
* @return The array of the player's accessories that match the type.
*/
public static ItemInstance[] getAccessories(PlayerBase player, String type)
{
public static ItemInstance[] getAccessories(PlayerBase player, String type) {
var foundItems = new ArrayList<ItemInstance>();
for (ItemInstance item : getAccessories(player))
{
if (item != null && item.getType() instanceof Accessory accessory)
{
if (Arrays.asList(accessory.getAccessoryTypes(item)).contains(type))
{
for (ItemInstance item : getAccessories(player)) {
if (item != null && item.getType() instanceof Accessory accessory) {
if (Arrays.asList(accessory.getAccessoryTypes(item)).contains(type)) {
foundItems.add(item);
}
}
Expand All @@ -72,12 +64,9 @@ public static ItemInstance[] getAccessories(PlayerBase player, String type)
* @param itemType The item you are looking for.
* @return Whether the player has any items that match the provided item type.
*/
public static boolean hasAccessory(PlayerBase player, ItemBase itemType)
{
for (ItemInstance item : getAccessories(player))
{
if (item != null && item.getType() == itemType)
{
public static boolean hasAccessory(PlayerBase player, ItemBase itemType) {
for (ItemInstance item : getAccessories(player)) {
if (item != null && item.getType() == itemType) {
return true;
}
}
Expand All @@ -89,14 +78,10 @@ public static boolean hasAccessory(PlayerBase player, ItemBase itemType)
* @param type The type of accessory you are looking for.
* @return Whether the player has any accessories in their inventory that match the type.
*/
public static boolean hasAnyAccessoriesOfType(PlayerBase player, String type)
{
for (ItemInstance item : getAccessories(player))
{
if (item != null && item.getType() instanceof Accessory accessory)
{
if (Arrays.asList(accessory.getAccessoryTypes(item)).contains(type))
{
public static boolean hasAnyAccessoriesOfType(PlayerBase player, String type) {
for (ItemInstance item : getAccessories(player)) {
if (item != null && item.getType() instanceof Accessory accessory) {
if (Arrays.asList(accessory.getAccessoryTypes(item)).contains(type)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import net.minecraft.entity.player.PlayerBase;
import net.minecraft.item.ItemInstance;

public interface AccessoryRenderer
{
AccessoryRenderer NULL_RENDERER = new AccessoryRenderer() {};
default void renderThirdPerson(PlayerBase player, PlayerRenderer renderer, ItemInstance itemInstance, double x, double y, double z, float h, float v)
{
public interface AccessoryRenderer {
AccessoryRenderer NULL_RENDERER = new AccessoryRenderer() {
};

default void renderThirdPerson(PlayerBase player, PlayerRenderer renderer, ItemInstance itemInstance, double x, double y, double z, float h, float v) {
}

default void renderFirstPerson(PlayerBase player, PlayerRenderer renderer, ItemInstance itemInstance)
{
default void renderFirstPerson(PlayerBase player, PlayerRenderer renderer, ItemInstance itemInstance) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import java.util.Optional;

public interface HasCustomRenderer
{
public interface HasCustomRenderer {
/**
* Used to provide the accessory renderer variable that you initialized in constructRenderer
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import net.minecraft.item.ItemInstance;
import org.lwjgl.opengl.GL11;

public class RenderingHelper
{
public static void beforeBiped(PlayerBase player, PlayerRenderer playerRenderer, Biped model, double x, double y, double z, float h, float v)
{
public class RenderingHelper {
public static void beforeBiped(PlayerBase player, PlayerRenderer playerRenderer, Biped model, double x, double y, double z, float h, float v) {
final ItemInstance itemInstance = player.getHeldItem();
model.field_629 = (itemInstance != null);
model.field_630 = player.method_1373();
Expand All @@ -37,8 +35,7 @@ public static void beforeBiped(PlayerBase player, PlayerRenderer playerRenderer,
model.setAngles(f8, f7, f5, f3 - f2, f4, f6);
}

public static void afterBiped(Biped model)
{
public static void afterBiped(Biped model) {
GL11.glDisable(3042);
GL11.glDisable(32826);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
import net.minecraft.util.maths.MathHelper;
import org.lwjgl.opengl.GL11;

public class CapeRenderer extends ConfigurableRenderer
{
public class CapeRenderer extends ConfigurableRenderer {
private static final Biped model = new Biped(0.0f);

public CapeRenderer(String texture)
{
public CapeRenderer(String texture) {
super(texture);
}

@Override
public void renderThirdPerson(PlayerBase player, PlayerRenderer renderer, ItemInstance itemInstance, double x, double y, double z, float h, float v)
{
public void renderThirdPerson(PlayerBase player, PlayerRenderer renderer, ItemInstance itemInstance, double x, double y, double z, float h, float v) {
AccessoryAPIClient.capeEnabled = false;

RenderingHelper.beforeBiped(player, renderer, model, x, y, z, h, v);
Expand All @@ -37,24 +34,20 @@ public void renderThirdPerson(PlayerBase player, PlayerRenderer renderer, ItemIn
final double d4 = MathHelper.sin(f2 * 3.141593f / 180.0f);
final double d5 = -MathHelper.cos(f2 * 3.141593f / 180.0f);
float f3 = (float) d2 * 10.0f;
if (f3 < -6.0f)
{
if (f3 < -6.0f) {
f3 = -6.0f;
}
if (f3 > 32.0f)
{
if (f3 > 32.0f) {
f3 = 32.0f;
}
float f4 = (float) (d * d4 + d3 * d5) * 100.0f;
final float f5 = (float) (d * d5 - d3 * d4) * 100.0f;
if (f4 < 0.0f)
{
if (f4 < 0.0f) {
f4 = 0.0f;
}
final float f6 = player.field_524 + (player.field_525 - player.field_524) * xAsFloat;
f3 += MathHelper.sin((player.field_1634 + (player.field_1635 - player.field_1634) * xAsFloat) * 6.0f) * 32.0f * f6;
if (player.method_1373())
{
if (player.method_1373()) {
f3 += 25.0f;
}
GL11.glRotatef(6.0f + f4 / 2.0f + f3, 1.0f, 0.0f, 0.0f);
Expand Down
Loading

0 comments on commit 239133b

Please sign in to comment.