Fix item colours and crash when using an item

This commit is contained in:
Sollace 2024-10-04 23:35:03 +01:00
parent 2620ac5de1
commit bc1d6f40e6
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 7 additions and 11 deletions

View file

@ -162,9 +162,9 @@ public interface URenderers {
ColorProviderRegistry.BLOCK.register(URenderers::getTintedBlockColor, TintedBlock.REGISTRY.stream().toArray(Block[]::new));
ColorProviderRegistry.ITEM.register((stack, i) -> getTintedBlockColor(Block.getBlockFromItem(stack.getItem()).getDefaultState(), null, null, i), TintedBlock.REGISTRY.stream().map(Block::asItem).filter(i -> i != Items.AIR).toArray(Item[]::new));
ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 ? -1 : DyedColorComponent.getColor(stack, Colors.WHITE), UItems.FRIENDSHIP_BRACELET);
ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 || !EnchantableItem.isEnchanted(stack) ? -1 : EnchantableItem.getSpellKey(stack).getColor(), UItems.GEMSTONE);
ColorProviderRegistry.ITEM.register((stack, i) -> i == 1 && EnchantableItem.isEnchanted(stack) ? EnchantableItem.getSpellKey(stack).getColor() : -1, UItems.MAGIC_STAFF);
ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 ? -1 : DyedColorComponent.getColor(stack, DyedColorComponent.DEFAULT_COLOR), UItems.FRIENDSHIP_BRACELET);
ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 || !EnchantableItem.isEnchanted(stack) ? Colors.WHITE : EnchantableItem.getSpellKey(stack).getColor() | 0xFF000000, UItems.GEMSTONE);
ColorProviderRegistry.ITEM.register((stack, i) -> i == 1 && EnchantableItem.isEnchanted(stack) ? EnchantableItem.getSpellKey(stack).getColor() | 0xFF000000 : Colors.WHITE, UItems.MAGIC_STAFF);
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), UBlocks.TRANSLUCENT_BLOCKS.stream().toArray(Block[]::new));
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(), UBlocks.SEMI_TRANSPARENT_BLOCKS.stream().toArray(Block[]::new));

View file

@ -82,8 +82,7 @@ public record DietProfile(
}
@Nullable
public FoodComponent getAdjustedFoodComponent(ItemStack stack) {
var food = stack.get(DataComponentTypes.FOOD);
public FoodComponent getAdjustedFoodComponent(ItemStack stack, FoodComponent food) {
if (this == EMPTY) {
return food;
}

View file

@ -23,10 +23,7 @@ public class TransientComponentMap {
private static final BiFunction<ItemStack, ?, ?> DEFAULT = (stack, t) -> t;
public static final TransientComponentMap INITIAL = Util.make(new TransientComponentMap(null), map -> {
map.set(UDataComponentTypes.DIET_PROFILE, (s, original) -> {
if (original != null) {
return original;
}
return ItemStackDuck.of(s).getTransientComponents().getCarrier()
return original != null ? original : ItemStackDuck.of(s).getTransientComponents().getCarrier()
.flatMap(Pony::of)
.map(pony -> PonyDiets.getInstance().getDiet(pony))
.orElse(DietProfile.EMPTY);
@ -34,12 +31,12 @@ public class TransientComponentMap {
map.set(DataComponentTypes.FOOD, (s, originalFood) -> {
DietProfile diet = s.get(UDataComponentTypes.DIET_PROFILE);
if (diet == null) {
if (diet == null || diet == DietProfile.EMPTY) {
return originalFood;
}
if (originalFood != null) {
return diet.getAdjustedFoodComponent(s);
return diet.getAdjustedFoodComponent(s, originalFood);
}
if (ItemStackDuck.of(s).getTransientComponents().getCarrier()