public static void Postfix(BlockEntityChisel __instance) { try { ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(__instance.Api); EnumChiselPlusMesh setMesh = accessor.Properties[__instance.Pos].Mesh; if (setMesh != EnumChiselPlusMesh.none && __instance.MaterialIds != null) { Vec3f rot = accessor.Properties[__instance.Pos].Rotation; ICoreClientAPI capi = (__instance.Api as ICoreClientAPI); string name = Enum.GetName(typeof(EnumChiselPlusMesh), setMesh); if (name == null) { return; } string code = string.Format("chiselplus:genericblocks-{0}", name); capi.Tesselator.TesselateBlock(capi.World.BlockAccessor.GetBlock(new AssetLocation(code)), out MeshData mesh); TextureSource texSource = new TextureSource(__instance.Api.World as ClientMain, capi.BlockTextureAtlas.Size, capi.World.BlockAccessor.GetBlock(__instance.MaterialIds.FirstOrDefault())); Dictionary <string, int> textureCodeToIdMapping = AccessTools.Field(typeof(TextureSource), "textureCodeToIdMapping").GetValue(texSource) as Dictionary <string, int>; mesh.SetTexPos(texSource[textureCodeToIdMapping.FirstOrDefault().Key]); mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.DEG2RAD * rot.X, GameMath.DEG2RAD * rot.Y, GameMath.DEG2RAD * rot.Z); __instance.Mesh = mesh; } } catch (Exception) { } }
public static void Prefix(BlockEntityChisel __instance, ref ITreeAttribute tree) { ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(__instance.Api); var store = accessor.Properties[__instance.Pos]; tree.SetInt("chiselplusmesh", (int)store.Mesh); tree.SetFloat("chiselplusRotX", store.Rotation.X); tree.SetFloat("chiselplusRotY", store.Rotation.Y); tree.SetFloat("chiselplusRotZ", store.Rotation.Z); }
public static void Postfix(BlockEntityChisel __instance, IPlayer byPlayer, BlockSelection blockSel, bool isBreak) { if (!__instance.Api.World.Claims.TryAccess(byPlayer, __instance.Pos, EnumBlockAccessFlags.Use)) { __instance.MarkDirty(true); return; } ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(__instance.Api); if (!accessor.Properties.ContainsKey(__instance.Pos)) { accessor.Properties[__instance.Pos] = new ChiselPlusProperties(); } EnumChiselPlusMode mode = (EnumChiselPlusMode)__instance.ChiselMode(byPlayer); if (__instance.Api.Side.IsServer()) { switch (mode) { case EnumChiselPlusMode.ChiselPlus: if (isBreak) { EnumChiselPlusMesh mesh = accessor.Properties[__instance.Pos].Mesh; accessor.Properties[__instance.Pos].Mesh = mesh > EnumChiselPlusMesh.slopehalf ? EnumChiselPlusMesh.none : mesh + 1; } else { bool success; accessor.Properties[__instance.Pos].Rotation.Z += (success = byPlayer.Entity.Controls.Sneak) ? 45 : 0; accessor.Properties[__instance.Pos].Rotation.X += (success = byPlayer.Entity.Controls.Sprint && !success) ? 45 : 0; accessor.Properties[__instance.Pos].Rotation.Y += !success ? 45 : 0; } __instance.MarkDirty(); break; default: break; } } if (__instance.Api.Side.IsClient()) { __instance.RegenMesh(); __instance.MarkDirty(true); } }
public static void Postfix(BlockEntityChisel __instance, ICoreAPI api) { ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(api); if (!accessor.Properties.ContainsKey(__instance.Pos)) { accessor.Properties[__instance.Pos] = new ChiselPlusProperties(); } if (api.Side.IsClient()) { __instance.RegenMesh(); __instance.MarkDirty(true); } }
public static void Postfix(BlockEntityChisel __instance, ref ITreeAttribute tree, ref IWorldAccessor worldAccessForResolve) { ChiselPlusPropertyAccessor accessor = new ChiselPlusPropertyAccessor(worldAccessForResolve.Api); if (!accessor.Properties.ContainsKey(__instance.Pos)) { accessor.Properties[__instance.Pos] = new ChiselPlusProperties(); } accessor.Properties[__instance.Pos].Mesh = (EnumChiselPlusMesh)(tree.TryGetInt("chiselplusmesh") ?? -1); accessor.Properties[__instance.Pos].Rotation.X = tree.TryGetFloat("chiselplusRotX") ?? 0.0f; accessor.Properties[__instance.Pos].Rotation.Y = tree.TryGetFloat("chiselplusRotY") ?? 0.0f; accessor.Properties[__instance.Pos].Rotation.Z = tree.TryGetFloat("chiselplusRotZ") ?? 0.0f; if (__instance.Api?.Side.IsClient() ?? false) { __instance.MarkDirty(true); } }