This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff92b6d
commit 510bdab
Showing
76 changed files
with
2,810 additions
and
2,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
/bin | ||
/obj | ||
/mods | ||
/releases | ||
/releases | ||
/.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"vsversion": "1.14.0" | ||
"vsversion": "1.14.5" | ||
} |
160 changes: 160 additions & 0 deletions
160
MoreVariantsFixes/.history/src/EntityBehavior/FixTypedContainer_20201224230751.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
using Vintagestory.API; | ||
using Vintagestory.API.Common; | ||
using Vintagestory.API.Common.Entities; | ||
using Vintagestory.API.Datastructures; | ||
using Vintagestory.API.MathTools; | ||
using Vintagestory.GameContent; | ||
|
||
namespace MoreVariantsFixes | ||
{ | ||
public class FixTypedContainer : EntityBehavior | ||
{ | ||
ICoreAPI Api { get => player?.Api; } | ||
IWorldAccessor World { get => player?.World; } | ||
EntityPlayer player; | ||
public FixTypedContainer(Entity entity) : base(entity) | ||
{ | ||
player = entity as EntityPlayer; | ||
} | ||
public override string PropertyName() | ||
{ | ||
return "fixtypedcontainer"; | ||
} | ||
public override void OnGameTick(float deltaTime) | ||
{ | ||
base.OnGameTick(deltaTime); | ||
|
||
if (player.BlockSelection != null && false) | ||
{ | ||
BlockPos pos = player.BlockSelection.Position; | ||
BlockEntityGenericTypedContainer be = World.BlockAccessor.GetBlockEntity(pos) as BlockEntityGenericTypedContainer; | ||
|
||
if (be?.Block?.Code?.Domain == "morevariants") | ||
{ | ||
if (be.Block.FirstCodePart() == "chest") | ||
{ | ||
if (be.type != "normal" && be.type != "normal-generic") | ||
{ | ||
BlockGenericTypedContainer newBlock = World.BlockAccessor.GetBlock(new AssetLocation("morevariants", | ||
be.Block.FirstCodePart() + "-" + be.type + "-" + be.Block.LastCodePart() | ||
)) as BlockGenericTypedContainer; | ||
|
||
if (newBlock != null) | ||
{ | ||
be.Block = newBlock; | ||
be.type = "normal-generic"; | ||
World.BlockAccessor.SetBlock(newBlock.BlockId, pos); | ||
} | ||
} | ||
else | ||
{ | ||
be.type = "normal-generic"; | ||
} | ||
} | ||
else if (be.Block.FirstCodePart() == "labeledchest") | ||
{ | ||
if (be.type != "normal" && be.type != "normal-labeled" && be.type != "normal-generic") | ||
{ | ||
BlockLabeledChest newBlock = World.BlockAccessor.GetBlock(new AssetLocation("morevariants", | ||
be.Block.FirstCodePart() + "-" + be.type.Split('-')[0] + "-" + be.Block.LastCodePart() | ||
)) as BlockLabeledChest; | ||
|
||
if (newBlock != null) | ||
{ | ||
be.Block = newBlock; | ||
World.BlockAccessor.SetBlock(newBlock.BlockId, pos); | ||
be.type = "normal-labeled"; | ||
} | ||
} | ||
else | ||
{ | ||
|
||
be.type = "normal-labeled"; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
/*World.Api.Logger.Warning("{0}: Obsolete {1} on {2} will be removed", Constants.MOD_ID, block.Code, pos); | ||
//try | ||
{ | ||
TreeAttribute tree = new TreeAttribute(); | ||
be.Inventory.ToTreeAttributes(tree); | ||
AssetLocation code = new AssetLocation("morevariants", | ||
block.FirstCodePart() + "-" + be.type.Split('-')[0] + "-" + block.LastCodePart() | ||
); | ||
Block newBlock = World.BlockAccessor.GetBlock(code); | ||
World.BlockAccessor.SetBlock(newBlock.BlockId, pos); | ||
be = World.BlockAccessor.GetBlockEntity(pos) as BlockEntityGenericTypedContainer; | ||
be.Inventory.FromTreeAttributes(tree); | ||
World.Api.Logger.Warning("{0}: Success", Constants.MOD_ID); | ||
} | ||
/*catch (Exception e) | ||
{ | ||
World.Api.Logger.Warning("{0}: Fail", Constants.MOD_ID); | ||
World.Api.Logger.Error(e.Message); | ||
}*/ | ||
} | ||
} | ||
} | ||
public class BEFixTypedChest : BlockEntityBehavior | ||
{ | ||
public BEFixTypedChest(BlockEntity blockentity) : base(blockentity) { } | ||
public override void Initialize(ICoreAPI api, JsonObject properties) | ||
{ | ||
base.Initialize(api, properties); | ||
Blockentity.RegisterGameTickListener(OnGameTick, 10000); | ||
} | ||
private void OnGameTick(float dt) | ||
{ | ||
BlockEntityGenericTypedContainer be = Blockentity as BlockEntityGenericTypedContainer; | ||
|
||
if (be?.Block?.Code?.Domain == "morevariants" && be.type != "normal-labeled" && be.type != "normal-generic") | ||
{ | ||
IBlockAccessor blockAccessor = Blockentity.Api.World.BlockAccessor; | ||
|
||
string newBEType; | ||
if (be.Block.FirstCodePart() == "chest") | ||
{ | ||
newBEType = "normal-generic"; | ||
} | ||
else if (be.Block.FirstCodePart() == "labeledchest") | ||
{ | ||
newBEType = "normal-labeled"; | ||
} | ||
else return; | ||
|
||
BlockGenericTypedContainer newBlock; | ||
if (be.type == "normal") | ||
{ | ||
newBlock = blockAccessor.GetBlock(be.Block.BlockId) as BlockGenericTypedContainer; | ||
} | ||
else | ||
{ | ||
newBlock = blockAccessor.GetBlock(new AssetLocation("morevariants", | ||
be.Block.FirstCodePart() + "-" + be.type.Split('-')[0] + "-" + be.Block.LastCodePart() | ||
)) as BlockGenericTypedContainer; | ||
} | ||
|
||
if (newBlock != null) | ||
{ | ||
TreeAttribute tree = new TreeAttribute(); | ||
be.Inventory.ToTreeAttributes(tree); | ||
float angle = be.MeshAngle; | ||
|
||
be.Block = newBlock; | ||
blockAccessor.SetBlock(newBlock.BlockId, be.Pos); | ||
|
||
be = blockAccessor.GetBlockEntity(be.Pos.Copy()) as BlockEntityGenericTypedContainer; | ||
be.Inventory.FromTreeAttributes(tree); | ||
be.type = newBEType; | ||
be.MeshAngle = angle; | ||
} | ||
} | ||
} | ||
} | ||
} |
162 changes: 162 additions & 0 deletions
162
MoreVariantsFixes/.history/src/EntityBehavior/FixTypedContainer_20210109135727.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
using Vintagestory.API; | ||
using Vintagestory.API.Common; | ||
using Vintagestory.API.Common.Entities; | ||
using Vintagestory.API.Datastructures; | ||
using Vintagestory.API.MathTools; | ||
using Vintagestory.GameContent; | ||
|
||
namespace MoreVariantsFixes | ||
{ | ||
public class FixTypedContainer : EntityBehavior | ||
{ | ||
|
||
BlockEntityLabeledChest | ||
ICoreAPI Api { get => player?.Api; } | ||
IWorldAccessor World { get => player?.World; } | ||
EntityPlayer player; | ||
public FixTypedContainer(Entity entity) : base(entity) | ||
{ | ||
player = entity as EntityPlayer; | ||
} | ||
public override string PropertyName() | ||
{ | ||
return "fixtypedcontainer"; | ||
} | ||
public override void OnGameTick(float deltaTime) | ||
{ | ||
base.OnGameTick(deltaTime); | ||
|
||
if (player.BlockSelection != null && false) | ||
{ | ||
BlockPos pos = player.BlockSelection.Position; | ||
BlockEntityGenericTypedContainer be = World.BlockAccessor.GetBlockEntity(pos) as BlockEntityGenericTypedContainer; | ||
|
||
if (be?.Block?.Code?.Domain == "morevariants") | ||
{ | ||
if (be.Block.FirstCodePart() == "chest") | ||
{ | ||
if (be.type != "normal" && be.type != "normal-generic") | ||
{ | ||
BlockGenericTypedContainer newBlock = World.BlockAccessor.GetBlock(new AssetLocation("morevariants", | ||
be.Block.FirstCodePart() + "-" + be.type + "-" + be.Block.LastCodePart() | ||
)) as BlockGenericTypedContainer; | ||
|
||
if (newBlock != null) | ||
{ | ||
be.Block = newBlock; | ||
be.type = "normal-generic"; | ||
World.BlockAccessor.SetBlock(newBlock.BlockId, pos); | ||
} | ||
} | ||
else | ||
{ | ||
be.type = "normal-generic"; | ||
} | ||
} | ||
else if (be.Block.FirstCodePart() == "labeledchest") | ||
{ | ||
if (be.type != "normal" && be.type != "normal-labeled" && be.type != "normal-generic") | ||
{ | ||
BlockLabeledChest newBlock = World.BlockAccessor.GetBlock(new AssetLocation("morevariants", | ||
be.Block.FirstCodePart() + "-" + be.type.Split('-')[0] + "-" + be.Block.LastCodePart() | ||
)) as BlockLabeledChest; | ||
|
||
if (newBlock != null) | ||
{ | ||
be.Block = newBlock; | ||
World.BlockAccessor.SetBlock(newBlock.BlockId, pos); | ||
be.type = "normal-labeled"; | ||
} | ||
} | ||
else | ||
{ | ||
|
||
be.type = "normal-labeled"; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
/*World.Api.Logger.Warning("{0}: Obsolete {1} on {2} will be removed", Constants.MOD_ID, block.Code, pos); | ||
//try | ||
{ | ||
TreeAttribute tree = new TreeAttribute(); | ||
be.Inventory.ToTreeAttributes(tree); | ||
AssetLocation code = new AssetLocation("morevariants", | ||
block.FirstCodePart() + "-" + be.type.Split('-')[0] + "-" + block.LastCodePart() | ||
); | ||
Block newBlock = World.BlockAccessor.GetBlock(code); | ||
World.BlockAccessor.SetBlock(newBlock.BlockId, pos); | ||
be = World.BlockAccessor.GetBlockEntity(pos) as BlockEntityGenericTypedContainer; | ||
be.Inventory.FromTreeAttributes(tree); | ||
World.Api.Logger.Warning("{0}: Success", Constants.MOD_ID); | ||
} | ||
/*catch (Exception e) | ||
{ | ||
World.Api.Logger.Warning("{0}: Fail", Constants.MOD_ID); | ||
World.Api.Logger.Error(e.Message); | ||
}*/ | ||
} | ||
} | ||
} | ||
public class BEFixTypedChest : BlockEntityBehavior | ||
{ | ||
public BEFixTypedChest(BlockEntity blockentity) : base(blockentity) { } | ||
public override void Initialize(ICoreAPI api, JsonObject properties) | ||
{ | ||
base.Initialize(api, properties); | ||
Blockentity.RegisterGameTickListener(OnGameTick, 10000); | ||
} | ||
private void OnGameTick(float dt) | ||
{ | ||
BlockEntityGenericTypedContainer be = Blockentity as BlockEntityGenericTypedContainer; | ||
|
||
if (be?.Block?.Code?.Domain == "morevariants" && be.type != "normal-labeled" && be.type != "normal-generic") | ||
{ | ||
IBlockAccessor blockAccessor = Blockentity.Api.World.BlockAccessor; | ||
|
||
string newBEType; | ||
if (be.Block.FirstCodePart() == "chest") | ||
{ | ||
newBEType = "normal-generic"; | ||
} | ||
else if (be.Block.FirstCodePart() == "labeledchest") | ||
{ | ||
newBEType = "normal-labeled"; | ||
} | ||
else return; | ||
|
||
BlockGenericTypedContainer newBlock; | ||
if (be.type == "normal") | ||
{ | ||
newBlock = blockAccessor.GetBlock(be.Block.BlockId) as BlockGenericTypedContainer; | ||
} | ||
else | ||
{ | ||
newBlock = blockAccessor.GetBlock(new AssetLocation("morevariants", | ||
be.Block.FirstCodePart() + "-" + be.type.Split('-')[0] + "-" + be.Block.LastCodePart() | ||
)) as BlockGenericTypedContainer; | ||
} | ||
|
||
if (newBlock != null) | ||
{ | ||
TreeAttribute tree = new TreeAttribute(); | ||
be.Inventory.ToTreeAttributes(tree); | ||
float angle = be.MeshAngle; | ||
|
||
be.Block = newBlock; | ||
blockAccessor.SetBlock(newBlock.BlockId, be.Pos); | ||
|
||
be = blockAccessor.GetBlockEntity(be.Pos.Copy()) as BlockEntityGenericTypedContainer; | ||
be.Inventory.FromTreeAttributes(tree); | ||
be.type = newBEType; | ||
be.MeshAngle = angle; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"vsversion": "1.14.0" | ||
"vsversion": "1.14.2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
MoreVariantsFixes/resources/assets/morevariantsfixes/patches/add-behavior.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.