public void PlaySoundDispenseParticles(IWorldAccessor world, BlockPos pos, ItemSlot slot) { try { if (world.Side.IsServer()) { world.SpawnCubeParticles(pos, pos.ToVec3d().Add(particleOrigin), pRadius, pQuantity); world.SpawnCubeParticles(pos.ToVec3d().Add(particleOrigin), slot.Itemstack, pRadius, pQuantity); world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z); } } catch (Exception) { } }
public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { ItemSlot activeslot = byPlayer.InventoryManager.ActiveHotbarSlot; if (activeslot.Itemstack.Item.Tool == EnumTool.Hammer && world.Side == EnumAppSide.Server) { world.PlaySoundAt(Sounds.Place, byPlayer); Swap(world, byPlayer, blockSel); world.SpawnCubeParticles(blockSel.Position, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5), 2, 32); } }
public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling) { string curcover = block.Variant["cover"]; if (curcover == "snow") { Block snowblock = world.GetBlock(new AssetLocation("snowblock")); if (snowblock != null) { world.SpawnCubeParticles(pos.ToVec3d().Add(0.5, 0.5, 0.5), new ItemStack(snowblock), 1, 20, 1, byPlayer); } } }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling) { handling = EnumHandling.PreventDefault; var active = byPlayer.InventoryManager.ActiveHotbarSlot; BlockPos pos = blockSel.Position; t = false; if (active.Itemstack != null) { foreach (var val in createBlocks) { if (active.Itemstack.Collectible.WildCardMatch(new AssetLocation(val[0].ToString()))) { makes = new AssetLocation(val[1].ToString()); count = Convert.ToInt32(val[2]); t = true; break; } } if (t && active.Itemstack.StackSize >= count) { if (world.Side == EnumAppSide.Client) { world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z); } if (count < 0 && active.Itemstack.StackSize >= 64) { world.SpawnItemEntity(new ItemStack(active.Itemstack.Collectible, -count), pos.ToVec3d().Add(0.5, 0.5, 0.5), new Vec3d(0.0, 0.1, 0.0)); } else { active.Itemstack.StackSize -= count; } if (active.Itemstack.StackSize <= 0) { active.Itemstack = null; } world.SpawnItemEntity(new ItemStack(world.GetBlock(makes)), pos.ToVec3d().Add(0.5, 0.5, 0.5), new Vec3d(0.0, 0.1, 0.0)); if (world.Side.IsServer()) { world.SpawnCubeParticles(pos.ToVec3d().Add(0.5, 0.5, 0.5), active.Itemstack, 2, 16); } active.MarkDirty(); return(true); } } return(true); }
private void SpreadLiquid(int blockId, BlockPos pos, IWorldAccessor world) { Block block = world.BulkBlockAccessor.GetBlock(pos); if (block.Id != 0 && block.LiquidCode == null) { world.SpawnCubeParticles(pos, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), 0.7f, 25, 0.75f); world.BulkBlockAccessor.BreakBlock(pos, null); } world.BulkBlockAccessor.SetBlock(blockId, pos); world.RegisterCallbackUnique(OnDelayedWaterUpdateCheck, pos, spreadDelay); Block ourBlock = world.GetBlock(blockId); TryReplaceNearbyLiquidBlocks(ourBlock, pos, world); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { EnumTool?tool = byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack.Collectible.Tool; if (world.BlockAccessor.GetBlockEntity(blockSel.Position) is BlockEntityMetalWedge && tool == EnumTool.Hammer) { BlockEntityMetalWedge wedge = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMetalWedge; if (!wedge.interacting) { wedge.interacting = true; if (wedge.animState < 1.0) { wedge.animState += 0.25f; world.SpawnCubeParticles(blockSel.Position, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5), 2, 16); ((byPlayer.Entity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); } else if (world.Side.IsServer()) { Block dBlock = api.World.BlockAccessor.GetBlock(blockSel.Position.DownCopy()); if (dBlock.GetBehavior <BlockBehaviorWedgable>() != null) { finishDrops = dBlock.GetBehavior <BlockBehaviorWedgable>().drops; } world.BlockAccessor.BreakBlock(blockSel.Position, null); if (finishDrops != null) { world.BlockAccessor.SetBlock(0, blockSel.Position.DownCopy()); foreach (var val in finishDrops) { world.SpawnItemEntity(val, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5)); } } else { world.BlockAccessor.BreakBlock(blockSel.Position.DownCopy(), null); } } world.RegisterCallback(dt => wedge.interacting = false, 1000); } } return(base.OnBlockInteractStart(world, byPlayer, blockSel)); }
public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handled) { handled = EnumHandling.PreventDefault; base.OnBlockInteractStop(secondsUsed, world, byPlayer, blockSel, ref handled); if (createBlocks == null) { world.Logger.Notification("CreateBlocks error in " + block.Code.ToString()); return; } var active = byPlayer?.InventoryManager; BlockPos Pos = blockSel?.Position; if (active?.ActiveHotbarSlot?.Itemstack?.Collectible?.Code != null && Pos != null) { foreach (var val in createBlocks) { //if (Api.Side.IsClient()) Api.ModLoader.GetModSystem<ShaderTest>().progressBar = 0; if (secondsUsed > val.MakeTime && active.ActiveHotbarSlot.Itemstack.Collectible.WildCardMatch(val.Takes.Code) && active.ActiveHotbarSlot.StackSize >= val.Takes.StackSize) { if (world.Side.IsServer()) { world.PlaySoundAt(block.Sounds.Place, Pos.X, Pos.Y, Pos.Z); if (active?.ActiveHotbarSlot?.Itemstack?.Item?.Tool != null) { active.ActiveHotbarSlot.Itemstack.Collectible.DamageItem(world, byPlayer.Entity, active.ActiveHotbarSlot); } } if (val.IntoInv) { if (!active.TryGiveItemstack(val.Makes)) { world.SpawnItemEntity(val.Makes, Pos.MidPoint(), new Vec3d(0.0, 0.1, 0.0)); } } else { world.SpawnItemEntity(val.Makes, Pos.MidPoint(), new Vec3d(0.0, 0.1, 0.0)); } active.ActiveHotbarSlot.TakeOut(val.Takes.StackSize); try { if (world.Side.IsClient()) { world.SpawnCubeParticles(Pos.MidPoint(), active.ActiveHotbarSlot.Itemstack, 2, 16); } } catch (Exception) { world.Logger.Error("Could not create particles, missing itemstack?"); } active.ActiveHotbarSlot.MarkDirty(); if (val.RemoveOnFinish) { world.BlockAccessor.SetBlock(0, Pos); } handled = EnumHandling.PreventDefault; return; } } } ItemStack stack = byPlayer?.InventoryManager?.ActiveHotbarSlot?.Itemstack; if (stack != null && allowPlaceOn) { string r = ""; BlockSelection newsel = blockSel.Clone(); newsel.Position = blockSel.Position.Offset(blockSel.Face); Block block = stack.Block; if (block != null && block.TryPlaceBlock(world, byPlayer, stack, newsel, ref r)) { world.PlaySoundAt(stack.Block?.Sounds.Place, newsel.Position); } } }
public override bool OnBlockInteractStep(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { if (!byPlayer.Entity.Controls.Sneak) { return(false); } ItemStack stack = OnPickBlock(world, blockSel.Position); if (world is IClientWorldAccessor) { ModelTransform tf = new ModelTransform(); tf.Origin.Set(1.1f, 0.5f, 0.5f); tf.EnsureDefaultValues(); if (ItemClass == EnumItemClass.Item) { if (secondsUsed > 0.5f) { tf.Translation.X = GameMath.Sin(30 * secondsUsed) / 10; } tf.Translation.Z += -Math.Min(1.6f, secondsUsed * 4 * 1.57f); tf.Translation.Y += Math.Min(0.15f, secondsUsed * 2); tf.Rotation.Y -= Math.Min(85f, secondsUsed * 350 * 1.5f); tf.Rotation.X += Math.Min(40f, secondsUsed * 350 * 0.75f); tf.Rotation.Z += Math.Min(30f, secondsUsed * 350 * 0.75f); } else { tf.Translation.X -= Math.Min(1.7f, secondsUsed * 4 * 1.8f) / FpHandTransform.ScaleXYZ.X; tf.Translation.Y += Math.Min(0.4f, secondsUsed * 1.8f) / FpHandTransform.ScaleXYZ.X; tf.Scale = 1 + Math.Min(0.5f, secondsUsed * 4 * 1.8f) / FpHandTransform.ScaleXYZ.X; tf.Rotation.X += Math.Min(40f, secondsUsed * 350 * 0.75f) / FpHandTransform.ScaleXYZ.X; if (secondsUsed > 0.5f) { tf.Translation.Y += GameMath.Sin(30 * secondsUsed) / 10 / FpHandTransform.ScaleXYZ.Y; } } byPlayer.Entity.Controls.UsingHeldItemTransformBefore = tf; if (secondsUsed > 0.5f && (int)(30 * secondsUsed) % 7 == 1) { ItemStack[] contents = GetNonEmptyContents(world, stack); if (contents.Length > 0) { ItemStack rndStack = contents[world.Rand.Next(contents.Length)]; world.SpawnCubeParticles(blockSel.Position.ToVec3d().Add(0.5f, 2 / 16f, 0.5f), rndStack, 0.2f, 4, 0.5f); } } return(secondsUsed <= 1.5f); } // Let the client decide when he is done eating return(true); }