Implement Item Properties and get Forge Version up to date
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user