Skip to content

Commit

Permalink
improv: Change accessories to hold their own accessory slot identifie…
Browse files Browse the repository at this point in the history
…rs (#2154)
  • Loading branch information
Alexandra-Myers authored May 14, 2024
1 parent 2a85ab4 commit cfb59d1
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.aetherteam.aether.block.dispenser;

import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.AetherTags;
import com.aetherteam.aether.attachment.AetherDataAttachments;
import com.aetherteam.aether.entity.projectile.weapon.HammerProjectile;
Expand All @@ -9,9 +8,8 @@
import com.aetherteam.aether.inventory.menu.AccessoriesMenu;
import com.aetherteam.aether.item.AetherItems;
import com.aetherteam.aether.item.accessories.AccessoryItem;
import com.aetherteam.aether.item.accessories.cape.CapeItem;
import com.aetherteam.aether.item.accessories.SlotIdentifierHolder;
import com.aetherteam.aether.item.accessories.gloves.GlovesItem;
import com.aetherteam.aether.item.accessories.miscellaneous.ShieldOfRepulsionItem;
import com.aetherteam.aether.item.accessories.pendant.PendantItem;
import com.aetherteam.aether.item.miscellaneous.bucket.SkyrootBucketItem;
import net.minecraft.Util;
Expand Down Expand Up @@ -105,15 +103,9 @@ public static boolean dispenseAccessory(BlockSource blockSource, ItemStack stack
CuriosApi.getCurio(itemStack).flatMap(curio -> CuriosApi.getCuriosInventory(livingEntity)).ifPresent(handler -> {
if (itemStack.is(AetherTags.Items.ACCESSORIES)) {
String identifier = "";
if (itemStack.getItem() instanceof GlovesItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "hands" : "aether_gloves";
} else if (itemStack.getItem() instanceof PendantItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "necklace" : "aether_pendant";
} else if (itemStack.getItem() instanceof CapeItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "back" : "aether_cape";
} else if (itemStack.getItem() instanceof ShieldOfRepulsionItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "body" : "aether_shield";
}
if (itemStack.getItem() instanceof SlotIdentifierHolder slotIdentifierHolder)
identifier = slotIdentifierHolder.getIdentifier();

Optional<ICurioStacksHandler> stacksHandler = handler.getStacksHandler(identifier);
if (stacksHandler.isPresent()) {
IDynamicStackHandler stackHandler = stacksHandler.get().getCosmeticStacks();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.aetherteam.aether.client.renderer.accessory.layer;

import com.aetherteam.aether.Aether;
import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.client.renderer.AetherModelLayers;
import com.aetherteam.aether.client.renderer.accessory.model.CapeModel;
import com.aetherteam.aether.item.accessories.cape.CapeItem;
Expand Down Expand Up @@ -43,7 +42,7 @@ public ArmorStandCapeLayer(RenderLayerParent<ArmorStand, ArmorStandModel> render

@Override
public void render(PoseStack poseStack, MultiBufferSource buffer, int packedLight, ArmorStand livingEntity, float limbSwing, float limbSwingAmount, float partialTick, float ageInTicks, float netHeadYaw, float headPitch) {
String identifier = AetherConfig.COMMON.use_curios_menu.get() ? "back" : "aether_cape";
String identifier = CapeItem.getIdentifierStatic();
Optional<ICuriosItemHandler> lazyHandler = CuriosApi.getCuriosInventory(livingEntity);
if (lazyHandler.isPresent()) {
ICuriosItemHandler handler = lazyHandler.get();
Expand Down
26 changes: 10 additions & 16 deletions src/main/java/com/aetherteam/aether/event/hooks/EntityHooks.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.aetherteam.aether.event.hooks;

import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.AetherTags;
import com.aetherteam.aether.attachment.AetherDataAttachments;
import com.aetherteam.aether.block.AetherBlocks;
Expand All @@ -15,6 +14,7 @@
import com.aetherteam.aether.entity.projectile.crystal.ThunderCrystal;
import com.aetherteam.aether.item.AetherItems;
import com.aetherteam.aether.item.accessories.AccessoryItem;
import com.aetherteam.aether.item.accessories.SlotIdentifierHolder;
import com.aetherteam.aether.item.accessories.cape.CapeItem;
import com.aetherteam.aether.item.accessories.gloves.GlovesItem;
import com.aetherteam.aether.item.accessories.miscellaneous.ShieldOfRepulsionItem;
Expand Down Expand Up @@ -179,7 +179,7 @@ private static void equipAccessory(Mob mob, String identifier, ArmorMaterials ar
*/
@Nullable
private static Item getEquipmentForSlot(String identifier, ArmorMaterials armorMaterials) {
if (identifier.equals(AetherConfig.COMMON.use_curios_menu.get() ? "hands" : "aether_gloves")) {
if (identifier.equals(GlovesItem.getIdentifierStatic())) {
switch (armorMaterials) {
case LEATHER -> {
return AetherItems.LEATHER_GLOVES.get();
Expand All @@ -197,7 +197,7 @@ private static Item getEquipmentForSlot(String identifier, ArmorMaterials armorM
return AetherItems.DIAMOND_GLOVES.get();
}
}
} else if (identifier.equals(AetherConfig.COMMON.use_curios_menu.get() ? "necklace" : "aether_pendant")) {
} else if (identifier.equals(PendantItem.getIdentifierStatic())) {
switch (armorMaterials) {
case GOLD -> {
return AetherItems.GOLDEN_PENDANT.get();
Expand Down Expand Up @@ -342,15 +342,9 @@ public static Optional<InteractionResult> interactWithArmorStand(Entity target,
if (!stack.isEmpty()) { // Equip behavior.
if (stack.is(AetherTags.Items.ACCESSORIES)) {
String identifier = "";
if (stack.getItem() instanceof GlovesItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "hands" : "aether_gloves";
} else if (stack.getItem() instanceof PendantItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "necklace" : "aether_pendant";
} else if (stack.getItem() instanceof CapeItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "back" : "aether_cape";
} else if (stack.getItem() instanceof ShieldOfRepulsionItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "body" : "aether_shield";
}
if (stack.getItem() instanceof SlotIdentifierHolder slotIdentifierHolder)
identifier = slotIdentifierHolder.getIdentifier();

Optional<ICuriosItemHandler> lazyHandler = CuriosApi.getCuriosInventory(armorStand);
if (lazyHandler.isPresent()) {
ICuriosItemHandler handler = lazyHandler.get();
Expand Down Expand Up @@ -427,10 +421,10 @@ private static String slotToUnequip(ArmorStand armorStand, Vec3 pos) {
double z = isSmall ? pos.z * 2.0 : pos.z;
double front = axis == Direction.Axis.X ? z : x;
double vertical = isSmall ? pos.y * 2.0 : pos.y;
String glovesIdentifier = AetherConfig.COMMON.use_curios_menu.get() ? "hands" : "aether_gloves";
String pendantIdentifier = AetherConfig.COMMON.use_curios_menu.get() ? "necklace" : "aether_pendant";
String capeIdentifier = AetherConfig.COMMON.use_curios_menu.get() ? "back" : "aether_cape";
String shieldIdentifier = AetherConfig.COMMON.use_curios_menu.get() ? "body" : "aether_shield";
String glovesIdentifier = GlovesItem.getIdentifierStatic();
String pendantIdentifier = PendantItem.getIdentifierStatic();
String capeIdentifier = CapeItem.getIdentifierStatic();
String shieldIdentifier = ShieldOfRepulsionItem.getIdentifierStatic();
if (!getItemByIdentifier(armorStand, glovesIdentifier).isEmpty()
&& Math.abs(front) >= (isSmall ? 0.15 : 0.2)
&& vertical >= (isSmall ? 0.65 : 0.75)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.aetherteam.aether.item.accessories;


/**
* Functional interface whose only defines an accessory slot identifier for an item.
* <p>
* Should be used to avoid hard-coding specific identifiers
* and enable easy changing and addition of new accessory slot identifiers.
*
* @author Alexandra
*/
@FunctionalInterface
public interface SlotIdentifierHolder {
/**
* @implNote May be best to pair with a static method to get an identifier if no instance methods are needed.
* @return The string used as an identifier for an accessory slot.
*/
String getIdentifier();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.aetherteam.aether.item.accessories.cape;

import com.aetherteam.aether.Aether;
import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.client.AetherSoundEvents;
import com.aetherteam.aether.item.accessories.AccessoryItem;
import com.aetherteam.aether.item.accessories.SlotIdentifierHolder;
import net.minecraft.resources.ResourceLocation;

public class CapeItem extends AccessoryItem {
public class CapeItem extends AccessoryItem implements SlotIdentifierHolder {
protected ResourceLocation CAPE_LOCATION;

public CapeItem(String capeLocation, Properties properties) {
Expand All @@ -24,4 +26,21 @@ public void setRenderTexture(String modId, String registryName) {
public ResourceLocation getCapeTexture() {
return this.CAPE_LOCATION;
}


/**
* @return {@link CapeItem}'s own identifier for its accessory slot,
* using a static method as it is used in other conditions without access to an instance.
*/
@Override
public String getIdentifier() {
return getIdentifierStatic();
}

/**
* @return {@link CapeItem}'s own identifier for its accessory slot.
*/
public static String getIdentifierStatic() {
return AetherConfig.COMMON.use_curios_menu.get() ? "back" : "aether_cape";
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.aetherteam.aether.item.accessories.gloves;

import com.aetherteam.aether.Aether;
import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.item.accessories.AccessoryItem;
import com.aetherteam.aether.item.accessories.SlotIdentifierHolder;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -19,7 +21,7 @@
import java.util.UUID;
import java.util.function.Supplier;

public class GlovesItem extends AccessoryItem {
public class GlovesItem extends AccessoryItem implements SlotIdentifierHolder {
protected final ArmorMaterial material;
protected final double damage;
protected ResourceLocation GLOVES_TEXTURE;
Expand Down Expand Up @@ -85,4 +87,20 @@ public ImmutableTriple<Float, Float, Float> getColors(ItemStack stack) {
}
return new ImmutableTriple<>(red, green, blue);
}
}

/**
* @return {@link GlovesItem}'s own identifier for its accessory slot,
* using a static method as it is used in other conditions without access to an instance.
*/
@Override
public String getIdentifier() {
return getIdentifierStatic();
}

/**
* @return {@link GlovesItem}'s own identifier for its accessory slot.
*/
public static String getIdentifierStatic() {
return AetherConfig.COMMON.use_curios_menu.get() ? "hands" : "aether_gloves";
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.aetherteam.aether.item.accessories.miscellaneous;

import com.aetherteam.aether.Aether;
import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.item.accessories.AccessoryItem;
import com.aetherteam.aether.item.accessories.SlotIdentifierHolder;
import net.minecraft.resources.ResourceLocation;

public class ShieldOfRepulsionItem extends AccessoryItem {
public class ShieldOfRepulsionItem extends AccessoryItem implements SlotIdentifierHolder {
private static final ResourceLocation SHIELD_OF_REPULSION = new ResourceLocation(Aether.MODID, "textures/models/accessory/shield_of_repulsion/shield_of_repulsion_accessory.png");
private static final ResourceLocation SHIELD_OF_REPULSION_INACTIVE = new ResourceLocation(Aether.MODID, "textures/models/accessory/shield_of_repulsion/shield_of_repulsion_inactive_accessory.png");
private static final ResourceLocation SHIELD_OF_REPULSION_SLIM = new ResourceLocation(Aether.MODID, "textures/models/accessory/shield_of_repulsion/shield_of_repulsion_slim_accessory.png");
Expand All @@ -29,4 +31,20 @@ public ResourceLocation getShieldOfRepulsionSlimTexture() {
public ResourceLocation getShieldOfRepulsionSlimInactiveTexture() {
return SHIELD_OF_REPULSION_SLIM_INACTIVE;
}

/**
* @return {@link ShieldOfRepulsionItem}'s own identifier for its accessory slot,
* using a static method as it is used in other conditions without access to an instance.
*/
@Override
public String getIdentifier() {
return getIdentifierStatic();
}

/**
* @return {@link ShieldOfRepulsionItem}'s own identifier for its accessory slot.
*/
public static String getIdentifierStatic() {
return AetherConfig.COMMON.use_curios_menu.get() ? "body" : "aether_shield";
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.aetherteam.aether.item.accessories.pendant;

import com.aetherteam.aether.Aether;
import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.item.accessories.AccessoryItem;
import com.aetherteam.aether.item.accessories.SlotIdentifierHolder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;

import java.util.function.Supplier;

public class PendantItem extends AccessoryItem {
public class PendantItem extends AccessoryItem implements SlotIdentifierHolder {
protected ResourceLocation PENDANT_LOCATION;

public PendantItem(String pendantLocation, Supplier<? extends SoundEvent> pendantSound, Properties properties) {
Expand All @@ -26,4 +28,20 @@ public void setRenderTexture(String modId, String registryName) {
public ResourceLocation getPendantTexture() {
return this.PENDANT_LOCATION;
}

/**
* @return {@link PendantItem}'s own identifier for its accessory slot,
* using a static method as it is used in other conditions without access to an instance.
*/
@Override
public String getIdentifier() {
return getIdentifierStatic();
}

/**
* @return {@link PendantItem}'s own identifier for its accessory slot.
*/
public static String getIdentifierStatic() {
return AetherConfig.COMMON.use_curios_menu.get() ? "necklace" : "aether_pendant";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ public static String getIdentifierForItem(LivingEntity livingEntity, ItemStack s
TagKey<Item> glovesTag = TagKey.create(Registries.ITEM, new ResourceLocation(CuriosConstants.MOD_ID, "hands"));
TagKey<Item> pendantTag = TagKey.create(Registries.ITEM, new ResourceLocation(CuriosConstants.MOD_ID, "necklace"));
if (stack.is(glovesTag)) {
return "hands";
return GlovesItem.getIdentifierStatic();
} else if (stack.is(pendantTag) && (livingEntity.getType() == EntityType.PIGLIN || livingEntity.getType() == EntityType.ZOMBIFIED_PIGLIN)) {
return "necklace";
return PendantItem.getIdentifierStatic();
}
} else {
if (stack.is(AetherTags.Items.AETHER_GLOVES)) {
return "aether_gloves";
return GlovesItem.getIdentifierStatic();
} else if (stack.is(AetherTags.Items.AETHER_PENDANT) && (livingEntity.getType() == EntityType.PIGLIN || livingEntity.getType() == EntityType.ZOMBIFIED_PIGLIN)) {
return "aether_pendant";
return PendantItem.getIdentifierStatic();
}
}
return "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.aetherteam.aether.mixin.mixins.client;

import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.item.accessories.cape.CapeItem;
import com.aetherteam.aether.mixin.AetherMixinHooks;
import net.minecraft.client.renderer.entity.layers.ElytraLayer;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -30,7 +30,7 @@ public class ElytraLayerMixin<T extends LivingEntity> {
@Inject(at = @At("HEAD"), method = "getElytraTexture(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/LivingEntity;)Lnet/minecraft/resources/ResourceLocation;", cancellable = true, remap = false)
private void getElytraTexture(ItemStack stack, T entity, CallbackInfoReturnable<ResourceLocation> cir) {
if (entity instanceof ArmorStand armorStand) {
String identifier = AetherConfig.COMMON.use_curios_menu.get() ? "back" : "aether_cape";
String identifier = CapeItem.getIdentifierStatic();
Optional<ICuriosItemHandler> lazyHandler = CuriosApi.getCuriosInventory(armorStand);
if (lazyHandler.isPresent()) {
ICuriosItemHandler handler = lazyHandler.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.aetherteam.aether.mixin.mixins.client;

import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.item.accessories.gloves.GlovesItem;
import net.minecraft.client.gui.screens.inventory.SmithingScreen;
import net.minecraft.world.entity.EquipmentSlot;
Expand Down Expand Up @@ -33,7 +32,7 @@ public class SmithingScreenMixin {
@Inject(at = @At("HEAD"), method = "updateArmorStandPreview(Lnet/minecraft/world/item/ItemStack;)V", cancellable = true)
private void updateArmorStandPreview(ItemStack stack, CallbackInfo ci) {
if (this.armorStandPreview != null) {
String identifier = AetherConfig.COMMON.use_curios_menu.get() ? "hands" : "aether_gloves";
String identifier = GlovesItem.getIdentifierStatic();
Optional<ICuriosItemHandler> lazyHandler = CuriosApi.getCuriosInventory(this.armorStandPreview);
if (lazyHandler.isPresent()) {
ICuriosItemHandler handler = lazyHandler.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.aetherteam.aether.mixin.mixins.common;

import com.aetherteam.aether.AetherConfig;
import com.aetherteam.aether.item.accessories.cape.CapeItem;
import com.aetherteam.aether.item.accessories.gloves.GlovesItem;
import com.aetherteam.aether.item.accessories.miscellaneous.ShieldOfRepulsionItem;
import com.aetherteam.aether.item.accessories.pendant.PendantItem;
import com.aetherteam.aether.item.accessories.SlotIdentifierHolder;
import com.aetherteam.aether.mixin.AetherMixinHooks;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.item.ItemStack;
Expand All @@ -25,15 +21,9 @@ public class ArmorStandMixin {
private void canTakeItem(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
ArmorStand armorStand = (ArmorStand) (Object) this;
String identifier = "";
if (stack.getItem() instanceof GlovesItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "hands" : "aether_gloves";
} else if (stack.getItem() instanceof PendantItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "necklace" : "aether_pendant";
} else if (stack.getItem() instanceof CapeItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "back" : "aether_cape";
} else if (stack.getItem() instanceof ShieldOfRepulsionItem) {
identifier = AetherConfig.COMMON.use_curios_menu.get() ? "body" : "aether_shield";
}
if (stack.getItem() instanceof SlotIdentifierHolder slotIdentifierHolder)
identifier = slotIdentifierHolder.getIdentifier();

if (!identifier.isEmpty()) {
ItemStack accessory = AetherMixinHooks.getItemByIdentifier(armorStand, identifier);
if (accessory.isEmpty()) {
Expand Down

0 comments on commit cfb59d1

Please sign in to comment.