W.I.P. Transition still not quite working

This commit is contained in:
melchior 2020-07-12 18:53:31 -04:00
parent 33410a2b2c
commit e2e81139fa
4 changed files with 98 additions and 33 deletions

View file

@ -22,7 +22,6 @@ namespace ElementalTools
internal const string fmaKey = @"fma";
internal const string pack_carburizationClassKey = @"PackCarburization";
internal const string pack_carburizationBEKey = @"PackCarburizationEntity";
internal const string PackCarburizationEntityNameKey = @"PackCarburizationEntity";
internal const string IronNameKey = @"iron";
@ -39,7 +38,7 @@ namespace ElementalTools
private void RegisterBlockClasses( )
{
CoreAPI.RegisterBlockClass(pack_carburizationClassKey, typeof(PackCarburization));
CoreAPI.RegisterBlockEntityClass(pack_carburizationBEKey, typeof(PackCarburizationEntity));
CoreAPI.RegisterBlockEntityClass(PackCarburizationEntityNameKey, typeof(PackCarburizationEntity));
}
private void ManipulateGridRecipies( )

View file

@ -24,15 +24,18 @@ namespace ElementalTools
//Heat to 'Red' hot for ~ 30-60 minutes (equive to ??? game cook time ??? )
//Output 'Blister' steel... not 'Shear' steel
internal PackCarburizationEntity Entity(BlockPos here)
{
var pcEnt = api.World.BlockAccessor.GetBlockEntity(here) as PackCarburizationEntity;
if (pcEnt == null) {
api.World.Logger.Warning($"PackCarburization [{here}]: BlockEntity NULL! (regenerating)");
api.World.Logger.Warning($"PackCarburization [{here}]: {this.EntityClass} Not-present/NULL! (regenerating)");
api.World.BlockAccessor.SpawnBlockEntity(ElementalToolsSystem.PackCarburizationEntityNameKey, here);
pcEnt = api.World.BlockAccessor.GetBlockEntity(here) as PackCarburizationEntity;
}
return null;
return pcEnt;
}
public float SteelTransitionTemp {
@ -55,6 +58,13 @@ namespace ElementalTools
}
}
public string State {
get
{
return this.Variant[@"type"];
}
}
/// <summary>
/// Clone Recipie component data / attributes
/// </summary>
@ -77,10 +87,10 @@ namespace ElementalTools
//outputSlot.Itemstack.Attributes = ironThingSlot.Itemstack.Attributes.Clone( );
ItemStack[ ] encapsulatedItems = new ItemStack[ ] { ironThingSlot.Itemstack.Clone( ) };//More than 1 or Quantity *#
ItemStack[ ] encapsulatedItems = new ItemStack[ ] { ironThingSlot.Itemstack.Clone( ) };
encapsulatedItems.First( ).StackSize = 1;//There can be only 1, per pack
SetContents(outputSlot.Itemstack, encapsulatedItems );
}
/// <summary>
@ -251,15 +261,14 @@ namespace ElementalTools
}
outputStack.Attributes = contentStack.Attributes.Clone( );
outputStack.TempAttributes = contentStack.TempAttributes.Clone( );
//outputStack.Attributes = contentStack.Attributes.Clone( );
//outputStack.TempAttributes = contentStack.TempAttributes.Clone( );
outputStack.Collectible.SetTemperature(world, outputStack, temperature);
firedPack.SetContents(outputStack, GetContents(world, contentStack));
SetTemperature(world, outputStack, temperature - 100f, false);
firedPack.SetContents(outputStack, GetContents(world, contentStack));
outputSlot.Itemstack = outputStack;
inputSlot.Itemstack = null;
//inputSlot.MarkDirty( );
//outputSlot.MarkDirty(); //?
outputSlot.MarkDirty(); //?
#if DEBUG
world.Logger.VerboseDebug("Finished: 'DoSmelt' " );
#endif
@ -273,6 +282,7 @@ namespace ElementalTools
}
public override bool CanSpoil(ItemStack itemstack)
{
return false;
@ -304,6 +314,48 @@ namespace ElementalTools
}
public override float OnGettingBroken(IPlayer player, BlockSelection blockSel, ItemSlot itemslot, float remainingResistance, float dt, int counter)
{
EnumTool? tool = itemslot.Itemstack?.Collectible?.Tool;
if (tool == EnumTool.Hammer || tool == EnumTool.Pickaxe || tool == EnumTool.Shovel || tool == EnumTool.Sword || tool == EnumTool.Spear || tool == EnumTool.Axe || tool == EnumTool.Hoe) {
if (counter % 5 == 0 || remainingResistance <= 0) {
double posx = blockSel.Position.X + blockSel.HitPosition.X;
double posy = blockSel.Position.Y + blockSel.HitPosition.Y;
double posz = blockSel.Position.Z + blockSel.HitPosition.Z;
player.Entity.World.PlaySoundAt(remainingResistance > 0 ? Sounds.GetHitSound(player) : Sounds.GetBreakSound(player), posx, posy, posz, player, true, 16, 1);
}
return remainingResistance - 0.05f;
}
return base.OnGettingBroken(player, blockSel, itemslot, remainingResistance, dt, counter);
}
public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
{
SimpleParticleProperties ash =
new SimpleParticleProperties(
9, 18,
ColorUtil.ToRgba(127, 222, 222, 222),
new Vec3d(pos.X, pos.Y, pos.Z),
new Vec3d(pos.X + 1, pos.Y + 1, pos.Z + 1),
new Vec3f(-0.2f, -0.1f, -0.2f),
new Vec3f(0.2f, 0.2f, 0.2f),
1.5f,
0,
0.5f,
1.0f,
EnumParticleModel.Quad
);
ash.OpacityEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, -200);
ash.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, 2);
world.SpawnParticles(ash);
base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);
}
}
}

View file

@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Text;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.GameContent;
@ -8,6 +10,7 @@ namespace ElementalTools
{
public class PackCarburizationEntity : BlockEntityContainer
{
private const string _invName = @"carburization_pack";
//Item Container for Iron object to convert...
internal InventoryGeneric internalInventory;
@ -22,7 +25,7 @@ namespace ElementalTools
public override string InventoryClassName {
get
{
return @"Packcarburization_Inventory";
return _invName;
}
}
@ -30,36 +33,30 @@ namespace ElementalTools
get { return base.Block as PackCarburization; }
}
public float Temperature { get; private set; }
public float Temperature { get; set; }
public PackCarburizationEntity( )
{
internalInventory = new InventoryGeneric(1, null, null);
public PackCarburizationEntity( )
{
internalInventory = new InventoryGeneric(1, _invName+"-0", null);//required: 'Instance ID' is a Dummy...token (real value set later)
}
public override void Initialize(ICoreAPI api)
{
base.Initialize(api);
}
protected override void OnTick(float dt)
{
//Soak up Carbon; Transform into S-T-E-E-L .... eventually.
if (this.Temperature > 20) {
this.Temperature -= 1f;//Rain? Compute vs. ambient temp / biome, on snow/ice...
}
if (!internalInventory.IsEmpty) {
foreach (ItemSlot slot in internalInventory) {
if (slot.Itemstack == null) continue;
if (slot.Empty) continue;
AssetLocation objCode = slot.Itemstack.Collectible.Code;
slot.Itemstack.Collectible.SetTemperature(this.Api.World, slot.Itemstack, Temperature, true);
if (Temperature > this.Block.SteelTransitionTemp) {
//Convert here or on 'DoSmelt' ?
//Which is really mostly about the clay container...not quenching to make it Martensite
}
slot.Itemstack.Collectible.SetTemperature(this.Api.World, slot.Itemstack, Temperature, false);
}
MarkDirty(true);
@ -86,13 +83,30 @@ namespace ElementalTools
else {
foreach (var thing in internalInventory) {
if (thing.Empty) continue;
dsc.AppendFormat("{1} \u00d7 {0}\n", thing.Itemstack.GetName( ), thing.StackSize);
}
}
}
//OnBlockPlaced -- Perform base call!
public override void OnBlockPlaced(ItemStack byItemStack = null)
{
if (byItemStack != null ) {
var contents = this.Block.GetContents(this.Api.World, byItemStack);
if (contents != null || contents.Length == 0) return;
internalInventory[0].Itemstack = contents.First( ).Clone( );
//internalInventory[0].Itemstack.SetFrom(byItemStack);
var temp =this.Block.GetTemperature(this.Api.World, byItemStack);
this.Temperature = temp;
}
else {
Api.World.Logger.VerboseDebug("No items in Stacks?! - thus empty...");
}
}
}
}

View file

@ -2,7 +2,7 @@
"itemdesc-mallet": "Basicaly LOG on a stick\n the ORGANIC Alternative to Hammers.",
"item-mallet":"Mallet",
"item-carburization_powder":"Carburization Powder",
"itemdesc-carburization_powder":"A 'magical' dark grey dust...ask the metal sages how its used...",
"block-pack_carbirization-*":"Carburization Pack",
"blockdesc-pack_carbirization-*":"A new Metal age dawns...SOOON!",
"itemdesc-carburization_powder":"A 'magical' dark grey dust...ask the metal sages how its used...",
"fma:block-pack_carburization-*":"Carburization Pack",
"fma:blockdesc-pack_carbirization-*":"A new Metal age dawns...SOOON!",
}