Implement Item Properties and get Forge Version up to date

This commit is contained in:
2022-07-03 17:37:52 +02:00
parent 28d8f0fa6a
commit 9d749fe2ee
19 changed files with 245 additions and 24 deletions

View File

@@ -0,0 +1,35 @@
package me.hypherionmc.craterlib.util;
import me.hypherionmc.craterlib.common.item.BlockItemDyable;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
/**
* @author HypherionSA
* @date 03/07/2022
*/
public class ColorPropertyFunction implements ClampedItemPropertyFunction {
private final BlockItemDyable item;
public ColorPropertyFunction(BlockItemDyable item) {
this.item = item;
}
@Override
public float call(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i) {
return Mth.clamp(this.unclampedCall(itemStack, clientLevel, livingEntity, i), 0.0F, 15.0F);
}
@Override
public float unclampedCall(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i) {
DyeColor color = item.getColorFromNBT(itemStack);
return color.getId();
}
}

View File

@@ -3,6 +3,7 @@ package me.hypherionmc.craterlib.util;
import com.mojang.math.Vector4f;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.DyeColor;
public class RenderUtils {
@@ -51,4 +52,8 @@ public class RenderUtils {
return pPackedColor & 255;
}
}
public static int renderColorFromDye(DyeColor color) {
return color.getMaterialColor().col | 0xFF000000;
}
}