public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel?.BlockEntity(api) is BlockEntityChisel) { handling = EnumHandHandling.PreventDefault; BlockEntityChisel entityChisel = ((BlockEntityChisel)blockSel.BlockEntity(api)); ITreeAttribute blueprintTree = slot?.Itemstack?.Attributes; ITreeAttribute dummy = blueprintTree.Clone(); entityChisel.ToTreeAttributes(dummy); blueprintTree["materials"] = dummy["materials"]; if (byEntity.Controls.Sneak) { blueprintTree["cuboids"] = new IntArrayAttribute(); entityChisel.ToTreeAttributes(blueprintTree); slot.MarkDirty(); } else if (blueprintTree["cuboids"] != null) { entityChisel.FromTreeAtributes(blueprintTree, api.World); } if (api.Side.IsClient()) { entityChisel.RegenMesh(); } } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
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); } }