Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyLiberatto committed Mar 2, 2020
2 parents e13bfe7 + 4d1980a commit 97bc5c5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
36 changes: 14 additions & 22 deletions Source/Content/BlockEntityBehaviors/BEBehaviorTransient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public TransitionConditions(int RequiredSunlight)

public class BEBehaviorTransient : BlockEntityBehavior
{
double transitionAtTotalDays = -1;
double transitionAtTotalHours = -1;
double elapsedTime = 0;
BlockPos Pos { get => Blockentity.Pos; }
string fromCode;
string toCode;
public Block OwnBlock { get => Blockentity.Block; }
public TransitionConditions conditions;
long id;

public BEBehaviorTransient(BlockEntity blockentity) : base(blockentity)
{
Expand All @@ -36,10 +36,10 @@ public BEBehaviorTransient(BlockEntity blockentity) : base(blockentity)
public override void Initialize(ICoreAPI api, JsonObject properties)
{
base.Initialize(api, properties);
if (transitionAtTotalDays <= 0)
if (transitionAtTotalHours <= 0)
{
float hours = properties["inGameHours"].AsFloat(24);
transitionAtTotalDays = api.World.Calendar.TotalDays + hours / 24;
transitionAtTotalHours = api.World.Calendar.TotalHours + hours;
}
fromCode = properties["convertFrom"].AsString()?.WithDomain(OwnBlock.Code.Domain);
toCode = properties["convertTo"].AsString()?.WithDomain(OwnBlock.Code.Domain);
Expand All @@ -49,17 +49,19 @@ public override void Initialize(ICoreAPI api, JsonObject properties)
{
if (api.Side.IsServer())
{
id = Blockentity.RegisterGameTickListener(CheckTransition, 2000);
Blockentity.RegisterGameTickListener(CheckTransition, 2000);
}
}
else api.World.BlockAccessor.RemoveBlockEntity(Pos);
}

public void CheckTransition(float dt)
{
if (transitionAtTotalDays > Api.World.Calendar.TotalDays) return;
if (Api.World.BlockAccessor.GetLightLevel(this.Blockentity.Pos, EnumLightLevelType.OnlySunLight) < (conditions?.RequiredSunlight ?? -1)) return;

int light = Api.World.BlockAccessor.GetLightLevel(this.Blockentity.Pos, EnumLightLevelType.OnlySunLight);
if (light < (conditions?.RequiredSunlight ?? -1)) return;
elapsedTime += dt;
if (Api.World.Calendar.TotalHours + elapsedTime < transitionAtTotalHours) return;

Block block = Api.World.BlockAccessor.GetBlock(Pos);
Block tblock;

Expand Down Expand Up @@ -87,26 +89,16 @@ public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor world
{
base.FromTreeAtributes(tree, worldForResolving);

transitionAtTotalDays = tree.GetDouble("transitionAtTotalDays");
transitionAtTotalHours = tree.GetDouble("transitionAtTotalDays");
elapsedTime = tree.GetDouble("elapsedTime");
}

public override void ToTreeAttributes(ITreeAttribute tree)
{
base.ToTreeAttributes(tree);

tree.SetDouble("transitionAtTotalDays", transitionAtTotalDays);
}

public override void OnBlockUnloaded()
{
Blockentity?.UnregisterGameTickListener(id);
base.OnBlockUnloaded();
}

public override void OnBlockRemoved()
{
Blockentity?.UnregisterGameTickListener(id);
base.OnBlockRemoved();
tree.SetDouble("transitionAtTotalDays", transitionAtTotalHours);
tree.SetDouble("elapsedTime", elapsedTime);
}
}
}
2 changes: 1 addition & 1 deletion Source/Systems/InWorldCraftingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void OnPlayerInteractStop(InWorldCraftingRecipe recipe, IPlayer byPlayer,
if (recipe.Remove) (byPlayer as IServerPlayer)?.Entity.World.BlockAccessor.SetBlock(0, Pos);
Block resolvedBlock = make.ResolvedItemstack.Block;
(byPlayer as IServerPlayer)?.Entity.World.BlockAccessor.SetBlock(resolvedBlock.BlockId, Pos);
resolvedBlock.OnBlockPlaced(byPlayer.Entity.World, Pos);
//resolvedBlock.OnBlockPlaced(byPlayer.Entity.World, Pos);
TakeOrDamage(recipe, slot, byPlayer);
}
}
Expand Down
Binary file modified bin/Immersion/Immersion.dll
Binary file not shown.
Binary file modified bin/Immersion/Immersion.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/Immersion/modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"website": "https://github.com/TonyLiberatto/The-Neolithic-Mod",
"authors": [ "Tony Liberatto","Novocain","Balduranne","BunnyViking" ],
"contributors": ["Tyron", "Milo", "Stroam","Elwood","copygirl", "MarcAFK", "Demmon1", "jhendrix61978", "Ereketh"],
"version": "1.1.17",
"version": "1.1.18",
"dependencies": {
"carrycapacity": "0.4.7-rc.1",
"game": "1.12.5"
Expand Down

0 comments on commit 97bc5c5

Please sign in to comment.