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
1 change: 0 additions & 1 deletion .idea/.idea.Electricity/.idea/.name

This file was deleted.

59 changes: 58 additions & 1 deletion Electricity/Content/Block/Accumulator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
using System;
using System.Text;
using ElectricityUnofficial.Interface;
using ElectricityUnofficial.Utils;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.API.MathTools;

namespace Electricity.Content.Block {
public class Accumulator : Vintagestory.API.Common.Block {
public class Accumulator : Vintagestory.API.Common.Block,IEnergyStorageItem {
public int maxcapacity;
public override void OnLoaded(ICoreAPI api)
{
base.OnLoaded(api);

maxcapacity = AttributeGetter.GetAttributeInt(this, "maxstorage", 16000);
Durability = 100;
}

public int receiveEnergy(ItemStack itemstack, int maxReceive)
{
int energy = itemstack.Attributes.GetInt("electricity:energy", 0);
int received = Math.Min(maxcapacity - energy, maxReceive);
itemstack.Attributes.SetInt("electricity:energy", energy + received);
int durab = (energy + received) / (maxcapacity / GetDurability(itemstack));
itemstack.Attributes.SetInt("durability", durab);
return received;
}
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode) {
return world.BlockAccessor
.GetBlock(blockSel.Position.AddCopy(BlockFacing.DOWN))
Expand All @@ -21,5 +44,39 @@ public override void OnNeighbourBlockChange(IWorldAccessor world, BlockPos pos,
world.BlockAccessor.BreakBlock(pos, null);
}
}

public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
{
base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);
dsc.AppendLine(Lang.Get("Storage") + inSlot.Itemstack.Attributes.GetInt("electricity:energy", 0) + "/" + maxcapacity + "⚡   ");
}

public override ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
{
Entity.Accumulator? be = world.BlockAccessor.GetBlockEntity(pos) as Entity.Accumulator;
ItemStack item = new ItemStack(world.BlockAccessor.GetBlock(pos));
if (be != null) item.Attributes.SetInt("electricity:energy", be.GetBehavior<Entity.Behavior.Accumulator>().GetCapacity());
if (be != null) item.Attributes.SetInt("durability", (100 * be.GetBehavior<Entity.Behavior.Accumulator>().GetCapacity() / maxcapacity));
return new ItemStack[] {item};
}

public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
{
Entity.Accumulator? be = world.BlockAccessor.GetBlockEntity(pos) as Entity.Accumulator;
ItemStack item = new ItemStack(world.BlockAccessor.GetBlock(pos));
if (be != null) item.Attributes.SetInt("electricity:energy", be.GetBehavior<Entity.Behavior.Accumulator>().GetCapacity());
if (be != null) item.Attributes.SetInt("durability", (100 * be.GetBehavior<Entity.Behavior.Accumulator>().GetCapacity() / maxcapacity));
return item;
}

public override void OnBlockPlaced(IWorldAccessor world, BlockPos blockPos, ItemStack byItemStack = null)
{
base.OnBlockPlaced(world, blockPos, byItemStack);
if (byItemStack != null)
{
Entity.Accumulator? be = world.BlockAccessor.GetBlockEntity(blockPos) as Entity.Accumulator;
be.GetBehavior<Entity.Behavior.Accumulator>().Store(byItemStack.Attributes.GetInt("electricity:energy", 0));
}
}
}
}
6 changes: 4 additions & 2 deletions Electricity/Content/Block/Entity/Behavior/Accumulator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Text;
using Electricity.Interface;
using Electricity.Utils;
using ElectricityUnofficial.Utils;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.API.Datastructures;

namespace Electricity.Content.Block.Entity.Behavior {
Expand All @@ -12,7 +14,7 @@ public Accumulator(BlockEntity blockEntity) : base(blockEntity) {
}

public int GetMaxCapacity() {
return 16000;
return AttributeGetter.GetAttributeInt(this.Block, "maxcapacity", 16000);
}

public int GetCapacity() {
Expand Down Expand Up @@ -43,7 +45,7 @@ public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder
base.GetBlockInfo(forPlayer, stringBuilder);

stringBuilder.AppendLine(StringHelper.Progressbar(this.GetCapacity() * 100.0f / this.GetMaxCapacity()));
stringBuilder.AppendLine("└ Storage: " + this.GetCapacity() + "/" + this.GetMaxCapacity() + "⚡   ");
stringBuilder.AppendLine("└ " + Lang.Get("Storage") + this.GetCapacity() + "/" + this.GetMaxCapacity() + "⚡   ");
stringBuilder.AppendLine();
}
}
Expand Down
5 changes: 3 additions & 2 deletions Electricity/Content/Block/Entity/Behavior/ElectricForge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Electricity.Interface;
using Electricity.Utils;
using Vintagestory.API.Common;
using Vintagestory.API.Config;

namespace Electricity.Content.Block.Entity.Behavior {
public class ElectricForge : BlockEntityBehavior, IElectricConsumer {
Expand Down Expand Up @@ -29,8 +30,8 @@ public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder
base.GetBlockInfo(forPlayer, stringBuilder);

stringBuilder.AppendLine(StringHelper.Progressbar(this.powerSetting));
stringBuilder.AppendLine("├ Consumption: " + this.powerSetting + "/" + 100 + "⚡   ");
stringBuilder.AppendLine("└ Temperature: " + this.maxTemp + "° (max.)");
stringBuilder.AppendLine("├ " + Lang.Get("Consumption") + this.powerSetting + "/" + 100 + "⚡   ");
stringBuilder.AppendLine("└ " + Lang.Get("Temperature") + this.maxTemp + "° (max.)");
stringBuilder.AppendLine();
}
}
Expand Down
9 changes: 5 additions & 4 deletions Electricity/Content/Block/Entity/Behavior/Electricity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Electricity.Interface;
using Electricity.Utils;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.API.Datastructures;
using Vintagestory.API.Util;

Expand Down Expand Up @@ -100,14 +101,14 @@ public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder
var networkInformation = this.System?.GetNetworks(this.Blockentity.Pos, this.Connection);

stringBuilder
.AppendLine("Electricity")
.AppendLine(Lang.Get("Electricity"))
// .AppendLine("├ Number of consumers: " + networkInformation?.NumberOfConsumers)
// .AppendLine("├ Number of producers: " + networkInformation?.NumberOfProducers)
// .AppendLine("├ Number of accumulators: " + networkInformation?.NumberOfAccumulators)
// .AppendLine("├ Block: " + networkInformation?.NumberOfBlocks)
.AppendLine("├ Production: " + networkInformation?.Production + "⚡   ")
.AppendLine("├ Consumption: " + networkInformation?.Consumption + "⚡   ")
.AppendLine("└ Overflow: " + networkInformation?.Overflow + "⚡   ");
.AppendLine("├ " + Lang.Get("Production") + networkInformation?.Production + "⚡   ")
.AppendLine("├ " + Lang.Get("Consumption") + networkInformation?.Consumption + "⚡   ")
.AppendLine("└ " + Lang.Get("Overflow") + networkInformation?.Overflow + "⚡   ");
}


Expand Down
3 changes: 2 additions & 1 deletion Electricity/Content/Block/Entity/Behavior/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Electricity.Utils;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.API.MathTools;
using Vintagestory.API.Server;
using Vintagestory.GameContent.Mechanics;
Expand Down Expand Up @@ -150,7 +151,7 @@ public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder
base.GetBlockInfo(forPlayer, stringBuilder);

stringBuilder.AppendLine(StringHelper.Progressbar(this.powerSetting));
stringBuilder.AppendLine("└ Production: " + this.powerSetting + "/" + 100 + "⚡   ");
stringBuilder.AppendLine("└ "+ Lang.Get("Production") + this.powerSetting + "/" + 100 + "⚡   ");
stringBuilder.AppendLine();
}
}
Expand Down
3 changes: 2 additions & 1 deletion Electricity/Content/Block/Entity/Behavior/Heater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Electricity.Interface;
using Electricity.Utils;
using Vintagestory.API.Common;
using Vintagestory.API.Config;

namespace Electricity.Content.Block.Entity.Behavior {
public class Heater : BlockEntityBehavior, IElectricConsumer {
Expand Down Expand Up @@ -46,7 +47,7 @@ public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder
base.GetBlockInfo(forPlayer, stringBuilder);

stringBuilder.AppendLine(StringHelper.Progressbar(this.HeatLevel * 100.0f / 8.0f));
stringBuilder.AppendLine("└ Consumption: " + this.HeatLevel + "/" + 8 + "⚡   ");
stringBuilder.AppendLine("└ "+ Lang.Get("Consumption") + this.HeatLevel + "/" + 8 + "⚡   ");
stringBuilder.AppendLine();
}
}
Expand Down
3 changes: 2 additions & 1 deletion Electricity/Content/Block/Entity/Behavior/Lamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Electricity.Interface;
using Electricity.Utils;
using Vintagestory.API.Common;
using Vintagestory.API.Config;

namespace Electricity.Content.Block.Entity.Behavior {
public class Lamp : BlockEntityBehavior, IElectricConsumer {
Expand Down Expand Up @@ -46,7 +47,7 @@ public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder
base.GetBlockInfo(forPlayer, stringBuilder);

stringBuilder.AppendLine(StringHelper.Progressbar(this.LightLevel * 100.0f / 8.0f));
stringBuilder.AppendLine("└ Consumption: " + this.LightLevel + "/" + 8 + "⚡   ");
stringBuilder.AppendLine("└ "+ Lang.Get("Consumption") + this.LightLevel + "/" + 8 + "⚡   ");
stringBuilder.AppendLine();
}
}
Expand Down
3 changes: 2 additions & 1 deletion Electricity/Content/Block/Entity/Behavior/Motor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Electricity.Utils;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.API.MathTools;
using Vintagestory.API.Server;
using Vintagestory.GameContent.Mechanics;
Expand Down Expand Up @@ -178,7 +179,7 @@ public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder
base.GetBlockInfo(forPlayer, stringBuilder);

stringBuilder.AppendLine(StringHelper.Progressbar(this.powerSetting));
stringBuilder.AppendLine("└ Consumption: " + this.powerSetting + "/" + 100 + "⚡   ");
stringBuilder.AppendLine("└ "+ Lang.Get("Consumption") + this.powerSetting + "/" + 100 + "⚡   ");
stringBuilder.AppendLine();
}
}
Expand Down
3 changes: 2 additions & 1 deletion Electricity/Content/Block/Entity/Behavior/SmallLamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Electricity.Interface;
using Electricity.Utils;
using Vintagestory.API.Common;
using Vintagestory.API.Config;

namespace Electricity.Content.Block.Entity.Behavior {
public class SmallLamp : BlockEntityBehavior, IElectricConsumer {
Expand Down Expand Up @@ -46,7 +47,7 @@ public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder
base.GetBlockInfo(forPlayer, stringBuilder);

stringBuilder.AppendLine(StringHelper.Progressbar(this.LightLevel * 100.0f / 4.0f));
stringBuilder.AppendLine("└ Consumption: " + this.LightLevel + "/" + 4 + "⚡   ");
stringBuilder.AppendLine("└ "+ Lang.Get("Consumption") + this.LightLevel + "/" + 4 + "⚡   ");
stringBuilder.AppendLine();
}
}
Expand Down
22 changes: 14 additions & 8 deletions Electricity/Content/Block/Entity/ElectricForge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,20 @@ public override void ToTreeAttributes(ITreeAttribute tree) {
public override void GetBlockInfo(IPlayer forPlayer, StringBuilder stringBuilder) {
base.GetBlockInfo(forPlayer, stringBuilder);

if (this.Contents != null) {
var temp = (int)this.Contents.Collectible.GetTemperature(this.Api.World, this.Contents);

stringBuilder.AppendLine(
temp <= 25
? $"\nContents: {this.Contents.StackSize}x {this.Contents.GetName()}\nTemperature: {Lang.Get("Cold")}"
: $"\nContents: {this.Contents.StackSize}x {this.Contents.GetName()}\nTemperature: {temp}°C"
);
if (this.Contents != null)
{
var temp = (int)Contents.Collectible.GetTemperature(Api.World, Contents);
stringBuilder.AppendLine();
if (temp <= 25)
{
stringBuilder.AppendLine(Lang.Get("Contents") + Contents.StackSize + "×" +
Contents.GetName() +
"\n└ " + Lang.Get("Temperature") + Lang.Get("Cold"));
}
else
stringBuilder.AppendLine(Lang.Get("Contents") + Contents.StackSize + "×" +
Contents.GetName() +
"\n└ " + Lang.Get("Temperature") + temp + "°C");
}
}

Expand Down
8 changes: 8 additions & 0 deletions Electricity/Interface/IEnergyStorageItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Vintagestory.API.Common;

namespace ElectricityUnofficial.Interface;

public interface IEnergyStorageItem
{
int receiveEnergy(ItemStack itemstack, int maxReceive);
}
24 changes: 24 additions & 0 deletions Electricity/Utils/AttributeGetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Vintagestory.API.Common;

namespace ElectricityUnofficial.Utils;

public static class AttributeGetter
{
public static int GetAttributeInt(CollectibleObject block, string attrname, int def = 0)
{
if (block != null && block.Attributes != null && block.Attributes[attrname] != null)
{
return block.Attributes[attrname].AsInt(def);
}
return def;
}

public static string GetAttributeString(CollectibleObject block, string attrname, string def)
{
if (block != null && block.Attributes != null && block.Attributes[attrname] != null)
{
return block.Attributes[attrname].AsString(def);
}
return def;
}
}
4 changes: 4 additions & 0 deletions Electricity/assets/electricity/blocktypes/accumulator.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"*"
]
},
"attributes": {
"rechargeable": true,
"maxcapacity": 16000
},
"shape": {
"base": "block/accumulator"
},
Expand Down
10 changes: 9 additions & 1 deletion Electricity/assets/electricity/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@
"block-switch-*": "Schalter",
"block-lamp-*": "Elektrische Lampe",
"block-forge": "Elektrische Schmiede",
"block-heater-*": "Elektrische Heizung"
"block-heater-*": "Elektrische Heizung",

"game:Electricity": "Electricity",
"game:Storage": "Storage: ",
"game:Temperature": "Temperatur: ",
"game:Consumption": "Verbrauch: ",
"game:Production": "Produktion: ",
"game:Overflow": "Überlauf: ",
"game:Contents": "Inhalt: "
}
10 changes: 9 additions & 1 deletion Electricity/assets/electricity/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
"block-lamp-*": "Electric Lamp",
"block-lamp_small-*": "Electric Lamp (Small)",
"block-forge": "Electric Forge",
"block-heater-*": "Electric Heater"
"block-heater-*": "Electric Heater",

"game:Electricity": "Electricity",
"game:Storage": "Storage: ",
"game:Temperature": "Temperature: ",
"game:Consumption": "Consumption: ",
"game:Production": "Production: ",
"game:Overflow": "Overflow: ",
"game:Contents": "Contents: "
}
20 changes: 20 additions & 0 deletions Electricity/assets/electricity/lang/ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"game:tabname-electricity": "Электричество",
"block-accumulator": "Аккумулятор",
"block-cable-*": "Кабель",
"block-motor-*": "Двигатель",
"block-generator-*": "Генератор",
"block-switch-*": "Переключатель",
"block-lamp-*": "Электрическая лампа",
"block-lamp_small-*": "Электрическая лампа (маленькая)",
"block-forge": "Электрический горн",
"block-heater-*": "Электрический нагреватель",

"game:Electricity": "Электросеть",
"game:Storage": "Хранит: ",
"game:Temperature": "Температура: ",
"game:Consumption": "Потребляет: ",
"game:Production": "Производит: ",
"game:Overflow": "Избыток: ",
"game:Contents": "Содержимое: "
}