public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel != null && byEntity.World.BlockAccessor.GetBlock(blockSel.Position).HasBehavior <BlockBehaviorLockable>(true)) { ModSystemBlockReinforcement modBre = byEntity.World.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); IPlayer player = (byEntity as EntityPlayer).Player; if (!modBre.IsReinforced(blockSel.Position)) { (byEntity.World.Api as ICoreClientAPI)?.TriggerIngameError(this, "cannotlock", Lang.Get("ingameerror-cannotlock-notreinforced")); return; } if (!modBre.TryLock(blockSel.Position, player, this.Code.ToString())) { (byEntity.World.Api as ICoreClientAPI)?.TriggerIngameError(this, "cannotlock", Lang.Get("ingameerror-cannotlock")); } else { //(byEntity.World.Api as ICoreClientAPI)?.ShowChatMessage(Lang.Get("lockapplied")); api.World.PlaySoundAt(new AssetLocation("sounds/tool/padlock.ogg"), player, player, false, 12); slot.TakeOut(1); slot.MarkDirty(); } handling = EnumHandHandling.PreventDefault; return; } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer) { ModSystemBlockReinforcement modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); if (modBre != null) { BlockReinforcement bre = modBre.GetReinforcment(pos); if (bre == null) { return(null); } StringBuilder sb = new StringBuilder(); if (bre.GroupUid != 0) { sb.AppendLine(Lang.Get(bre.Locked ? "Has been locked and reinforced by group {0}." : "Has been reinforced by group {0}.", bre.LastGroupname)); } else { sb.AppendLine(Lang.Get(bre.Locked ? "Has been locked and reinforced by {0}." : "Has been reinforced by {0}.", bre.LastPlayername)); } sb.AppendLine(Lang.Get("Strength: {0}", bre.Strength)); return(sb.ToString()); } return(null); }
public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (byEntity.World.Side == EnumAppSide.Client) { handling = EnumHandHandling.PreventDefaultAction; return; } if (blockSel == null) { return; } ModSystemBlockReinforcement modBre = byEntity.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); IServerPlayer player = (byEntity as EntityPlayer).Player as IServerPlayer; if (player == null) { return; } BlockReinforcement bre = modBre.GetReinforcment(blockSel.Position); string errorCode = ""; if (!modBre.TryRemoveReinforcement(blockSel.Position, player, ref errorCode)) { if (errorCode == "notownblock") { (player as IServerPlayer).SendIngameError("cantremove", "Cannot remove reinforcement. This block does not belong to you"); } else { (player as IServerPlayer).SendIngameError("cantremove", "Cannot remove reinforcement. It's not reinforced"); } return; } else { if (bre.Locked) { ItemStack stack = new ItemStack(byEntity.World.GetItem(new AssetLocation(bre.LockedByItemCode))); if (!player.InventoryManager.TryGiveItemstack(stack, true)) { byEntity.World.SpawnItemEntity(stack, byEntity.ServerPos.XYZ); } } } BlockPos pos = blockSel.Position; byEntity.World.PlaySoundAt(new AssetLocation("sounds/tool/reinforce"), pos.X, pos.Y, pos.Z, null); handling = EnumHandHandling.PreventDefaultAction; }
public override float GetMiningSpeedModifier(IWorldAccessor world, BlockPos pos, IPlayer byPlayer) { ModSystemBlockReinforcement modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); BlockReinforcement bre = modBre.GetReinforcment(pos); if (bre != null && bre.Strength > 0 && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative) { return(0.6f); } return(1.0f); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (byEntity.World.Side == EnumAppSide.Client) { handling = EnumHandHandling.PreventDefaultAction; return; } if (blockSel == null) { return; } ModSystemBlockReinforcement bre = byEntity.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); IPlayer player = (byEntity as EntityPlayer).Player; if (player == null) { return; } ItemSlot resSlot = bre.FindResourceForReinforcing(player); if (resSlot == null) { return; } int strength = resSlot.Itemstack.ItemAttributes["reinforcementStrength"].AsInt(0); if (!bre.StrengthenBlock(blockSel.Position, player, strength)) { (player as IServerPlayer).SendIngameError("alreadyreinforced", "Cannot reinforce block, it's already reinforced!"); return; } resSlot.TakeOut(1); resSlot.MarkDirty(); BlockPos pos = blockSel.Position; byEntity.World.PlaySoundAt(new AssetLocation("sounds/tool/reinforce"), pos.X, pos.Y, pos.Z, null); handling = EnumHandHandling.PreventDefaultAction; if (byEntity.World.Side == EnumAppSide.Client) { ((byEntity as EntityPlayer)?.Player as IClientPlayer).TriggerFpAnimation(EnumHandInteract.HeldItemInteract); } }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling) { ModSystemBlockReinforcement bre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); if (bre.IsLocked(blockSel.Position, byPlayer)) { if (world.Side == EnumAppSide.Client) { (world.Api as ICoreClientAPI).TriggerIngameError(this, "locked", Lang.Get("ingameerror-locked")); } handling = EnumHandling.PreventSubsequent; return(false); } return(base.OnBlockInteractStart(world, byPlayer, blockSel, ref handling)); }
public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer) { ModSystemBlockReinforcement modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); if (modBre != null) { BlockReinforcement bre = modBre.GetReinforcment(pos); if (bre == null) { return(null); } if (bre.Locked) { return("\n" + Lang.Get("Has been locked and reinforced by {0}.\nStrength: {1}", bre.LastPlayername, bre.Strength)); } else { return("\n" + Lang.Get("Has been reinforced by {0}.\nStrength: {1}", bre.LastPlayername, bre.Strength)); } } return(null); }