W.I.P. preliminary Variable Item

This commit is contained in:
melchior 2021-04-24 17:55:38 -04:00
parent e4a719fcbd
commit 5691495fca
9 changed files with 397 additions and 8 deletions

View file

@ -73,6 +73,7 @@
<Compile Include="EntityBehaviors\HotbarObserverBehavior.cs" />
<Compile Include="EntityBehaviors\HotbarObserverData.cs" />
<Compile Include="Data\RecoveryEntry.cs" />
<Compile Include="Items\VariableMetalItem.cs" />
</ItemGroup>
<ItemGroup>
<None Include="modinfo.json">
@ -81,7 +82,7 @@
<None Include="assets\fma\itemtypes\metal\metal_shavings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="assets\fma\shapes\item\shavings\metal_shavings.json">
<None Include="assets\fma\shapes\item\metal\metal_shavings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="assets\fma\lang\en.json">
@ -93,6 +94,13 @@
<None Include="assets\fma\patches\hotbarobserver_for_playerentity.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="modicon.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="assets\fma\shapes\item\metal\fragments.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="assets\fma\itemtypes\metal\fragments.json" />
</ItemGroup>
<ItemGroup>
<Folder Include="assets\" />
@ -101,7 +109,7 @@
<Folder Include="assets\fma\itemtypes\" />
<Folder Include="assets\fma\itemtypes\metal\" />
<Folder Include="assets\fma\shapes\item\" />
<Folder Include="assets\fma\shapes\item\shavings\" />
<Folder Include="assets\fma\shapes\item\metal\" />
<Folder Include="assets\fma\lang\" />
<Folder Include="BlockEntities\" />
<Folder Include="assets\fma\shapes\item\tools\" />
@ -112,6 +120,7 @@
<Folder Include="EntityBehaviors\" />
<Folder Include="assets\fma\patches\" />
<Folder Include="Data\" />
<Folder Include="Items\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -0,0 +1,113 @@
using System;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.API.MathTools;
using Vintagestory.Client.NoObf;
namespace AnvilMetalRecovery
{
public class VariableMetalItem : Item
{
private const string metalQuantityKey = @"metalQuantity";
private const string metalIngotCodeKey = @"metalIngotCode";
protected ClientCoreAPI ClientAPI { get; private set; }
protected AssetLocation MetalCode(ItemStack itemStack)
{
return new AssetLocation(itemStack.Attributes.GetString(metalIngotCodeKey, @"game:ingot-copper"));
}
protected int MetalQuantity(ItemStack itemStack)
{
return itemStack.Attributes.GetInt(metalQuantityKey, 10);
}
public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
{
//Set correct material texture from ItemStack attributes
var ingotCode = MetalCode(itemstack);
var textureDonatorItem = ClientAPI.World.GetItem(ingotCode);
this.Textures["metal"] = textureDonatorItem.FirstTexture;
//renderinfo.TextureId = textureDonatorItem.FirstTexture.??
}
/* (from Itemstack -attr)
* On creation/container entry: - assign (everywhere!):
* CombustibleProps
* .SmeltedStack
* .ResolvedItemstack.
*
*/
//virtual bool CanBePlacedInto(ItemStack stack, ItemSlot slot) //Here?
//virtual void OnModifiedInInventorySlot //Only for new-Inserts (?)
//virtual bool CanSmelt //YES!
//virtual float GetMeltingDuration //Order-ops, or failsafe?
//virtual float GetMeltingPoint //Order-ops, or failsafe?
//virtual void DoSmelt //Mabey?
public void ApplyMetalProperties(RecoveryEntry become, ItemStack contStack)
{
contStack.Attributes.SetInt(metalQuantityKey, ( int )become.Quantity);
contStack.Attributes.SetString(metalIngotCodeKey, become.IngotCode.ToString( ));
if (CombustibleProps == null) {
CombustibleProps = new CombustibleProperties( ) {
SmeltingType = EnumSmeltType.Smelt,
MeltingPoint = 999,//TODO: This is where a Rules based metal propperties Master-file would help!
MeltingDuration = 123,
SmeltedRatio = ( int )Math.Round(become.Quantity * MetalRecoverySystem.IngotVoxelEquivalent, 0),
SmeltedStack = new JsonItemStack( ) { Code = become.IngotCode.Clone( ), Quantity = 1 }
};
CombustibleProps.SmeltedStack.Resolve(api.World, "VariableMetalItem_apply", true);
}
}
public void RegenerateCombustablePropsFromStack(ItemStack contStack)
{
//TODO: Lookup Metal data from Ingot-{metal} code....Clumsy!
int quantity = 1;
AssetLocation ingotCode = null;
if (CombustibleProps == null) {
CombustibleProps = new CombustibleProperties( ) {
SmeltingType = EnumSmeltType.Smelt,
MeltingPoint = 999,//TODO: This is where a Rules based metal propperties Master-file would help!
MeltingDuration = 123,
SmeltedRatio = ( int )Math.Round(quantity * MetalRecoverySystem.IngotVoxelEquivalent, 0),
SmeltedStack = new JsonItemStack( ) { Code = ingotCode.Clone( ), Quantity = 1 }
};
CombustibleProps.SmeltedStack.Resolve(api.World, "VariableMetalItem_regen", true);
}
}
public override void GetHeldItemInfo(ItemSlot inSlot, System.Text.StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
{
base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);
var metalName = Lang.Get(MetalCode(inSlot.Itemstack).ToString( ));
var metalQuantity = MetalQuantity(inSlot.Itemstack);
dsc.AppendLine(Lang.Get("metal_worth", metalQuantity, metalName));
}
}
}

View file

@ -17,7 +17,7 @@ namespace AnvilMetalRecovery
public partial class MetalRecoverySystem : ModSystem
{
internal const string anvilKey = @"Anvil";
internal const float ingotVoxelEquivalent = 2.38f;
public const float IngotVoxelEquivalent = 2.38f;
private Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = new Dictionary<AssetLocation, RecoveryEntry>();//Ammount & Material?
@ -56,8 +56,8 @@ namespace AnvilMetalRecovery
{
this.CoreAPI = api;
RegisterItemMappings( );
base.Start(api);
}
@ -107,6 +107,14 @@ namespace AnvilMetalRecovery
Mod.Logger.VerboseDebug("Anvil Metal Recovery - should be installed...");
}
private void RegisterItemMappings( )
{
this.CoreAPI.RegisterItemClass("VariableMetalItem", typeof(VariableMetalItem));
}
/*
internal void GenerateMetalShavingsItems( )
{
@ -151,7 +159,7 @@ namespace AnvilMetalRecovery
setVoxels = recipie.Voxels.OfType<bool>( ).Count(vox => vox);
#if DEBUG
Mod.Logger.VerboseDebug($"{recipie.Output.Quantity}* '{outputItem.Code}' -> {setVoxels}x '{inputObject.Code}' voxel = ~{setVoxels * ingotVoxelEquivalent:F1} metal Units");
Mod.Logger.VerboseDebug($"{recipie.Output.Quantity}* '{outputItem.Code}' -> {setVoxels}x '{inputObject.Code}' voxel = ~{setVoxels * IngotVoxelEquivalent:F1} metal Units");
#endif
if (outputItem.Tool.HasValue)
@ -194,7 +202,7 @@ namespace AnvilMetalRecovery
if (ItemFilterList.Contains(hotbarData.ItemCode)) {
#if DEBUG
var rec = itemToVoxelLookup[hotbarData.ItemCode];
Mod.Logger.VerboseDebug("broken-tool/weap. {0} WORTH: {1:F1}*{2} units", hotbarData.ItemCode.ToString( ),(rec.Quantity*ingotVoxelEquivalent), rec.IngotCode.ToShortString() );
Mod.Logger.VerboseDebug("broken-tool/weap. {0} WORTH: {1:F1}*{2} units", hotbarData.ItemCode.ToString( ),(rec.Quantity*IngotVoxelEquivalent), rec.IngotCode.ToShortString() );
#endif
}

View file

@ -0,0 +1,46 @@
{
code: "metal_fragments",
class:"VariableMetalItem",
maxstacksize: 1,
attributes: {
handbook: {
exclude: true
}
}
},
storageFlags: 5,
shape: { base: "fma:item/metal/fragments" },
textures: {
"metal": { base: "game:block/metal/plate/copper" },
},
creativeinventory: { "general": ["*"], "items": ["*"] },
materialDensity: 9000,
guiTransform: {
rotate: true,
translation: { x: -3, y: 0, z: 0 },
rotation: { x: 149, y: -30, z: 7 },
origin: { x: 0.5, y: 0.1, z: 0.5 },
scale: 3.02
},
fpHandTransform: {
translation: { x: 0, y: 0.1, z: 0 },
rotation: { x: 65, y: 21, z: -6 },
origin: { x: 0.5, y: 0.1, z: 0.5 },
scale: 2.15
},
tpHandTransform: {
translation: { x: -0.77, y: -0.15, z: -0.64 },
rotation: { x: 0, y: -71, z: 18 },
origin: { x: 0.5, y: 0.1, z: 0.5 },
scale: 0.75
},
groundTransform: {
translation: { x: 0, y: 0, z: 0 },
rotation: { x: 0, y: 0, z: 0 },
origin: { x: 0.5, y: 0, z: 0.5 },
scale: 4.8
}
}

View file

@ -20,7 +20,7 @@
],
storageFlags: 5,
shape: { base: "fma:item/shavings/metal_shavings" },
shape: { base: "fma:item/metal/metal_shavings" },
textures: {
"metal": { base: "game:block/metal/ingot/{metal}" },
},

View file

@ -22,4 +22,6 @@
"fma:item-metal_shaving-titanium": "Titanium Shavings",
"fma:item-metal_shaving-uranium": "Uranium Shavings",
"fma:item-metal_shaving-zinc": "Zinc Shavings",
"fma:item-metal_fragments":"Broken (metal) Fragments.",
"fma:metal_worth":"worth {0} units of {1}.",
}

View file

@ -0,0 +1,211 @@
{
"editor": {
"allAngles": true,
"entityTextureMode": false
},
"textureWidth": 16,
"textureHeight": 16,
"textureSizes": {
},
"textures": {
"metal": "game:block/metal/plate/copper"
},
"elements": [
{
"name": "Base_part",
"from": [ 5.0, 0.0, 5.0 ],
"to": [ 9.0, 2.0, 8.0 ],
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 4.0, 2.0 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 3.0, 2.0 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 4.0, 2.0 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 3.0, 2.0 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 4.0, 3.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 4.0, 3.0 ] }
},
"children": [
{
"name": "Fragment1",
"from": [ 0.0, 1.01, 3.85 ],
"to": [ 8.0, 2.01, 4.85 ],
"rotationOrigin": [ 0.0, 0.0, 4.0 ],
"rotationX": 51.0,
"rotationY": 3.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 8.0, 1.0 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 8.0, 1.0 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 8.0, 1.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 8.0, 1.0 ] }
}
},
{
"name": "Fragment2",
"from": [ 7.0, 0.0, 3.0 ],
"to": [ 9.0, 0.75, 5.0 ],
"rotationOrigin": [ 7.0, 0.0, 3.0 ],
"rotationY": -119.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 2.0, 0.5 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 2.0, 0.5 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 2.0, 0.5 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 2.0, 0.5 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 2.0, 2.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 2.0, 2.0 ] }
}
},
{
"name": "Fragment3",
"from": [ -0.45, 0.0, 6.0 ],
"to": [ 0.8, 1.25, 7.25 ],
"rotationOrigin": [ 0.0, 0.0, 7.0 ],
"rotationY": 69.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
}
},
{
"name": "Fragment4",
"from": [ 4.6, 0.8, -0.7 ],
"to": [ 6.35, 2.55, 5.3 ],
"rotationOrigin": [ 5.1, 2.3, 0.3 ],
"rotationX": -14.0,
"rotationZ": -25.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.5, 1.5 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 6.0, 1.5 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.5, 1.5 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 6.0, 1.5 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.5, 6.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.5, 6.0 ] }
}
},
{
"name": "Fragment5",
"from": [ -1.0, 0.0, -3.0 ],
"to": [ -0.5, 0.5, 0.5 ],
"rotationOrigin": [ -1.0, 0.0, -1.0 ],
"rotationY": -53.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 0.5 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 3.5, 0.5 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 0.5 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 3.5, 0.5 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 3.5 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 3.5 ] }
}
},
{
"name": "Fragment7",
"from": [ 3.0, 0.0, -3.0 ],
"to": [ 3.5, 0.5, 0.5 ],
"rotationOrigin": [ 3.0, 0.0, -1.0 ],
"rotationY": 77.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 0.5 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 3.5, 0.5 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 0.5 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 3.5, 0.5 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 3.5 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 3.5 ] }
}
},
{
"name": "Fragment8",
"from": [ 1.0, 2.0, 1.0 ],
"to": [ 2.0, 3.0, 2.0 ],
"rotationOrigin": [ 1.0, 2.0, 1.0 ],
"rotationY": 11.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
}
},
{
"name": "Fragment9",
"from": [ 5.8, 0.0, 1.0 ],
"to": [ 6.8, 1.0, 2.0 ],
"rotationOrigin": [ 5.8, 0.0, 1.0 ],
"rotationY": 8.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
}
},
{
"name": "Fragment10",
"from": [ 0.0, 0.0, 2.75 ],
"to": [ 1.0, 1.0, 3.75 ],
"rotationOrigin": [ 0.0, 1.0, 4.0 ],
"rotationY": -44.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
}
},
{
"name": "Fragment11",
"from": [ 1.0, 0.0, 6.0 ],
"to": [ 1.5, 0.5, 9.5 ],
"rotationOrigin": [ 0.0, 0.0, 5.0 ],
"rotationY": 174.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 0.5 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 3.5, 0.5 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 0.5 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 3.5, 0.5 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 3.5 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 0.5, 3.5 ] }
}
},
{
"name": "Fragment12",
"from": [ 2.5, 0.0, 3.15 ],
"to": [ 3.5, 1.0, 4.15 ],
"rotationOrigin": [ 3.0, 2.0, 3.0 ],
"rotationY": 11.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
}
},
{
"name": "Fragment13",
"from": [ 0.4, 0.0, -1.0 ],
"to": [ 1.4, 1.0, 0.0 ],
"rotationOrigin": [ 1.4, 2.0, -1.0 ],
"rotationY": -13.0,
"faces": {
"north": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"east": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"south": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"west": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"up": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
"down": { "texture": "#metal", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
}
}
]
}
]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB