This commit is contained in:
parent
d393812448
commit
ad6d36fecb
6 changed files with 57 additions and 27 deletions
|
@ -67,7 +67,7 @@ public class FlowerCrownItemModel implements ItemModel
|
|||
Vector2f uv = TRANSLATIONS.get(layer);
|
||||
return new Transformation(
|
||||
new Vector3f(uv.x * 0.0625f, uv.y * 0.0625f, 0.0f),
|
||||
new Quaternionf(), new Vector3f(1.002f), new Quaternionf());
|
||||
new Quaternionf(), new Vector3f(1.001f), new Quaternionf());
|
||||
}
|
||||
|
||||
private ResourceLocation getFlowerLocation(int layer)
|
||||
|
@ -77,6 +77,21 @@ public class FlowerCrownItemModel implements ItemModel
|
|||
"flower/flower_" + (layer % 2 == 0 ? "large" : "small"));
|
||||
}
|
||||
|
||||
private ResourceLocation getOutlineLocation(int layer)
|
||||
{
|
||||
|
||||
return ResourceLocation.fromNamespaceAndPath(CharmsAndFabrics.MODID,
|
||||
"flower/flower_outline_" +
|
||||
(layer % 2 == 0 ? "large" : "small"));
|
||||
}
|
||||
|
||||
private TextureAtlasSprite getSprite(ResourceLocation textureLocation)
|
||||
{
|
||||
SpriteGetter sprites = this.context.blockModelBaker().sprites();
|
||||
Material material = ClientHooks.getBlockMaterial(textureLocation);
|
||||
return sprites.get(material, DEBUG_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bakes the base and updates the LayerRenderState quads
|
||||
*/
|
||||
|
@ -95,32 +110,48 @@ public class FlowerCrownItemModel implements ItemModel
|
|||
return new BlockModelWrapper(List.of(), quads, this.renderProperties);
|
||||
}
|
||||
|
||||
private ItemModel bakeLayer(int layer, ItemStack flower)
|
||||
private List<BakedQuad> bakeModel(ResourceLocation textureLocation,
|
||||
int layer)
|
||||
{
|
||||
SpriteGetter sprites = this.context.blockModelBaker().sprites();
|
||||
Material material =
|
||||
ClientHooks.getBlockMaterial(this.getFlowerLocation(layer));
|
||||
TextureAtlasSprite sprite = sprites.get(material, DEBUG_NAME);
|
||||
TextureAtlasSprite sprite = this.getSprite(textureLocation);
|
||||
List<BlockElement> bits =
|
||||
UnbakedElementsHelper.createUnbakedItemElements(0, sprite);
|
||||
return UnbakedElementsHelper.bakeElements(bits, $ -> sprite,
|
||||
new ComposedModelState(BlockModelRotation.X0_Y0,
|
||||
this.getTransform(layer)));
|
||||
}
|
||||
|
||||
private ItemModel bakeOutline(int layer)
|
||||
{
|
||||
List<BakedQuad> quads =
|
||||
UnbakedElementsHelper.bakeElements(bits, $ -> sprite,
|
||||
new ComposedModelState(BlockModelRotation.X0_Y0,
|
||||
this.getTransform(layer)));
|
||||
this.bakeModel(this.getOutlineLocation(layer), layer);
|
||||
return new BlockModelWrapper(List.of(new FlowersTint(layer)), quads,
|
||||
this.renderProperties);
|
||||
}
|
||||
|
||||
private ItemModel composeModel(FlowerCrownContent content)
|
||||
private ItemModel bakeFlower(int layer)
|
||||
{
|
||||
List<ItemModel> models = new ArrayList<>();
|
||||
models.add(this.bakeOutline(layer));
|
||||
|
||||
List<BakedQuad> quads =
|
||||
this.bakeModel(this.getFlowerLocation(layer), layer);
|
||||
models.add(
|
||||
new BlockModelWrapper(List.of(), quads, this.renderProperties));
|
||||
return new CompositeModel(models);
|
||||
}
|
||||
|
||||
private ItemModel bakeFlowerCrown(FlowerCrownContent content)
|
||||
{
|
||||
List<ItemModel> models = new ArrayList<>();
|
||||
models.add(this.bakeBase());
|
||||
for (int i = 0; i < content.flowers().size(); i++)
|
||||
{
|
||||
if (!content.flowers().get(i).isEmpty())
|
||||
if (content.flowers().get(i).isEmpty())
|
||||
{
|
||||
models.add(this.bakeLayer(i, content.flowers().get(i)));
|
||||
continue;
|
||||
}
|
||||
models.add(this.bakeFlower(i));
|
||||
}
|
||||
return new CompositeModel(models);
|
||||
}
|
||||
|
@ -133,13 +164,12 @@ public class FlowerCrownItemModel implements ItemModel
|
|||
{
|
||||
FlowerCrownContent comp = stack.get(
|
||||
CnFRegistries.DataComponents.FLOWER_CROWN_CONTENT.get());
|
||||
if (comp == null)
|
||||
if (comp != null)
|
||||
{
|
||||
comp = new FlowerCrownContent(List.of());
|
||||
this.bakeFlowerCrown(comp)
|
||||
.update(renderState, stack, itemModelResolver, displayContext,
|
||||
level, entity, seed);
|
||||
}
|
||||
this.composeModel(comp)
|
||||
.update(renderState, stack, itemModelResolver, displayContext,
|
||||
level, entity, seed);
|
||||
}
|
||||
|
||||
public record Unbaked(ResourceLocation base) implements ItemModel.Unbaked
|
||||
|
|
|
@ -7,7 +7,6 @@ import fr.sushi.charmsnfabrics.common.CnFRegistries;
|
|||
import fr.sushi.charmsnfabrics.common.data.FlowerCrownContent;
|
||||
import net.minecraft.client.color.item.ItemTintSource;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -26,21 +25,22 @@ public record FlowersTint(int layer) implements ItemTintSource
|
|||
public int calculate(ItemStack stack, @Nullable ClientLevel level,
|
||||
@Nullable LivingEntity entity)
|
||||
{
|
||||
FlowerCrownContent data =
|
||||
stack.get(CnFRegistries.DataComponents.FLOWER_CROWN_CONTENT.get());
|
||||
FlowerCrownContent data = stack.get(
|
||||
CnFRegistries.DataComponents.FLOWER_CROWN_CONTENT.get());
|
||||
if (data != null)
|
||||
{
|
||||
ItemStack flower = data.flowers().get(this.layer);
|
||||
if (flower.is(ItemTags.FLOWERS)) {
|
||||
|
||||
}
|
||||
if (flower.is(Items.POPPY))
|
||||
if (flower.is(Items.BLUE_ORCHID))
|
||||
{
|
||||
return DyeColor.RED.getTextureDiffuseColor();
|
||||
return DyeColor.LIGHT_BLUE.getTextureDiffuseColor();
|
||||
}
|
||||
else if (flower.is(Items.DANDELION))
|
||||
else if (flower.is(Items.LILY_OF_THE_VALLEY))
|
||||
{
|
||||
return DyeColor.YELLOW.getTextureDiffuseColor();
|
||||
return DyeColor.WHITE.getTextureDiffuseColor();
|
||||
}
|
||||
else if (flower.is(Items.PINK_TULIP))
|
||||
{
|
||||
return DyeColor.MAGENTA.getTextureDiffuseColor();
|
||||
}
|
||||
}
|
||||
return 0xFFFFFFFF;
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 141 B After Width: | Height: | Size: 108 B |
Binary file not shown.
After Width: | Height: | Size: 123 B |
Binary file not shown.
After Width: | Height: | Size: 103 B |
Binary file not shown.
Before Width: | Height: | Size: 112 B After Width: | Height: | Size: 95 B |
Loading…
Add table
Add a link
Reference in a new issue