added Mold breakage, Recovery behavior W.I.P.

This commit is contained in:
melchior 2022-08-06 20:37:41 -04:00
parent 1f65f75ca5
commit 8b9565f2f7
8 changed files with 182 additions and 50 deletions

View file

@ -87,6 +87,7 @@
<Compile Include="Data\AMR_Config.cs" />
<Compile Include="Data\RecoveryEntryTable.cs" />
<Compile Include="Blocks\BlockWateringCanPlus.cs" />
<Compile Include="BlockBehaviors\MoldDestructionRecovererBehavior.cs" />
</ItemGroup>
<ItemGroup>
<None Include="modinfo.json">
@ -153,6 +154,7 @@
<Folder Include="Blocks\" />
<Folder Include="assets\fma\sounds\" />
<Folder Include="assets\fma\sounds\sfx\" />
<Folder Include="BlockBehaviors\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -0,0 +1,57 @@
using System;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.Common.Entities;
using Vintagestory.API.Config;
using Vintagestory.API.Datastructures;
using Vintagestory.API.MathTools;
using Vintagestory.API.Server;
using Vintagestory.GameContent;
namespace AnvilMetalRecovery
{
public class MoldDestructionRecovererBehavior : BlockBehavior
{
public static readonly string BehaviorClassName = @"MoldDestructionRecoverer";
public MoldDestructionRecovererBehavior(Block block) : base(block)
{
}
public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
{
if (world.Api.Side.IsClient( )) return;
ICoreAPI CoreAPI = world.Api;
ICoreServerAPI ServerAPI = world.Api as ICoreServerAPI;
#if DEBUG
world.Api.Logger.VerboseDebug("MoldDestructionRecovererBehavior::OnBlockBroken");
#endif
var someBlock = ServerAPI.World.BlockAccessor.GetBlock(pos);
var someBlockEntity = ServerAPI.World.BlockAccessor.GetBlockEntity(pos);
if (someBlockEntity is BlockEntityIngotMold) {
var ingotMold = someBlockEntity as BlockEntityIngotMold;
#if DEBUG
world.Api.Logger.VerboseDebug("{0} Ingot Mold(s) with L {1} Units, R {2} Units", ingotMold.quantityMolds, ingotMold.fillLevelLeft, ingotMold.fillLevelRight);
#endif
}
if (someBlockEntity is BlockEntityToolMold) {
var toolMold = someBlockEntity as BlockEntityToolMold;
#if DEBUG
world.Api.Logger.VerboseDebug("Tool Mold with {0} Units", toolMold.fillLevel);
#endif
}
}
}
}

View file

@ -5,6 +5,7 @@ using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.Common.Entities;
using Vintagestory.API.Config;
using Vintagestory.API.Datastructures;
using Vintagestory.API.MathTools;
using Vintagestory.API.Server;
using Vintagestory.GameContent;
@ -13,7 +14,29 @@ namespace AnvilMetalRecovery
{
public class BlockWateringCanPlus : BlockWateringCan
{
private const float coolRateDefault = 5.0f;
private const float coolRateDefault = 0.0075f;
private const float flashPointTemp = 100f;
private SimpleParticleProperties steamParticles = new SimpleParticleProperties {
MinPos = new Vec3d(),
AddPos = new Vec3d( ),
MinQuantity = 6,
AddQuantity = 12,
Color = ColorUtil.ToRgba(100, 225, 225, 225),
OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, 1.0f),
GravityEffect = -0.015f,
WithTerrainCollision = false,
ShouldDieInLiquid = true,
ParticleModel = EnumParticleModel.Quad,
LifeLength = 2.0f,
MinVelocity = new Vec3f(-0.25f, 0.1f, -0.25f),
AddVelocity = new Vec3f(0.25f, 0.1f, 0.25f),
MinSize = 0.075f,
MaxSize = 0.1f,
WindAffected = true,
WindAffectednes = 0.4f,
};
protected ICoreAPI CoreAPI { get { return this.api; } }
protected ICoreServerAPI ServerAPI { get { return this.api as ICoreServerAPI; } }
@ -37,12 +60,18 @@ namespace AnvilMetalRecovery
/// </remarks>
public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
{
#if DEBUG
this.api.Logger.VerboseDebug("BlockWateringCanPlus::OnHeldInteractStep");
var result = base.OnHeldInteractStep(secondsUsed, slot, byEntity, blockSel, entitySel);
#endif
PerformBlockCooling(secondsUsed, slot, byEntity, blockSel, entitySel);
return base.OnHeldInteractStep(secondsUsed, slot, byEntity, blockSel, entitySel);
}
return result;
public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
{
base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);
dsc.AppendLine(Lang.Get(@"fma:spray_cooler_text"));
}
private void PerformBlockCooling(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
@ -50,35 +79,45 @@ namespace AnvilMetalRecovery
if (blockSel == null) return;
if (byEntity.Controls.Sneak) return;
if ((DateTime.Now.Millisecond / 100) % 2 == 1) return;
BlockPos targetPos = blockSel.Position;
if (this.GetRemainingWateringSeconds(slot.Itemstack) >= 0.1f)
if (!slot.Empty && this.GetRemainingWateringSeconds(slot.Itemstack) >= 0.1f)
{
var server = (CoreAPI.World.Side.IsServer());
var server = (CoreAPI.World.Side.IsServer());
var someBlock = CoreAPI.World.BlockAccessor.GetBlock(targetPos);
if (someBlock != null
&& someBlock.BlockMaterial == EnumBlockMaterial.Ceramic
&& (someBlock.Class == @"BlockIngotMold" || someBlock.Class == @"BlockToolMold"))
{
var someBlockEntity = CoreAPI.World.BlockAccessor.GetBlockEntity(targetPos);
var someBlockEntity = server ? ServerAPI.World.BlockAccessor.GetBlockEntity(targetPos) : ClientAPI.World.BlockAccessor.GetBlockEntity(targetPos);
#if DEBUG
this.api.Logger.VerboseDebug("Ok, its an Tool/Ingot mold.: {0}",someBlockEntity);
#endif
if (someBlockEntity is BlockEntityIngotMold) {
var rightSide = AimAtRight(blockSel.HitPosition);
var ingotMold = someBlockEntity as BlockEntityIngotMold;
if (ingotMold.fillSide && ingotMold.fillLevelRight > 0 && ingotMold.IsLiquidRight) {
if (server) CoolContents(ingotMold.contentsRight); else GenerateSpecialEffects(blockSel.HitPosition);
if (rightSide && (ingotMold.fillLevelRight > 0 && ingotMold.TemperatureRight > flashPointTemp)) {
if (server) CoolContents(ingotMold.contentsRight); else GenerateSpecialEffects(blockSel.Position, blockSel.HitPosition, byEntity as EntityPlayer);
ingotMold.MarkDirty( );
}
else if (ingotMold.fillLevelLeft > 0 && ingotMold.IsLiquidLeft) {
if (server) CoolContents(ingotMold.contentsLeft); else GenerateSpecialEffects(blockSel.HitPosition);
else if (ingotMold.fillLevelLeft > 0 && ingotMold.TemperatureLeft > flashPointTemp) {
if (server) CoolContents(ingotMold.contentsLeft); else GenerateSpecialEffects(blockSel.Position, blockSel.HitPosition, byEntity as EntityPlayer);
ingotMold.MarkDirty( );
}
return;
}
if (someBlockEntity is BlockEntityToolMold) {
var toolMold = someBlockEntity as BlockEntityToolMold;
if (toolMold.fillLevel > 0 && toolMold.IsLiquid) {
if (server) CoolContents(toolMold.metalContent); else GenerateSpecialEffects(blockSel.HitPosition);
if (toolMold.fillLevel > 0 && toolMold.Temperature > flashPointTemp) {
if (server) CoolContents(toolMold.metalContent); else GenerateSpecialEffects(blockSel.Position, blockSel.HitPosition, byEntity as EntityPlayer );
toolMold.MarkDirty( );
}
return;
}
@ -86,39 +125,37 @@ namespace AnvilMetalRecovery
}
}
internal void GenerateSpecialEffects(Vec3d here)
internal void GenerateSpecialEffects(BlockPos blockLoc, Vec3d aimPoint, EntityPlayer playerEntity)
{
var steamParticles = new SimpleParticleProperties {
MinPos = here,
AddPos = here.AddCopy(0.1,0.1,0.1),
MinQuantity = 8,
AddQuantity = 24,
Color = ColorUtil.ToRgba(100, 225, 225, 225),
GravityEffect = -0.015f,
WithTerrainCollision = true,
ParticleModel = EnumParticleModel.Quad,
LifeLength = 2.0f,
MinVelocity = new Vec3f(-0.25f, 0.1f, -0.25f),
AddVelocity = new Vec3f(0.25f, 0.1f, 0.25f),
MinSize = 0.075f,
MaxSize = 0.1f,
//VertexFlags = 32
};
ClientAPI.World.SpawnParticles(steamParticles );
ClientAPI.World.PlaySoundAt(CoolSoundEffect, here.X,here.Y,here.Z, null, false, 16 );
if ((DateTime.Now.Millisecond / 333) % 2 == 1) return;
steamParticles.MinPos = blockLoc.ToVec3d().AddCopy(aimPoint);
steamParticles.AddPos = new Vec3d(0.05f, 0f, 0.05f);
#if DEBUG
api.Logger.VerboseDebug("Generate steam particles");
#endif
ClientAPI.World.SpawnParticles(steamParticles, playerEntity.Player );
ClientAPI.World.PlaySoundAt(CoolSoundEffect, playerEntity, playerEntity.Player, randomizePitch: false, volume: 0.5f);
}
internal void CoolContents(ItemStack itemStack)
{
var temperature = itemStack.Collectible.GetTemperature(CoreAPI.World, itemStack);
if (temperature > 25f)//TODO: USE local AMBIENT Temp
itemStack.Collectible.SetTemperature(CoreAPI.World, itemStack, (temperature - coolRateDefault), false);
if (temperature > 20f)//TODO: USE local AMBIENT Temp
itemStack.Collectible.SetTemperature(CoreAPI.World, itemStack, temperature - (temperature * coolRateDefault), false);
(itemStack.Attributes["temperature"] as ITreeAttribute)?.SetFloat("cooldownSpeed", 400);
#if DEBUG
CoreAPI.Logger.VerboseDebug("Reduced Molten metal temp: {0:F1} ", temperature);
CoreAPI.Logger.VerboseDebug("Cooled Molten metal, temp: {0:F1} ", temperature);
#endif
}
internal bool AimAtRight(Vec3d hitPosition)
{
return hitPosition.X >= 0.5f;
}
}
}

View file

@ -14,14 +14,14 @@ namespace AnvilMetalRecovery
{
ToolFragmentRecovery = true;
VoxelEquivalentValue = MetalRecoverySystem.IngotVoxelDefault;
ToolRecoveryRate = 1.0f;
ToolRecoveryRate = 0.95f;
}
public AMRConfig(bool setDefaultBL)
{
ToolFragmentRecovery = true;
VoxelEquivalentValue = MetalRecoverySystem.IngotVoxelDefault;
ToolRecoveryRate = 1.0f;
ToolRecoveryRate = 0.95f;
if (setDefaultBL) {
BlackList = new List<AssetLocation> {
new AssetLocation(@"game:metalplate"),

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using HarmonyLib;
@ -108,7 +109,7 @@ namespace AnvilMetalRecovery
this.CoreAPI = api;
RegisterItemMappings( );
//RegisterBlockBehaviors( );
RegisterBlockBehaviors( );
#if DEBUG
@ -138,7 +139,8 @@ namespace AnvilMetalRecovery
ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, PersistServersideConfig);
ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering);
PerformBlockClassSwaps();
ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.RunGame, CacheRecoveryDataTable);
ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.RunGame, CacheRecoveryDataTable);
ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.GameReady, AttachExtraBlockBehaviors);
SetupGeneralObservers( );
@ -181,14 +183,9 @@ namespace AnvilMetalRecovery
#if DEBUG
Mod.Logger.Debug("RegisterBlockBehaviors");
#endif
//this.CoreAPI.RegisterBlockBehaviorClass(DirectSprayCooler_Behavior.ClassName, typeof(DirectSprayCooler_Behavior));
//this.CoreAPI.RegisterCollectibleBehaviorClass(DirectSprayCooler_Behavior.ClassName, typeof(DirectSprayCooler_Behavior));
}
private void PerformBlockClassSwaps(float delta = 0.0f)
{
PerformBlockClassSwaps( );
}
this.CoreAPI.RegisterBlockBehaviorClass(MoldDestructionRecovererBehavior.BehaviorClassName, typeof(MoldDestructionRecovererBehavior));
this.CoreAPI.RegisterCollectibleBehaviorClass(MoldDestructionRecovererBehavior.BehaviorClassName, typeof(MoldDestructionRecovererBehavior));
}
private void PerformBlockClassSwaps()
{
@ -198,6 +195,42 @@ namespace AnvilMetalRecovery
this.ClientCore.ClassRegistryNative.ReplaceBlockClassType(BlockWateringCanPlus.BlockClassName, typeof(BlockWateringCanPlus));
}
private void AttachExtraBlockBehaviors()
{
Collection<AssetLocation> mold_behaviorsAppendList = new Collection<AssetLocation>( ) {
new AssetLocation(@"game",@"ingotmold-burned"),
new AssetLocation(@"game",@"toolmold-burned-*"),
};
var moldRecoverBehaviorType = ServerAPI.ClassRegistry.GetBlockBehaviorClass(MoldDestructionRecovererBehavior.BehaviorClassName);
foreach (var assetName in mold_behaviorsAppendList) {
if (!assetName.IsWildCard)
{
this.CoreAPI.AddBlockBehavior(assetName, MoldDestructionRecovererBehavior.BehaviorClassName, moldRecoverBehaviorType);
#if DEBUG
Mod.Logger.VerboseDebug("Attached Block-Behavior {0} to '{1}' ", MoldDestructionRecovererBehavior.BehaviorClassName, assetName);
#endif
}
else {
var searchResults = ServerAPI.World.SearchBlocks(assetName);
if (searchResults != null && searchResults.Length > 0) {
#if DEBUG
Mod.Logger.VerboseDebug("Attaching Block-Behaviors, wildcard matches from '{0}'", assetName);
#endif
for (int index = 0; index < searchResults.Length; index++)
{
var matchBlock = searchResults[index];
this.CoreAPI.AddBlockBehavior(matchBlock.Code, MoldDestructionRecovererBehavior.BehaviorClassName, moldRecoverBehaviorType);
#if DEBUG
Mod.Logger.VerboseDebug("Attached Block-Behavior {0} to '{1}' ", MoldDestructionRecovererBehavior.BehaviorClassName, matchBlock.Code);
#endif
}
}
}
}
}
private void SetupGeneralObservers( ){
ServerCore.Event.RegisterEventBusListener(Item_DamageEventReciever, 1.0f, ItemDamageChannelName);
}

View file

@ -23,4 +23,7 @@
"fma:item-metal_shaving-titanium": "Rebarbas de titânio",
"fma:item-metal_shaving-uranium": "Rebarbas de urânio",
"fma:item-metal_shaving-zinc": "Rebarbas de zinco",
"fma:item-metal_fragments":"Fragmentos de metal.",
"fma:itemdesc-item-metal_fragments": "Tente, partir isso com um cinzel...",
"fma:metal_worth":"vale {0} unidades de {1}."
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Before After
Before After

View file

@ -4,7 +4,7 @@
"description" : "Get back smithing discards and broken tool scrap! Plus lots more.",
"authors": ["Melchior"],
"ModID":"metalrecovery",
"version": "0.1.18-pre.0",
"version": "0.1.18-rc.1",
"dependencies": {
"game": "1.16.5",
"survival": ""