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