From 6a9073919771739c32c3eb1ea96b3cd23326b48b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 19 Dec 2020 21:43:49 +0100 Subject: [PATCH] Attempt to use custom cube category --- GamecraftModdingAPI/Blocks/CustomBlock.cs | 54 ++++++++++++------- GamecraftModdingAPI/Main.cs | 5 +- .../Tests/GamecraftModdingAPIPluginTest.cs | 1 - 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/CustomBlock.cs b/GamecraftModdingAPI/Blocks/CustomBlock.cs index 331552c..15cfb15 100644 --- a/GamecraftModdingAPI/Blocks/CustomBlock.cs +++ b/GamecraftModdingAPI/Blocks/CustomBlock.cs @@ -2,27 +2,19 @@ using System.Collections; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Reflection; -using DataLoader; -using GamecraftModdingAPI.App; -using GamecraftModdingAPI.Utility; -using GPUInstancer; using HarmonyLib; + +using DataLoader; using RobocraftX.Blocks; -using RobocraftX.Common; using RobocraftX.Rendering; -using Svelto.DataStructures; using Svelto.ECS; using Svelto.Tasks; -using Unity.Entities.Conversion; -using Unity.Physics; using UnityEngine; using UnityEngine.AddressableAssets; -using BoxCollider = UnityEngine.BoxCollider; using Material = UnityEngine.Material; -using Object = UnityEngine.Object; -using ScalingPermission = DataLoader.ScalingPermission; + +using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { @@ -62,18 +54,18 @@ namespace GamecraftModdingAPI.Blocks public CustomBlock(EGID id) : base(id) { - if (id.groupID != Group) - throw new BlockTypeException("The block is not a custom block! It has a group of " + id.groupID); + /*if (id.groupID != Group) + throw new BlockTypeException("The block is not a custom block! It has a group of " + id.groupID);*/ } - public CustomBlock(uint id) : this(new EGID(id, Group)) + public CustomBlock(uint id) : base(id) { } - public static ExclusiveGroup Group { get; } = new ExclusiveGroup("Custom block"); + //public static ExclusiveGroup Group { get; } = new ExclusiveGroup("Custom block"); [HarmonyPatch] - public static class Patch + public static class MaterialCopyPatch { private static Material[] materials; @@ -110,6 +102,7 @@ namespace GamecraftModdingAPI.Blocks var cld = new CubeListData { //"Assets/Prefabs/Cube.prefab" - "CTR_CommandBlock" - "strConsoleBlock" cubeType = attr.Type, + //cubeCategory = (CubeCategory) 1000, cubeCategory = attr.Category, inventoryCategory = attr.InventoryCategory, ID = nextID++, @@ -141,8 +134,24 @@ namespace GamecraftModdingAPI.Blocks } } - public static IEnumerator Prep() - { //TODO: Don't let the game load until this finishes + /*[HarmonyPatch] - The block has no collision even in simulation if using a custom category + private static class FactorySetupPatch + { + public static void Prefix(BlockEntityFactory __instance) + { + var builders = (Dictionary) + AccessTools.Field(__instance.GetType(), "_blockBuilders").GetValue(__instance); + builders.Add((CubeCategory) 1000, new BlockBuilder(Group)); + } + + public static MethodBase TargetMethod() + { + return AccessTools.Method(typeof(BlockEntityFactory), "ParseDataDB"); + } + }*/ + + internal static IEnumerator Prepare() + { //Should be pretty quick foreach (var type in _customBlocks.Values) { var attr = type.GetCustomAttribute(); @@ -153,5 +162,12 @@ namespace GamecraftModdingAPI.Blocks Addressables.AddResourceLocator(res.Result); } } + + /*internal static void OnBlockFactoryObtained(BlockEntityFactory factory) + { + var builders = (Dictionary) + AccessTools.Field(factory.GetType(), "_blockBuilders").GetValue(factory); + builders.Add((CubeCategory) 1000, new BlockBuilder(Group)); + }*/ } } \ No newline at end of file diff --git a/GamecraftModdingAPI/Main.cs b/GamecraftModdingAPI/Main.cs index 584ae90..775670f 100644 --- a/GamecraftModdingAPI/Main.cs +++ b/GamecraftModdingAPI/Main.cs @@ -1,12 +1,14 @@ using System; using System.Reflection; -using GamecraftModdingAPI.Blocks; using HarmonyLib; using RobocraftX; +using RobocraftX.Schedulers; using RobocraftX.Services; using Svelto.Context; +using Svelto.Tasks.ExtraLean; +using GamecraftModdingAPI.Blocks; using GamecraftModdingAPI.Utility; using GamecraftModdingAPI.Events; using GamecraftModdingAPI.Tasks; @@ -89,6 +91,7 @@ namespace GamecraftModdingAPI AsyncUtils.Init(); GamecraftModdingAPI.App.Client.Init(); GamecraftModdingAPI.App.Game.Init(); + CustomBlock.Prepare().RunOn(ExtraLean.UIScheduler); Logging.MetaLog($"{currentAssembly.GetName().Name} v{currentAssembly.GetName().Version} initialized"); } diff --git a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs index 02c7d2c..009c368 100644 --- a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs +++ b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs @@ -369,7 +369,6 @@ namespace GamecraftModdingAPI.Tests Log.Output("Submitted: " + Window.selected.submittedCode); }) .Build(); - CustomBlock.Prep().RunOn(ExtraLean.UIScheduler); try { CustomBlock.RegisterCustomBlock();