public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { BlockPos position = null; IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); try{ position = this.currentEvents[byPlayer]; } catch { return; } } this.currentEvents.Remove(byPlayer); if (secondsUsed > 1.95f) { string polished = "rockpolished-" + byEntity.World.BlockAccessor.GetBlock(position).CodeEndWithoutParts(1); byEntity.World.BlockAccessor.SetBlock(byEntity.World.GetBlock(new AssetLocation(polished)).BlockId, position); byEntity.World.BlockAccessor.MarkBlockDirty(position); slot.TakeOut(1); slot.MarkDirty(); } }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (byEntity.World.Side != EnumAppSide.Server) { handling = EnumHandHandling.PreventDefault; return; } IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (!(byPlayer is IServerPlayer)) { return; } IServerPlayer serverplayer = byPlayer as IServerPlayer; TreeAttribute tree = new TreeAttribute(); tree.SetString("playeruid", byPlayer?.PlayerUID); tree.SetString("category", itemslot.Itemstack.Attributes.GetString("category")); tree.SetItemstack("itemstack", itemslot.Itemstack.Clone()); api.Event.PushEvent("loreDiscovery", tree); itemslot.TakeOut(1); itemslot.MarkDirty(); handling = EnumHandHandling.PreventDefault; }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { itemslot.MarkDirty(); return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefault; return; } } be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face)); if (be is BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefault; return; } } Block block = byEntity.World.GetBlock(new AssetLocation("platepile")); if (block == null) { return; } if (((BlockPlatePile)block).Construct(itemslot, byEntity.World, blockSel.Position.AddCopy(blockSel.Face), byPlayer)) { handling = EnumHandHandling.PreventDefault; } }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { pouringLoop?.Stop(); pouringLoop?.Dispose(); pouringLoop = null; slot.MarkDirty(); }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null) { return; } IPlayer player = byEntity.World.PlayerByUid((byEntity as EntityPlayer)?.PlayerUID); if (!byEntity.World.TestPlayerAccessBlock(player, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { slot.MarkDirty(); return; } if (!(byEntity is EntityPlayer) || player.WorldData.CurrentGameMode != EnumGameMode.Creative) { slot.TakeOut(1); slot.MarkDirty(); } EntityProperties type = byEntity.World.GetEntityType(new AssetLocation("strawdummy")); Entity entity = byEntity.World.ClassRegistry.CreateEntity(type); if (entity != null) { entity.ServerPos.X = blockSel.Position.X + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.X) + 0.5f; entity.ServerPos.Y = blockSel.Position.Y + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.Y); entity.ServerPos.Z = blockSel.Position.Z + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.Z) + 0.5f; entity.ServerPos.Yaw = byEntity.LocalPos.Yaw + GameMath.PI; if (player?.PlayerUID != null) { entity.WatchedAttributes.SetString("ownerUid", player.PlayerUID); } entity.Pos.SetFrom(entity.ServerPos); byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/torch"), entity, player); byEntity.World.SpawnEntity(entity); handling = EnumHandHandling.PreventDefaultAction; } }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (byEntity.Attributes.GetInt("aiming") == 0) { return; } byEntity.Attributes.SetInt("aiming", 0); byEntity.StopAnimation("aim"); if (secondsUsed < 0.35f) { return; } float damage = 0.5f; string rockType = slot.Itemstack.Collectible.FirstCodePart(1); ItemStack stack = slot.TakeOut(1); slot.MarkDirty(); IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } byEntity.World.PlaySoundAt(new AssetLocation("sounds/player/throw"), byEntity, byPlayer, false, 8); EntityProperties type = byEntity.World.GetEntityType(new AssetLocation("thrownbeenade")); Entity entity = byEntity.World.ClassRegistry.CreateEntity(type); ((EntityThrownBeenade)entity).FiredBy = byEntity; ((EntityThrownBeenade)entity).Damage = damage; ((EntityThrownBeenade)entity).ProjectileStack = stack; float acc = (1 - byEntity.Attributes.GetFloat("aimingAccuracy", 0)); double rndpitch = byEntity.WatchedAttributes.GetDouble("aimingRandPitch", 1) * acc * 0.75; double rndyaw = byEntity.WatchedAttributes.GetDouble("aimingRandYaw", 1) * acc * 0.75; Vec3d pos = byEntity.ServerPos.XYZ.Add(0, byEntity.EyeHeight - 0.2, 0); Vec3d aheadPos = pos.AheadCopy(1, byEntity.ServerPos.Pitch + rndpitch, byEntity.ServerPos.Yaw + rndyaw); Vec3d velocity = (aheadPos - pos) * 0.5; entity.ServerPos.SetPos(byEntity.ServerPos.BehindCopy(0.21).XYZ.Add(0, byEntity.EyeHeight - 0.2, 0).Ahead(0.25, 0, byEntity.ServerPos.Yaw + GameMath.PIHALF)); entity.ServerPos.Motion.Set(velocity); entity.Pos.SetFrom(entity.ServerPos); entity.World = byEntity.World; byEntity.World.SpawnEntity(entity); byEntity.StartAnimation("throw"); }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink; if (be != null && be.CanReceiveAny) { KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack); if (contents.Key == null) { slot.Itemstack = new ItemStack(byEntity.World.GetBlock(new AssetLocation("crucible-burned"))); slot.MarkDirty(); handHandling = EnumHandHandling.PreventDefault; return; } if (HasSolidifed(slot.Itemstack, contents.Key, byEntity.World)) { return; } if (contents.Value <= 0) { return; } if (!be.CanReceive(contents.Key)) { return; } be.BeginFill(blockSel.HitPosition); byEntity.World.RegisterCallback((world, pos, dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemInteract) { IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } world.PlaySoundAt(new AssetLocation("sounds/hotmetal"), byEntity, byPlayer); } }, blockSel.Position, 666); handHandling = EnumHandHandling.PreventDefault; } }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { slot.MarkDirty(); if (blockSel == null) { return; } ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink; be?.OnPourOver(); }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { BlockPos pos = blockSel.Position; AssetLocation asset = new AssetLocation("amethyst:amethyst-dust-isolated-unlit"); if (pos != null && !api.World.BlockAccessor.GetBlock(pos + new BlockPos(0, 1, 0)).WildCardMatch(new AssetLocation("amethyst:amethyst-dust*")) && !api.World.BlockAccessor.GetBlock(pos).WildCardMatch(new AssetLocation("amethyst:amethyst-dust*"))) { api.World.BlockAccessor.SetBlock(api.World.BlockAccessor.GetBlock(asset).BlockId, pos + new BlockPos(0, 1, 0)); slot.TakeOut(1); slot.MarkDirty(); api.World.PlaySoundAt(api.World.BlockAccessor.GetBlock(asset).Sounds.Place, pos.X, pos.Y, pos.Z); return; } return; }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (blockSel == null) { return; } if (secondsUsed < 1.9f) { return; } IWorldAccessor world = byEntity.World; Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); if (!CanSqueezeInto(block)) { return; } BlockBucket blockbucket = block as BlockBucket; if (blockbucket != null) { if (blockbucket.TryAddContent(world, blockSel.Position, new ItemStack(world.GetItem(new AssetLocation("honeyportion"))), 1) == 0) { return; } } else { world.BlockAccessor.SetBlock(world.GetBlock(new AssetLocation("bowl-honey")).BlockId, blockSel.Position); } slot.TakeOut(1); slot.MarkDirty(); IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = world.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } byPlayer?.InventoryManager.TryGiveItemstack(new ItemStack(world.GetItem(new AssetLocation("beeswax")))); }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } BlockPos pos = blockSel.Position; string lastCodePart = itemslot.Itemstack.Collectible.LastCodePart(); BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(pos); if (be is BlockEntityFarmland) { Block cropBlock = byEntity.World.GetBlock(CodeWithPath("crop-" + lastCodePart + "-1")); if (cropBlock == null) { return; } IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } bool planted = ((BlockEntityFarmland)be).TryPlant(cropBlock); if (planted) { byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/plant"), pos.X, pos.Y, pos.Z, byPlayer); if (byPlayer?.WorldData?.CurrentGameMode != EnumGameMode.Creative) { itemslot.TakeOut(1); itemslot.MarkDirty(); } } if (planted) { handHandling = EnumHandHandling.PreventDefault; } } }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (byEntity.World.Side == EnumAppSide.Client) { ILoadedSound sound = byEntity.World.Api.ObjectCache["temporalGearSound"] as ILoadedSound; sound?.Stop(); sound?.Dispose(); //Console.WriteLine("sound stop"); } if (blockSel == null || secondsUsed < 3.45) { return; } slot.TakeOut(1); slot.MarkDirty(); if (byEntity.World.Side == EnumAppSide.Client) { byEntity.World.PlaySoundAt(new AssetLocation("sounds/effect/portal.ogg"), byEntity, null, false); particlesHeld.minSize = 0.25f; particlesHeld.maxSize = 0.5f; particlesHeld.minQuantity = 300; Vec3d pos = blockSel.Position.ToVec3d().Add(blockSel.HitPosition); SpawnParticles(byEntity.World, pos, true); } if (byEntity.World.Side == EnumAppSide.Server && byEntity is EntityPlayer) { IServerPlayer plr = byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID) as IServerPlayer; ICoreServerAPI sapi = byEntity.World.Api as ICoreServerAPI; plr.SetSpawnPosition(new PlayerSpawnPos(byEntity.ServerPos.XYZInt.X, byEntity.ServerPos.XYZInt.Y, byEntity.ServerPos.XYZInt.Z) { yaw = byEntity.ServerPos.Yaw, pitch = byEntity.ServerPos.Pitch }); } }
private void InsertHoney(IItemSlot itemslot, IEntityAgent byEntity) { Block emptyBowl = byEntity.World.GetBlock(new AssetLocation("bowl-honey")); ItemStack emptyStack = new ItemStack(emptyBowl); if (itemslot.Itemstack.StackSize <= 1) { itemslot.Itemstack = emptyStack; } else { IPlayer player = (byEntity as EntityPlayer)?.Player; itemslot.TakeOut(1); if (!player.InventoryManager.TryGiveItemstack(emptyStack, true)) { byEntity.World.SpawnItemEntity(emptyStack, byEntity.LocalPos.XYZ); } } itemslot.MarkDirty(); }
internal bool Construct(IItemSlot slot, IWorldAccessor world, BlockPos pos, IPlayer player) { Block block = world.BlockAccessor.GetBlock(pos); if (!block.IsReplacableBy(this)) { return(false); } Block belowBlock = world.BlockAccessor.GetBlock(pos.DownCopy()); if (!belowBlock.SideSolid[BlockFacing.UP.Index] && (belowBlock != this || FillLevel(world.BlockAccessor, pos.DownCopy()) != 4)) { return(false); } world.BlockAccessor.SetBlock(BlockId, pos); BlockEntity be = world.BlockAccessor.GetBlockEntity(pos); if (be is BlockEntityFirewoodPile) { BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be; if (player == null || player.WorldData.CurrentGameMode != EnumGameMode.Creative) { pile.inventory.GetSlot(0).Itemstack = (ItemStack)slot.TakeOut(2); slot.MarkDirty(); } else { pile.inventory.GetSlot(0).Itemstack = (ItemStack)slot.Itemstack.Clone(); } pile.MarkDirty(); world.BlockAccessor.MarkBlockDirty(pos); world.PlaySoundAt(new AssetLocation("sounds/block/planks"), pos.X, pos.Y, pos.Z, player, false); } return(true); }
/// <summary> /// Called when the player successfully completed the using action, always called once an interaction is over /// </summary> /// <param name="secondsUsed"></param> /// <param name="slot"></param> /// <param name="byEntity"></param> /// <param name="blockSel"></param> /// <param name="entitySel"></param> public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { FoodNutritionProperties[] multiProps = GetContentNutritionProperties(byEntity.World, slot.Itemstack, byEntity as Entity); if (byEntity.World.Side == EnumAppSide.Server && multiProps != null && secondsUsed >= 0.95f) { slot.TakeOut(1); slot.MarkDirty(); IPlayer player = (byEntity as EntityPlayer).Player; Block block = byEntity.World.GetBlock(new AssetLocation("bowl-burned")); if (player == null || !player.InventoryManager.TryGiveItemstack(new ItemStack(block), true)) { byEntity.World.SpawnItemEntity(new ItemStack(block), byEntity.LocalPos.XYZ); } foreach (var nutriProps in multiProps) { player.Entity.ReceiveSaturation(nutriProps.Saturation, nutriProps.FoodCategory, 10 + nutriProps.Saturation / 100f * 30f); if (nutriProps.EatenStack?.ResolvedItemstack != null) { if (player == null || !player.InventoryManager.TryGiveItemstack(nutriProps.EatenStack.ResolvedItemstack.Clone(), true)) { byEntity.World.SpawnItemEntity(nutriProps.EatenStack.ResolvedItemstack.Clone(), byEntity.LocalPos.XYZ); } } if (nutriProps.Health != 0) { byEntity.ReceiveDamage(new DamageSource() { Source = EnumDamageSource.Internal, Type = nutriProps.Health > 0 ? EnumDamageType.Heal : EnumDamageType.Poison }, Math.Abs(nutriProps.Health)); } } } }
public void PutClay(IItemSlot slot) { if (workItemStack == null) { if (api.World is IClientWorldAccessor) { OpenDialog(api.World as IClientWorldAccessor, pos, slot.Itemstack); } CreateInitialWorkItem(); workItemStack = new ItemStack(api.World.GetItem(new AssetLocation("clayworkitem-" + slot.Itemstack.Collectible.LastCodePart()))); baseMaterial = new ItemStack(api.World.GetItem(new AssetLocation("clay-" + slot.Itemstack.Collectible.LastCodePart()))); } AvailableVoxels += 25; slot.TakeOut(1); slot.MarkDirty(); RegenMeshAndSelectionBoxes(); MarkDirty(); }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } IPlayer player = byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID); if (!byEntity.World.TestPlayerAccessBlock(player, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { return; } if (!(byEntity is EntityPlayer) || player.WorldData.CurrentGameMode != EnumGameMode.Creative) { slot.TakeOut(1); slot.MarkDirty(); } EntityProperties type = byEntity.World.GetEntityType(new AssetLocation(CodeEndWithoutParts(1))); Entity entity = byEntity.World.ClassRegistry.CreateEntity(type); if (entity != null) { entity.ServerPos.X = blockSel.Position.X + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.X) + 0.5f; entity.ServerPos.Y = blockSel.Position.Y + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.Y); entity.ServerPos.Z = blockSel.Position.Z + (blockSel.DidOffset ? 0 : blockSel.Face.Normali.Z) + 0.5f; entity.ServerPos.Yaw = (float)byEntity.World.Rand.NextDouble() * 2 * GameMath.PI; entity.Pos.SetFrom(entity.ServerPos); entity.Attributes.SetString("origin", "playerplaced"); byEntity.World.SpawnEntity(entity); handHandling = EnumHandHandling.PreventDefaultAction; } }
public void ServeIntoBowl(BlockPos pos, IItemSlot potslot, IWorldAccessor world) { if (world.Side == EnumAppSide.Client) { return; } Block mealblock = api.World.GetBlock(new AssetLocation("bowl-meal")); world.BlockAccessor.SetBlock(mealblock.BlockId, pos); BlockEntityMeal bemeal = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityMeal; if (bemeal == null) { return; } bemeal.RecipeCode = GetRecipeCode(world, potslot.Itemstack); ItemStack[] stacks = GetContents(api.World, potslot.Itemstack); for (int i = 0; i < stacks.Length; i++) { bemeal.inventory.GetSlot(i).Itemstack = stacks[i].Clone(); } int quantityServings = GetServings(world, potslot.Itemstack); SetServings(world, potslot.Itemstack, quantityServings - 1); if (quantityServings <= 0) { potslot.Itemstack = new ItemStack(api.World.GetBlock(new AssetLocation(FirstCodePart() + "-burned"))); } potslot.MarkDirty(); bemeal.MarkDirty(true); }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null || byEntity.World == null || byEntity.Controls.Sneak) { base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, ref handHandling); return; } bool waterBlock = byEntity.World.BlockAccessor.GetBlock(blockSel.Position.AddCopy(blockSel.Face)).IsWater(); Block block = byEntity.World.GetBlock(new AssetLocation(waterBlock ? "giantreed-arundo-water-harvested" : "giantreed-arundo-free-harvested")); if (block == null) { base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, ref handHandling); return; } IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } blockSel = blockSel.Clone(); blockSel.Position.Add(blockSel.Face); bool ok = block.TryPlaceBlock(byEntity.World, byPlayer, itemslot.Itemstack, blockSel); if (ok) { itemslot.TakeOut(1); itemslot.MarkDirty(); handHandling = EnumHandHandling.PreventDefaultAction; } }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null) { return; } if (byEntity.Controls.Sneak) { return; } slot.Itemstack.TempAttributes.SetFloat("secondsUsed", 0); IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (byEntity.World.BlockAccessor.GetBlock(blockSel.Position).IsWater()) { BlockPos pos = blockSel.Position; SetRemainingWateringSeconds(slot.Itemstack, CapacitySeconds); slot.Itemstack.TempAttributes.SetInt("refilled", 1); slot.MarkDirty(); byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/water"), pos.X, pos.Y, pos.Z, byPlayer); handHandling = EnumHandHandling.PreventDefault; return; } BlockBucket bucket = byEntity.World.BlockAccessor.GetBlock(blockSel.Position) as BlockBucket; if (bucket != null && bucket.GetContent(byEntity.World, blockSel.Position)?.Collectible.IsWater() == true) { BlockPos pos = blockSel.Position; ItemStack takenWater = bucket.TryTakeContent(byEntity.World, blockSel.Position, 5); SetRemainingWateringSeconds(slot.Itemstack, CapacitySeconds * takenWater.StackSize / 5f); slot.Itemstack.TempAttributes.SetInt("refilled", 1); slot.MarkDirty(); byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/water"), pos.X, pos.Y, pos.Z, byPlayer); handHandling = EnumHandHandling.PreventDefault; } slot.Itemstack.TempAttributes.SetInt("refilled", 0); float remainingwater = GetRemainingWateringSeconds(slot.Itemstack); if (remainingwater <= 0) { return; } if (byEntity.World.Side == EnumAppSide.Client) { byEntity.World.RegisterCallback(After350ms, 350); } handHandling = EnumHandHandling.PreventDefault; }
internal bool OnPlayerInteract(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { IItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot; if (!byPlayer.Entity.Controls.Sneak) { if (contents == null) { return(false); } ItemStack split = contents.Clone(); split.StackSize = 1; contents.StackSize--; if (contents.StackSize == 0) { contents = null; } //api.World.Logger.Notification("Forge item retrieve temp: {0}, side {1}", split.Collectible.GetTemperature(api.World, split), api.Side); if (!byPlayer.InventoryManager.TryGiveItemstack(split)) { world.SpawnItemEntity(contents, pos.ToVec3d().Add(0.5, 0.5, 0.5)); } renderer?.SetContents(contents, fuelLevel, burning, true); MarkDirty(); api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), pos.X, pos.Y, pos.Z, byPlayer, false); return(true); } else { if (slot.Itemstack == null) { return(false); } // Add fuel CombustibleProperties combprops = slot.Itemstack.Collectible.CombustibleProps; if (combprops != null && combprops.BurnTemperature > 1000) { if (fuelLevel >= 10 / 16f) { return(false); } fuelLevel += 1 / 16f; renderer?.SetContents(contents, fuelLevel, burning, false); MarkDirty(); slot.TakeOut(1); slot.MarkDirty(); return(true); } string firstCodePart = slot.Itemstack.Collectible.FirstCodePart(); // Add heatable item if (contents == null && (firstCodePart == "ingot" || firstCodePart == "metalplate" || firstCodePart == "workitem")) { contents = slot.Itemstack.Clone(); contents.StackSize = 1; slot.TakeOut(1); slot.MarkDirty(); renderer?.SetContents(contents, fuelLevel, burning, true); MarkDirty(); api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), pos.X, pos.Y, pos.Z, byPlayer, false); return(true); } // Merge heatable item if (contents != null && contents.Equals(api.World, slot.Itemstack, GlobalConstants.IgnoredStackAttributes) && contents.StackSize < 4 && contents.StackSize < contents.Collectible.MaxStackSize) { float myTemp = contents.Collectible.GetTemperature(api.World, contents); float histemp = slot.Itemstack.Collectible.GetTemperature(api.World, slot.Itemstack); contents.Collectible.SetTemperature(world, contents, (myTemp * contents.StackSize + histemp * 1) / (contents.StackSize + 1)); contents.StackSize++; slot.TakeOut(1); slot.MarkDirty(); renderer?.SetContents(contents, fuelLevel, burning, true); api.World.PlaySoundAt(new AssetLocation("sounds/block/ingot"), pos.X, pos.Y, pos.Z, byPlayer, false); MarkDirty(); return(true); } return(false); } }
public override bool OnHeldInteractStep(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (blockSel == null) { return(false); } ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink; if (be == null) { return(false); } if (!be.CanReceiveAny) { return(false); } KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack); if (!be.CanReceive(contents.Key)) { return(false); } float speed = 1.5f; float temp = GetTemperature(byEntity.World, slot.Itemstack); if (byEntity.World is IClientWorldAccessor) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); tf.Origin.Set(0.5f, 0.2f, 0.5f); tf.Translation.Set(0, 0, -Math.Min(0.25f, speed * secondsUsed / 4)); tf.Scale = 1f + Math.Min(0.25f, speed * secondsUsed / 4); tf.Rotation.X = Math.Max(-110, -secondsUsed * 90 * speed); byEntity.Controls.UsingHeldItemTransformBefore = tf; } IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (secondsUsed > 1 / speed) { if ((int)(30 * secondsUsed) % 3 == 1) { Vec3d pos = byEntity.Pos.XYZ .Ahead(0.1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw) .Ahead(1.0f, byEntity.Pos.Pitch, byEntity.Pos.Yaw - GameMath.PIHALF) ; pos.Y += byEntity.EyeHeight - 0.4f; smokePouring.minPos = pos.AddCopy(-0.15, -0.15, -0.15); Vec3d blockpos = blockSel.Position.ToVec3d().Add(0.5, 0.2, 0.5); bigMetalSparks.minQuantity = Math.Max(0.2f, 1 - (secondsUsed - 1) / 4); if ((int)(30 * secondsUsed) % 7 == 1) { bigMetalSparks.minPos = pos; bigMetalSparks.minVelocity.Set(-2, -1, -2); bigMetalSparks.addVelocity.Set(4, 1, 4); byEntity.World.SpawnParticles(bigMetalSparks, byPlayer); byEntity.World.SpawnParticles(smokePouring, byPlayer); } float y2 = 0; Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); Cuboidf[] collboxs = block.GetCollisionBoxes(byEntity.World.BlockAccessor, blockSel.Position); for (int i = 0; collboxs != null && i < collboxs.Length; i++) { y2 = Math.Max(y2, collboxs[i].Y2); } // Metal Spark on the mold bigMetalSparks.minVelocity.Set(-2, 1, -2); bigMetalSparks.addVelocity.Set(4, 5, 4); bigMetalSparks.minPos = blockpos.AddCopy(-0.25, y2 - 2 / 16f, -0.25); bigMetalSparks.addPos.Set(0.5, 0, 0.5); bigMetalSparks.glowLevel = (byte)GameMath.Clamp((int)temp - 770, 48, 128); byEntity.World.SpawnParticles(bigMetalSparks, byPlayer); // Smoke on the mold byEntity.World.SpawnParticles( Math.Max(1, 12 - (secondsUsed - 1) * 6), ColorUtil.ToRgba(50, 220, 220, 220), blockpos.AddCopy(-0.5, y2 - 2 / 16f, -0.5), blockpos.Add(0.5, y2 - 2 / 16f + 0.15, 0.5), new Vec3f(-0.5f, 0f, -0.5f), new Vec3f(0.5f, 0f, 0.5f), 1.5f, -0.05f, 0.75f, EnumParticleModel.Quad, byPlayer ); } int transferedAmount = Math.Min(2, contents.Value); be.ReceiveLiquidMetal(contents.Key, ref transferedAmount, temp); int newAmount = Math.Max(0, contents.Value - (2 - transferedAmount)); slot.Itemstack.Attributes.SetInt("units", newAmount); if (newAmount <= 0 && byEntity.World is IServerWorldAccessor) { slot.Itemstack = new ItemStack(byEntity.World.GetBlock(new AssetLocation("crucible-burned"))); slot.MarkDirty(); // Since we change the item stack we have to call this ourselves OnHeldInteractStop(secondsUsed, slot, byEntity, blockSel, entitySel); return(false); } return(true); } return(true); }
public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (byEntity.Attributes.GetInt("aimingCancel") == 1) { return; } byEntity.Attributes.SetInt("aiming", 0); byEntity.StopAnimation("bowaim"); if (byEntity.World is IClientWorldAccessor) { slot.Itemstack.TempAttributes.SetInt("renderVariant", 0); } if (secondsUsed < 0.35f) { return; } IItemSlot arrowSlot = GetNextArrow(byEntity); if (arrowSlot == null) { return; } string arrowMaterial = arrowSlot.Itemstack.Collectible.FirstCodePart(1); float damage = 0; // Bow damage if (slot.Itemstack.Collectible.Attributes != null) { damage += slot.Itemstack.Collectible.Attributes["damage"].AsFloat(0); } // Arrow damage if (arrowSlot.Itemstack.Collectible.Attributes != null) { damage += arrowSlot.Itemstack.Collectible.Attributes["damage"].AsFloat(0); } ItemStack stack = arrowSlot.TakeOut(1); arrowSlot.MarkDirty(); IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } byEntity.World.PlaySoundAt(new AssetLocation("sounds/bow-release"), byEntity, byPlayer, false, 8); EntityProperties type = byEntity.World.GetEntityType(new AssetLocation("arrow")); Entity entity = byEntity.World.ClassRegistry.CreateEntity(type); ((EntityProjectile)entity).FiredBy = byEntity; ((EntityProjectile)entity).Damage = damage; ((EntityProjectile)entity).ProjectileStack = stack; ((EntityProjectile)entity).DropOnImpactChance = (arrowMaterial == "flint") ? 0.5f : 0.65f;; int?texIndex = type.Attributes?["texturealternateMapping"]?[arrowMaterial].AsInt(0); entity.WatchedAttributes.SetInt("textureIndex", texIndex == null ? 0 : (int)texIndex); float acc = (1 - byEntity.Attributes.GetFloat("aimingAccuracy", 0)); double rndpitch = byEntity.WatchedAttributes.GetDouble("aimingRandPitch", 1) * acc * 0.75; double rndyaw = byEntity.WatchedAttributes.GetDouble("aimingRandYaw", 1) * acc * 0.75; Vec3d pos = byEntity.ServerPos.XYZ.Add(0, byEntity.EyeHeight - 0.2, 0); Vec3d aheadPos = pos.AheadCopy(1, byEntity.ServerPos.Pitch + rndpitch, byEntity.ServerPos.Yaw + rndyaw); Vec3d velocity = (aheadPos - pos) * 0.75; entity.ServerPos.SetPos(byEntity.ServerPos.BehindCopy(0.21).XYZ.Add(0, byEntity.EyeHeight - 0.2, 0)); entity.ServerPos.Motion.Set(velocity); entity.Pos.SetFrom(entity.ServerPos); entity.World = byEntity.World; ((EntityProjectile)entity).SetRotation(); byEntity.World.SpawnEntity(entity); slot.Itemstack.Collectible.DamageItem(byEntity.World, byEntity, slot); byEntity.StartAnimation("bowhit"); }
public override void OnHeldInteractStart(IItemSlot itemslot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { bool knappable = itemslot.Itemstack.Collectible.Attributes != null && itemslot.Itemstack.Collectible.Attributes["knappable"].AsBool(false); bool haveKnappableStone = false; IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; if (knappable && byEntity.Controls.Sneak && blockSel != null) { Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position); haveKnappableStone = block.Code.Path.StartsWith("loosestones") && block.FirstCodePart(1).Equals(itemslot.Itemstack.Collectible.FirstCodePart(1)) ; } if (haveKnappableStone) { if (!byEntity.World.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use)) { itemslot.MarkDirty(); return; } IWorldAccessor world = byEntity.World; Block knappingBlock = world.GetBlock(new AssetLocation("knappingsurface")); if (knappingBlock == null) { return; } BlockPos pos = blockSel.Position; if (!knappingBlock.IsSuitablePosition(world, pos)) { return; } world.BlockAccessor.SetBlock(knappingBlock.BlockId, pos); if (knappingBlock.Sounds != null) { world.PlaySoundAt(knappingBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z); } BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface; if (bec != null) { bec.BaseMaterial = itemslot.Itemstack.Clone(); bec.BaseMaterial.StackSize = 1; if (byEntity.World is IClientWorldAccessor) { bec.OpenDialog(world as IClientWorldAccessor, pos, itemslot.Itemstack); } } //itemslot.Take(1); handling = EnumHandHandling.PreventDefault; byEntity.Attributes.SetInt("aimingCancel", 1); return; } if (blockSel != null && byEntity?.World != null && byEntity.Controls.Sneak) { IWorldAccessor world = byEntity.World; Block block = world.GetBlock(CodeWithPath("loosestones-" + LastCodePart())); if (block == null) { return; } if (!world.BlockAccessor.GetBlock(blockSel.Position).SideSolid[BlockFacing.UP.Index]) { return; } BlockPos targetpos = blockSel.Position.AddCopy(blockSel.Face); BlockSelection placeSel = blockSel.Clone(); placeSel.Position = targetpos; placeSel.DidOffset = true; if (!block.TryPlaceBlock(world, byPlayer, itemslot.Itemstack, placeSel)) { return; } if (block.Sounds != null) { world.PlaySoundAt(block.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z); } itemslot.Itemstack.StackSize--; handling = EnumHandHandling.PreventDefault; byEntity.Attributes.SetInt("aimingCancel", 1); return; } if (byEntity.Controls.Sneak) { return; } // Not ideal to code the aiming controls this way. Needs an elegant solution - maybe an event bus? byEntity.Attributes.SetInt("aiming", 1); byEntity.Attributes.SetInt("aimingCancel", 0); byEntity.StartAnimation("aim"); handling = EnumHandHandling.PreventDefault; }
private bool SpillContents(IItemSlot bucketSlot, IEntityAgent byEntity, BlockSelection blockSel) { BlockPos pos = blockSel.Position; IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; IBlockAccessor blockAcc = byEntity.World.BlockAccessor; BlockPos secondPos = blockSel.Position.AddCopy(blockSel.Face); WaterTightContainableProps props = GetContentProps(byEntity.World, bucketSlot.Itemstack); if (props == null || !props.AllowSpill || props.WhenSpilled == null) { return(false); } if (props.WhenSpilled.Action == WaterTightContainableProps.EnumSpilledAction.PlaceBlock) { Block waterBlock = byEntity.World.GetBlock(props.WhenSpilled.Stack.Code); if (props.WhenSpilled.StackByFillLevel != null) { float currentlitres = GetCurrentLitres(byEntity.World, bucketSlot.Itemstack); JsonItemStack fillLevelStack = null; props.WhenSpilled.StackByFillLevel.TryGetValue((int)currentlitres, out fillLevelStack); if (fillLevelStack != null) { waterBlock = byEntity.World.GetBlock(fillLevelStack.Code); } } if (blockAcc.GetBlock(pos).Replaceable >= 6000) { blockAcc.SetBlock(waterBlock.BlockId, pos); blockAcc.MarkBlockDirty(pos); } else { if (blockAcc.GetBlock(secondPos).Replaceable >= 6000) { blockAcc.SetBlock(waterBlock.BlockId, secondPos); blockAcc.MarkBlockDirty(secondPos); } else { return(false); } } } if (props.WhenSpilled.Action == WaterTightContainableProps.EnumSpilledAction.DropContents) { props.WhenSpilled.Stack.Resolve(byEntity.World, "bucketspill"); ItemStack stack = props.WhenSpilled.Stack.ResolvedItemstack.Clone(); stack.StackSize = (int)(props.ItemsPerLitre * GetContent(byEntity.World, bucketSlot.Itemstack).StackSize); byEntity.World.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(blockSel.HitPosition)); } ItemStack emptyBucketStack = new ItemStack(this); if (bucketSlot.Itemstack.StackSize <= 1) { bucketSlot.Itemstack = emptyBucketStack; bucketSlot.MarkDirty(); } else { bucketSlot.TakeOut(1); if (!byPlayer.InventoryManager.TryGiveItemstack(emptyBucketStack, true)) { byEntity.World.SpawnItemEntity(emptyBucketStack, byEntity.LocalPos.XYZ); } } byEntity.World.PlaySoundAt(props.FillSpillSound, pos.X, pos.Y, pos.Z, byPlayer); return(true); }
public bool TryFillBucketFromBlock(IItemSlot itemslot, IEntityAgent byEntity, BlockPos pos) { IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; IBlockAccessor blockAcc = byEntity.World.BlockAccessor; Block block = blockAcc.GetBlock(pos); if (block.Attributes?["waterTightContainerProps"].Exists == false) { return(false); } WaterTightContainableProps props = block.Attributes?["waterTightContainerProps"]?.AsObject <WaterTightContainableProps>(); if (props?.WhenFilled == null || !props.Containable) { return(false); } props.WhenFilled.Stack.Resolve(byEntity.World, "blockbucket"); ItemStack contentStack = GetContent(byEntity.World, itemslot.Itemstack); if (contentStack != null && contentStack.Equals(props.WhenFilled.Stack.ResolvedItemstack)) { SetContent(itemslot.Itemstack, contentStack); itemslot.MarkDirty(); return(true); } // Is full if (contentStack != null && contentStack.StackSize == (int)(props.ItemsPerLitre * BucketCapacityLitres)) { return(false); } contentStack = props.WhenFilled.Stack.ResolvedItemstack.Clone(); contentStack.StackSize = (int)(props.ItemsPerLitre * BucketCapacityLitres); ItemStack fullBucketStack = new ItemStack(this); SetContent(fullBucketStack, contentStack); if (itemslot.Itemstack.StackSize <= 1) { itemslot.Itemstack = fullBucketStack; } else { itemslot.TakeOut(1); if (!byPlayer.InventoryManager.TryGiveItemstack(fullBucketStack, true)) { byEntity.World.SpawnItemEntity(fullBucketStack, byEntity.LocalPos.XYZ); } } itemslot.MarkDirty(); byEntity.World.PlaySoundAt(props.FillSpillSound, pos.X, pos.Y, pos.Z, byPlayer); return(true); }
private bool TryPut(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { IItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot; if (slot.Itemstack == null) { return(false); } ItemStack stack = slot.Itemstack; string metalType = stack.Collectible.LastCodePart(); bool viableTier = metalsByCode.ContainsKey(metalType) && metalsByCode[metalType].Tier <= OwnMetalTier + 1; bool viableBaseMaterial = stack.Collectible is ItemIngot && CanWork(stack) && viableTier; // Place ingot if (viableBaseMaterial && (workItemStack == null || workItemStack.Collectible.LastCodePart().Equals(stack.Collectible.LastCodePart()))) { if (workItemStack == null) { if (world is IClientWorldAccessor) { OpenDialog(stack); } CreateInitialWorkItem(); workItemStack = new ItemStack(api.World.GetItem(new AssetLocation("workitem-" + stack.Collectible.LastCodePart()))); workItemStack.Collectible.SetTemperature(api.World, workItemStack, stack.Collectible.GetTemperature(api.World, stack)); baseMaterial = new ItemStack(api.World.GetItem(new AssetLocation("ingot-" + stack.Collectible.LastCodePart()))); } AvailableVoxels += 32; stack.StackSize--; if (stack.StackSize <= 0) { slot.Itemstack = null; } slot.MarkDirty(); RegenMeshAndSelectionBoxes(); MarkDirty(); return(true); } // Place workitem bool viableWorkItem = stack.Collectible.FirstCodePart().Equals("workitem") && viableTier; if (viableWorkItem) { try { deserializeVoxels(slot.Itemstack.Attributes.GetBytes("voxels")); AvailableVoxels = slot.Itemstack.Attributes.GetInt("availableVoxels"); selectedRecipeNumber = slot.Itemstack.Attributes.GetInt("selectedRecipeNumber"); workItemStack = stack.Clone(); slot.Itemstack = null; slot.MarkDirty(); } catch (Exception) { } if (selectedRecipeNumber < 0 && world is IClientWorldAccessor) { OpenDialog(stack); } RegenMeshAndSelectionBoxes(); CheckIfFinished(byPlayer); MarkDirty(); return(true); } return(false); }
public override void OnHeldInteractStart(IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } IWorldAccessor world = byEntity.World; BlockPos offsetedPos = blockSel.Position.AddCopy(blockSel.Face); BlockPos belowPos = offsetedPos.DownCopy(); Block targetedBlock = world.BlockAccessor.GetBlock(blockSel.Position); Block nextblock; AssetLocation loc = new AssetLocation(this.Attributes["blockfirstcodepart"].AsString()); string firstcodepart = loc.Path; IPlayer player = byEntity.World.PlayerByUid((byEntity as EntityPlayer)?.PlayerUID); if (!byEntity.World.TestPlayerAccessBlock(player, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { slot.MarkDirty(); return; } if (targetedBlock.FirstCodePart() == firstcodepart) { int stage = 1; int.TryParse(targetedBlock.LastCodePart(), out stage); if (stage == 9) { return; } nextblock = world.GetBlock(targetedBlock.CodeWithPart("" + (stage + 1), 1)); world.BlockAccessor.SetBlock(nextblock.BlockId, blockSel.Position); } else { nextblock = byEntity.World.GetBlock(loc.WithPathAppendix("-1")); if (nextblock == null) { return; } Block blockAtTargetPos = world.BlockAccessor.GetBlock(offsetedPos); if (!blockAtTargetPos.IsReplacableBy(nextblock)) { return; } if (!world.BlockAccessor.GetBlock(belowPos).SideSolid[BlockFacing.UP.Index]) { return; } world.BlockAccessor.SetBlock(nextblock.BlockId, offsetedPos); } slot.TakeOut(1); slot.MarkDirty(); if (nextblock.Sounds != null) { IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } world.PlaySoundAt(nextblock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer); } handHandling = EnumHandHandling.PreventDefault; }