Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ namespace AttributeRenderingLibrary;

public class BlockBehaviorShapeTexturesFromAttributes(Block block) : StrongBlockBehavior(block), IBlockShapeTexturesFromAttributes, IContainedMeshSource
{
public Dictionary<string, List<object>> NameByType { get; protected set; }
public Dictionary<string, List<object>> DescriptionByType { get; protected set; }
public Dictionary<string, Cuboidf[]> CollisionBoxesByType { get; protected set; }
public Dictionary<string, Cuboidf[]> SelectionBoxesByType { get; protected set; }
public Dictionary<string, BlockDropItemStack[]> DropsByType { get; protected set; }

public Dictionary<string, CompositeShape> shapeByType { get; protected set; }
public Dictionary<string, CompositeShape> shapeInventoryByType { get; protected set; }
public Dictionary<string, Dictionary<string, CompositeTexture>> texturesByType { get; protected set; }
public VariantSelectionList<List<object>> NameByType { get; protected set; }
public VariantSelectionList<List<object>> DescriptionByType { get; protected set; }
public VariantSelectionList<Cuboidf[]> CollisionBoxesByType { get; protected set; }
public VariantSelectionList<Cuboidf[]> SelectionBoxesByType { get; protected set; }
public VariantSelectionList<BlockDropItemStack[]> DropsByType { get; protected set; }

public VariantSelectionList<CompositeShape> shapeByType { get; protected set; }
public VariantSelectionList<CompositeShape> shapeInventoryByType { get; protected set; }
public VariantSelectionList<Dictionary<string, CompositeTexture>> texturesByType { get; protected set; }
#region Extra shape overrides
public Dictionary<string, string[]> ShapeIgnoreElementsByType { get; protected set; }
public Dictionary<string, string[]> ShapeIgnoreElementsCombineByType { get; protected set; }
public Dictionary<string, string[]> ShapeSelectiveElementsByType { get; protected set; }
public Dictionary<string, string[]> ShapeSelectiveElementsCombineByType { get; protected set; }
public VariantSelectionList<string[]> ShapeIgnoreElementsByType { get; protected set; }
public VariantSelectionList<string[]> ShapeIgnoreElementsCombineByType { get; protected set; }
public VariantSelectionList<string[]> ShapeSelectiveElementsByType { get; protected set; }
public VariantSelectionList<string[]> ShapeSelectiveElementsCombineByType { get; protected set; }
#endregion

private ICoreClientAPI clientApi;
Expand All @@ -44,40 +44,45 @@ public override void Initialize(JsonObject properties)
{
base.Initialize(properties);

if (properties != null)
{
NameByType = properties["name"].AsObject<Dictionary<string, List<object>>>();
DescriptionByType = properties["description"].AsObject<Dictionary<string, List<object>>>();
DropsByType = properties["drops"].AsObject<Dictionary<string, BlockDropItemStack[]>>();

shapeByType = properties["shape"].AsObject<Dictionary<string, CompositeShape>>();
shapeInventoryByType = properties["shapeInventory"].AsObject<Dictionary<string, CompositeShape>>();
texturesByType = properties["textures"].AsObject<Dictionary<string, Dictionary<string, CompositeTexture>>>();
if (properties is not { Count: > 0 })
return;

ShapeIgnoreElementsByType = properties["shapeIgnoreElements"].AsObject<Dictionary<string, string[]>>();
ShapeIgnoreElementsCombineByType = properties["shapeIgnoreElementsCombine"].AsObject<Dictionary<string, string[]>>();
ShapeSelectiveElementsByType = properties["shapeSelectiveElements"].AsObject<Dictionary<string, string[]>>();
ShapeSelectiveElementsCombineByType = properties["shapeSelectiveElementsCombine"].AsObject<Dictionary<string, string[]>>();
NameByType = VariantSelectionList<List<object>>.LoadFrom(properties["name"]);
DescriptionByType = VariantSelectionList<List<object>>.LoadFrom(properties["description"]);
DropsByType = VariantSelectionList<BlockDropItemStack[]>.LoadFrom(properties["drops"]);

LoadAndResolveCollisionAndSelectionBoxes(properties);
}
shapeByType = VariantSelectionList<CompositeShape>.LoadFrom(properties["shape"]);
shapeInventoryByType = VariantSelectionList<CompositeShape>.LoadFrom(properties["shapeInventory"]);
texturesByType = VariantSelectionList<Dictionary<string, CompositeTexture>>.LoadFrom(properties["textures"]);

ShapeIgnoreElementsByType = VariantSelectionList<string[]>.LoadFrom(properties["shapeIgnoreElements"]);
ShapeIgnoreElementsCombineByType = VariantSelectionList<string[]>.LoadFrom(properties["shapeIgnoreElementsCombine"]);
ShapeSelectiveElementsByType = VariantSelectionList<string[]>.LoadFrom(properties["shapeSelectiveElements"]);
ShapeSelectiveElementsCombineByType = VariantSelectionList<string[]>.LoadFrom(properties["shapeSelectiveElementsCombine"]);

LoadAndResolveCollisionAndSelectionBoxes(properties);
}

private void LoadAndResolveCollisionAndSelectionBoxes(JsonObject properties)
{
Dictionary<string, RotatableCube[]> rawCollisionsAndSelections = properties["collisionSelectionBoxes"]?.AsObject<Dictionary<string, RotatableCube[]>>();
Dictionary<string, RotatableCube[]> rawCollisions = properties["collisionBoxes"]?.AsObject<Dictionary<string, RotatableCube[]>>();
Dictionary<string, RotatableCube[]> rawSelections = properties["selectionBoxes"]?.AsObject<Dictionary<string, RotatableCube[]>>();

if (rawCollisionsAndSelections?.Count > 0)
if (properties["collisionSelectionBoxes"] is { Token: not null } rawCollisionsAndSelections)
{
CollisionBoxesByType = rawCollisionsAndSelections?.ToDictionary(x => x.Key, x => x.Value.ToCuboidf());
SelectionBoxesByType = rawCollisionsAndSelections?.ToDictionary(x => x.Key, x => x.Value.ToCuboidf());
var dict = rawCollisionsAndSelections
.AsObject<Dictionary<string, RotatableCube[]>>();
CollisionBoxesByType = VariantSelectionList<Cuboidf[]>.LoadFrom(dict, cube => cube.ToCuboidf());
SelectionBoxesByType = VariantSelectionList<Cuboidf[]>.LoadFrom(dict, cube => cube.ToCuboidf());
}
else
{
CollisionBoxesByType = rawCollisions?.ToDictionary(x => x.Key, x => x.Value.ToCuboidf());
SelectionBoxesByType = rawSelections?.ToDictionary(x => x.Key, x => x.Value.ToCuboidf());
if (properties["collisionBoxes"] is { Token: not null } rawCollisions)
CollisionBoxesByType = VariantSelectionList<Cuboidf[]>.LoadFrom(rawCollisions
.AsObject<Dictionary<string, RotatableCube[]>>(),
cube => cube.ToCuboidf());

if (properties["selectionBoxes"] is { Token: not null } rawSelections)
SelectionBoxesByType = VariantSelectionList<Cuboidf[]>.LoadFrom(rawSelections
.AsObject<Dictionary<string, RotatableCube[]>>(),
cube => cube.ToCuboidf());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ namespace AttributeRenderingLibrary;
public class CollectibleBehaviorContainedTransform(CollectibleObject collObj) : CollectibleBehavior(collObj), IContainedTransform
{
public Transforms BasicTransforms { get; protected set; }
public Dictionary<string, Dictionary<string, ModelTransform>> ExtraTransforms { get; protected set; }
public Dictionary<string, VariantSelectionList<ModelTransform>> ExtraTransforms { get; protected set; }

public override void Initialize(JsonObject properties)
{
base.Initialize(properties);
BasicTransforms = properties["transforms"].AsObject<Transforms>();
ExtraTransforms = properties["extraTransforms"].AsObject<Dictionary<string, Dictionary<string, ModelTransform>>>()?.ToDictionary(x => x.Key.ToLowerInvariant(), x => x.Value);
BasicTransforms = Transforms.LoadFrom(properties["transforms"]);
ExtraTransforms = properties["extraTransforms"]
.AsObject<Dictionary<string, Dictionary<string, ModelTransform>>>()
?.ToDictionary(
x => x.Key.ToLowerInvariant(),
x => VariantSelectionList<ModelTransform>.LoadFrom(x.Value)
);
}

public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
Expand All @@ -30,7 +35,7 @@ public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, En

public void ApplyOnBeforeRenderTransform(EnumItemRenderTarget target, Variants variants, ref ModelTransform transform)
{
Dictionary<string, ModelTransform> basicTransformsByType = target switch
VariantSelectionList<ModelTransform> basicTransformsByType = target switch
{
EnumItemRenderTarget.Gui => BasicTransforms?.GuiTransform,
EnumItemRenderTarget.HandTp => BasicTransforms?.TpHandTransform,
Expand All @@ -54,7 +59,7 @@ ModelTransform IContainedTransform.GetTransform(BlockEntityDisplay be, string at

if (ExtraTransforms != null
&& ExtraTransforms.Count > 0
&& ExtraTransforms.TryGetValue(attributeTransformCode, out Dictionary<string, ModelTransform> transformsByType)
&& ExtraTransforms.TryGetValue(attributeTransformCode, out VariantSelectionList<ModelTransform> transformsByType)
&& Variants.FromStack(stack).FindByVariant(transformsByType, out ModelTransform transform))
{
transform = transform.EnsureDefaultValues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using Vintagestory.API.Common;
using Vintagestory.API.Datastructures;
using Vintagestory.GameContent;
Expand All @@ -8,17 +9,17 @@ namespace AttributeRenderingLibrary;

public class CollectibleBehaviorHeldBagTyped(CollectibleObject collObj) : CollectibleBehaviorHeldBag(collObj)
{
public Dictionary<string, int> QuantitySlotsByType { get; protected set; }
public Dictionary<string, string> SlotBgColorByType { get; protected set; }
public Dictionary<string, EnumItemStorageFlags> StorageFlagsByType { get; protected set; }
public VariantSelectionList<int> QuantitySlotsByType { get; protected set; }
public VariantSelectionList<string> SlotBgColorByType { get; protected set; }
public VariantSelectionList<EnumItemStorageFlags> StorageFlagsByType { get; protected set; }

public override void Initialize(JsonObject properties)
{
base.Initialize(properties);

QuantitySlotsByType = properties["quantitySlots"].AsObject<Dictionary<string, int>>();
SlotBgColorByType = properties["slotBgColor"].AsObject<Dictionary<string, string>>();
StorageFlagsByType = properties["storageFlags"].AsObject<Dictionary<string, int>>()?.ToDictionary(x => x.Key, x => (EnumItemStorageFlags)x.Value);
QuantitySlotsByType = VariantSelectionList<int>.LoadFrom(properties["quantitySlots"]);
SlotBgColorByType = VariantSelectionList<string>.LoadFrom(properties["slotBgColor"]);
StorageFlagsByType = VariantSelectionList<EnumItemStorageFlags>.LoadFrom(properties["storageFlags"].Token as JObject, token => (EnumItemStorageFlags)token.Value<int>());
}

public override int GetQuantitySlots(ItemStack bagstack)
Expand Down
Loading