Browse Source

Attempt to use custom cube category

tags/v1.8.0
NorbiPeti 3 years ago
parent
commit
6a90739197
3 changed files with 39 additions and 21 deletions
  1. +35
    -19
      GamecraftModdingAPI/Blocks/CustomBlock.cs
  2. +4
    -1
      GamecraftModdingAPI/Main.cs
  3. +0
    -1
      GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs

+ 35
- 19
GamecraftModdingAPI/Blocks/CustomBlock.cs View File

@@ -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<CubeCategory, IBlockBuilder>)
AccessTools.Field(__instance.GetType(), "_blockBuilders").GetValue(__instance);
builders.Add((CubeCategory) 1000, new BlockBuilder<StandardBlockEntityDescriptor>(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<CustomBlockAttribute>();
@@ -153,5 +162,12 @@ namespace GamecraftModdingAPI.Blocks
Addressables.AddResourceLocator(res.Result);
}
}

/*internal static void OnBlockFactoryObtained(BlockEntityFactory factory)
{
var builders = (Dictionary<CubeCategory, IBlockBuilder>)
AccessTools.Field(factory.GetType(), "_blockBuilders").GetValue(factory);
builders.Add((CubeCategory) 1000, new BlockBuilder<StandardBlockEntityDescriptor>(Group));
}*/
}
}

+ 4
- 1
GamecraftModdingAPI/Main.cs View File

@@ -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");
}



+ 0
- 1
GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs View File

@@ -369,7 +369,6 @@ namespace GamecraftModdingAPI.Tests
Log.Output("Submitted: " + Window.selected.submittedCode);
})
.Build();
CustomBlock.Prep().RunOn(ExtraLean.UIScheduler);
try
{
CustomBlock.RegisterCustomBlock<TestBlock>();


Loading…
Cancel
Save