From f231ea9f6d2bccaacac672cb8d62bcd42cac9a6a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 9 Apr 2020 01:14:21 +0200 Subject: [PATCH] Fix placement engine for latest GC and add block IDs --- GamecraftModdingAPI/Blocks/BlockIDs.cs | 23 +++++++++++-- GamecraftModdingAPI/Blocks/PlacementEngine.cs | 34 +++++++++++-------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/BlockIDs.cs b/GamecraftModdingAPI/Blocks/BlockIDs.cs index 3aa1bb3..1a7a77a 100644 --- a/GamecraftModdingAPI/Blocks/BlockIDs.cs +++ b/GamecraftModdingAPI/Blocks/BlockIDs.cs @@ -162,8 +162,9 @@ namespace GamecraftModdingAPI.Blocks TractorTyre, MonsterTruckTyre, MotocrossBikeTyre, - CartTyre, - ANDLogicBlock = 170, + CartTyre, //168 + ObjectIdentifier, + ANDLogicBlock, NANDLogicBlock, NORLogicBlock, NOTLogicBlock, @@ -180,6 +181,13 @@ namespace GamecraftModdingAPI.Blocks SubtractorMathsBlock, SimpleConnector, MeanMathsBlock, + Bit, + Counter, + Timer, + ObjectFilter, + PlayerFilter, + TeamFilter, + Number2Text, //193 BeachTree1 = 200, BeachTree2, BeachTree3, @@ -208,6 +216,15 @@ namespace GamecraftModdingAPI.Blocks GrassEdge, GrassEdgeInnerCorner, GrassEdgeCorner, - GrassEdgeSlope + GrassEdgeSlope, + CentreHUD, + ObjectiveHUD, + GameStatsHUD, //231 + Mover = 250, + Rotator, + MovementDampener, + RotationDampener, + AdvancedMover, + AdvancedRotator } } \ No newline at end of file diff --git a/GamecraftModdingAPI/Blocks/PlacementEngine.cs b/GamecraftModdingAPI/Blocks/PlacementEngine.cs index 9a3632e..1101431 100644 --- a/GamecraftModdingAPI/Blocks/PlacementEngine.cs +++ b/GamecraftModdingAPI/Blocks/PlacementEngine.cs @@ -49,15 +49,10 @@ namespace GamecraftModdingAPI.Blocks { //It appears that only the non-uniform scale has any visible effect, but if that's not given here it will be set to the uniform one if (darkness > 9) throw new Exception("That is too dark. Make sure to use 0-9 as darkness. (0 is default.)"); - BuildBlock((ushort) block, (byte) (color + darkness * 10), position, uscale, scale, rotation).Init( - new BlockPlacementInfoStruct() - { - loadedFromDisk = false, - placedBy = playerId - }); + BuildBlock((ushort) block, (byte) (color + darkness * 10), position, uscale, scale, rotation, playerId); } - private EntityStructInitializer BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, float3 rot) + private void BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, float3 rot, uint playerId) { if (_blockEntityFactory == null) throw new Exception("The factory is null."); @@ -78,8 +73,6 @@ namespace GamecraftModdingAPI.Blocks CubeCategoryStruct category = new CubeCategoryStruct {category = CubeCategory.General, type = CubeType.Block}; DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid}; - uint num = PrefabsID.DBIDMAP[dbid]; - GFXPrefabEntityStructGO gfx = new GFXPrefabEntityStructGO {prefabID = num}; BlockPlacementScaleEntityStruct placementScale = new BlockPlacementScaleEntityStruct { blockPlacementHeight = uscale, blockPlacementWidth = uscale, desiredScaleFactor = uscale, @@ -99,17 +92,18 @@ namespace GamecraftModdingAPI.Blocks break; } - int cubeId = PrefabsID.GenerateDBID((ushort) category.category, block); EntityStructInitializer structInitializer = - _blockEntityFactory.Build(egid2, (uint) cubeId); //The ghost block index is only used for triggers + _blockEntityFactory.Build(egid2, dbid); //The ghost block index is only used for triggers if (colour.indexInPalette != byte.MaxValue) structInitializer.Init(new ColourParameterEntityStruct { - indexInPalette = colour.indexInPalette + indexInPalette = colour.indexInPalette, + needsUpdate = true }); - structInitializer.Init(new GFXPrefabEntityStructGPUI(gfx.prefabID)); - structInitializer.Init(new PhysicsPrefabEntityStruct(gfx.prefabID)); + uint prefabId = PrefabsID.GetPrefabId(dbid, 0); + structInitializer.Init(new GFXPrefabEntityStructGPUI(prefabId)); + structInitializer.Init(new PhysicsPrefabEntityStruct(prefabId)); structInitializer.Init(dbEntity); structInitializer.Init(new PositionEntityStruct {position = position}); structInitializer.Init(rotation); @@ -119,7 +113,17 @@ namespace GamecraftModdingAPI.Blocks { scaleFactor = placementScale.desiredScaleFactor }); - return structInitializer; + structInitializer.Init( + new BlockPlacementInfoStruct() + { + loadedFromDisk = false, + placedBy = playerId + }); + PrimaryRotationUtility.InitialisePrimaryDirection(rotation.rotation, ref structInitializer); + EGID playerEGID = new EGID(playerId, CharacterExclusiveGroups.OnFootGroup); + ref PickedBlockExtraDataStruct pickedBlock = ref entitiesDB.QueryEntity(playerEGID); + pickedBlock.placedBlockEntityID = playerEGID; + pickedBlock.placedBlockWasAPickedBlock = false; } public string Name { get; } = "GamecraftModdingAPIPlacementGameEngine";