2021-02-14 21:15:30 +01:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.Items;
|
|
|
|
import net.minecraft.util.Identifier;
|
|
|
|
import net.minecraft.util.registry.Registry;
|
|
|
|
|
|
|
|
public interface ChameleonItem {
|
|
|
|
|
|
|
|
default boolean isFullyDisguised() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default ItemStack getAppearanceStack(ItemStack stack) {
|
|
|
|
Item appearance = getAppearance(stack);
|
|
|
|
if (appearance != Items.AIR) {
|
|
|
|
return createAppearanceStack(stack, appearance);
|
|
|
|
}
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
default ItemStack createAppearanceStack(ItemStack stack, Item appearance) {
|
2021-02-14 22:13:12 +01:00
|
|
|
ItemStack newAppearance = appearance.getDefaultStack();
|
2021-12-22 10:15:09 +01:00
|
|
|
if (stack.hasNbt()) {
|
|
|
|
newAppearance.setNbt(stack.getNbt().copy());
|
2021-02-14 21:15:30 +01:00
|
|
|
}
|
2021-02-14 22:13:12 +01:00
|
|
|
newAppearance.setCount(stack.getCount());
|
2021-12-22 10:15:09 +01:00
|
|
|
newAppearance.removeSubNbt("appearance");
|
2021-02-14 21:15:30 +01:00
|
|
|
return newAppearance;
|
|
|
|
}
|
|
|
|
|
|
|
|
default boolean hasAppearance(ItemStack stack) {
|
|
|
|
return getAppearance(stack) != Items.AIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
default Item getAppearance(ItemStack stack) {
|
2021-12-22 10:15:09 +01:00
|
|
|
if (stack.hasNbt() && stack.getNbt().contains("appearance")) {
|
|
|
|
return Registry.ITEM.get(new Identifier(stack.getNbt().getString("appearance")));
|
2021-02-14 21:15:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Items.AIR;
|
|
|
|
}
|
|
|
|
|
2021-02-14 22:13:12 +01:00
|
|
|
default ItemStack setAppearance(ItemStack stack, ItemStack appearance) {
|
|
|
|
ItemStack result = stack.copy();
|
|
|
|
|
2021-12-22 10:15:09 +01:00
|
|
|
if (appearance.hasNbt()) {
|
|
|
|
result.setNbt(appearance.getNbt().copy());
|
2021-02-14 22:13:12 +01:00
|
|
|
result.removeCustomName();
|
|
|
|
result.setDamage(stack.getDamage());
|
|
|
|
result.setCount(stack.getCount());
|
|
|
|
}
|
2021-12-22 10:15:09 +01:00
|
|
|
result.getOrCreateNbt().putString("appearance", Registry.ITEM.getId(appearance.getItem()).toString());
|
2021-02-14 22:13:12 +01:00
|
|
|
|
|
|
|
return result;
|
2021-02-14 21:15:30 +01:00
|
|
|
}
|
|
|
|
}
|