public bool StrengthenBlock(BlockPos pos, IPlayer byPlayer, int strength) { if (api.Side == EnumAppSide.Client) { return(false); } Dictionary <int, BlockReinforcement> reinforcmentsOfChunk = getOrCreateReinforcmentsAt(pos); int index3d = toLocalIndex(pos); if (reinforcmentsOfChunk.ContainsKey(index3d)) { BlockReinforcement bre = reinforcmentsOfChunk[index3d]; if (bre.Strength > 0) { return(false); } bre.Strength = strength; } else { reinforcmentsOfChunk[index3d] = new BlockReinforcement() { PlayerUID = byPlayer.PlayerUID, LastPlayername = byPlayer.PlayerName, Strength = strength }; } saveReinforcments(reinforcmentsOfChunk, pos); return(true); }
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 bool TryLock(BlockPos pos, IPlayer byPlayer, string itemCode) { Dictionary <int, BlockReinforcement> reinforcmentsOfChunk = getOrCreateReinforcmentsAt(pos); if (reinforcmentsOfChunk == null) { return(false); } int index3d = toLocalIndex(pos); BlockReinforcement bre; if (reinforcmentsOfChunk.TryGetValue(index3d, out bre)) { if (bre.PlayerUID != byPlayer.PlayerUID || bre.Locked) { return(false); } bre.Locked = true; bre.LockedByItemCode = itemCode; saveReinforcments(reinforcmentsOfChunk, pos); return(true); } reinforcmentsOfChunk[index3d] = new BlockReinforcement() { PlayerUID = byPlayer.PlayerUID, LastPlayername = byPlayer.PlayerName, Strength = 0, Locked = true, LockedByItemCode = itemCode }; saveReinforcments(reinforcmentsOfChunk, pos); return(true); }
public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling) { ModSystemBlockReinforcement modBre; if (byPlayer?.WorldData.CurrentGameMode == EnumGameMode.Creative) { if (world.Side == EnumAppSide.Server) { modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); modBre.ClearReinforcement(pos); } return; } modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); BlockReinforcement bre = modBre.GetReinforcment(pos); if (bre != null && bre.Strength > 0) { handling = EnumHandling.PreventDefault; world.PlaySoundAt(new AssetLocation("sounds/tool/breakreinforced"), pos.X, pos.Y, pos.Z, byPlayer); modBre.ConsumeStrength(pos, 1); world.BlockAccessor.MarkBlockDirty(pos); } }
public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling) { if (byPlayer == null) { return; // Fast return path for no player (although normally OnBlockBroken will specify a player) } ModSystemBlockReinforcement modBre; modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); BlockReinforcement bre = modBre.GetReinforcment(pos); if (bre != null && bre.Strength > 0) { handling = EnumHandling.PreventDefault; // This prevents the block from breaking normally, while it any amount of reinforcement left world.PlaySoundAt(new AssetLocation("sounds/tool/breakreinforced"), pos.X, pos.Y, pos.Z, byPlayer); if (!byPlayer.HasPrivilege("denybreakreinforced")) { modBre.ConsumeStrength(pos, 1); world.BlockAccessor.MarkBlockDirty(pos); } } }
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); }
/// <summary> /// Prevent right-click pickup in survival mode, for blocks which have any level of reinforcement on them /// </summary> /// <param name="world"></param> /// <param name="pos"></param> /// <param name="byPlayer"></param> /// <returns>True if pickup is allowed; false if pickup is denied</returns> static public bool AllowRightClickPickup(IWorldAccessor world, BlockPos pos, IPlayer byPlayer) { ModSystemBlockReinforcement modBre; modBre = world.Api.ModLoader.GetModSystem <ModSystemBlockReinforcement>(); BlockReinforcement bre = modBre.GetReinforcment(pos); if (bre != null && bre.Strength > 0) { return(false); } return(true); }
/// <summary> /// Reinforces a block. If forGroupId is not set, the reinforcment is owned by the player, otherwise the reinforcment will be owned by the group /// </summary> /// <param name="pos"></param> /// <param name="byPlayer"></param> /// <param name="strength"></param> /// <param name="forGroupUid"></param> /// <returns></returns> public bool StrengthenBlock(BlockPos pos, IPlayer byPlayer, int strength, int forGroupUid = 0) { if (api.Side == EnumAppSide.Client) { return(false); } Dictionary <int, BlockReinforcement> reinforcmentsOfChunk = getOrCreateReinforcmentsAt(pos); int index3d = toLocalIndex(pos); if (reinforcmentsOfChunk.ContainsKey(index3d)) { BlockReinforcement bre = reinforcmentsOfChunk[index3d]; if (bre.Strength > 0) { return(false); } bre.Strength = strength; } else { string grpname = null; if ((api as ICoreServerAPI).Groups.PlayerGroupsById.TryGetValue(forGroupUid, out var grp)) { grpname = grp.Name; } reinforcmentsOfChunk[index3d] = new BlockReinforcement() { PlayerUID = forGroupUid == 0 ? byPlayer.PlayerUID : null, GroupUid = forGroupUid, LastPlayername = byPlayer.PlayerName, LastGroupname = grpname, Strength = strength }; } saveReinforcments(reinforcmentsOfChunk, pos); return(true); }
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); }