public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { ItemStack stack = OnPickBlock(world, blockSel.Position); if (!byPlayer.Entity.Controls.Sneak) { if (byPlayer.InventoryManager.TryGiveItemstack(stack, true)) { world.BlockAccessor.SetBlock(0, blockSel.Position); world.PlaySoundAt(this.Sounds.Place, byPlayer, byPlayer); return(true); } return(false); } if (GetContentNutritionProperties(world, stack, byPlayer.Entity) != null) { world.RegisterCallback((dt) => { if (byPlayer.Entity.Controls.HandUse == EnumHandInteract.BlockInteract) { byPlayer.Entity.PlayEntitySound("eat", byPlayer); } }, 500); byPlayer.Entity.StartAnimation("eat"); return(true); } return(false); }
public override void OnBlockPlaced(IWorldAccessor world, BlockPos pos, ItemStack byItemStack = null) { if (world.GetBlockEntitiesAround(pos, new Vec2i(11, 11)).Any(e => (e is BlockEntitySnitch))) { world.RegisterCallback(dt => world.BlockAccessor.BreakBlock(pos, null), 500); } base.OnBlockPlaced(world, pos, byItemStack); }
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 static void PlaySoundAtWithDelay(this IWorldAccessor world, AssetLocation location, BlockPos Pos, int delay) { world.RegisterCallback(dt => world.PlaySoundAt(location, Pos.X, Pos.Y, Pos.Z), delay); }