internal void CollectStack(EntityStack stackToCollect) { int id = stackToCollect.Id; // find first stack of same type foreach (Slot slot in Slots) { if (slot.Content.Id == id && !slot.IsFull) { stackToCollect.TransferAll(slot.Content); if (stackToCollect.IsEmpty) { return; } } } // find first empty slot foreach (Slot slot in Slots) { if (slot.IsEmpty) { slot.Content.Id = id; stackToCollect.TransferAll(slot.Content); return; } } }
internal void CollectStack(EntityStack stackToCollect) { int id = stackToCollect.Id; // find first stack of same type foreach (Slot slot in Slots) { if (slot.Content.Id == id && !slot.IsFull) { stackToCollect.TransferAll(slot.Content); if (stackToCollect.IsEmpty) return; } } // find first empty slot foreach (Slot slot in Slots) { if (slot.IsEmpty) { slot.Content.Id = id; stackToCollect.TransferAll(slot.Content); return; } } }
internal bool TransferAll(EntityStack destinationStack) { if (destinationStack.Count + Count > 64) { return(false); } TransferEntities(destinationStack, Count); return(true); }
internal void Swap(EntityStack swapStack) { int tempCount = this.count; int tempId = this.Id; this.count = swapStack.count; this.Id = swapStack.Id; swapStack.count = tempCount; swapStack.Id = tempId; }
internal void TransferEntities(EntityStack destinationStack, int transferCount) { if (!Compatible(destinationStack)) { return; } destinationStack.Id = this.Id; if (destinationStack.Count + transferCount > 64) { transferCount = 64 - destinationStack.Count; } destinationStack.Add(transferCount); Remove(transferCount); }
internal void ThrowStack(EntityStack stack) { // drop items in crafting table and in hand... if (stack.IsEmpty) { return; } stack.Position = Position + EyePosition; stack.Position.Y -= (float)(MathLibrary.GlobalRandom.NextDouble() * 0.5f); stack.Velocity = Direction * 0.1f; stack.Yaw = (float)(MathLibrary.GlobalRandom.NextDouble() * Math.PI); stack.Pitch = (float)(MathLibrary.GlobalRandom.NextDouble() * Math.PI); stack.Velocity.X += (float)0.05f * (float)(MathLibrary.GlobalRandom.NextDouble() * 2.0 - 1.0); stack.Velocity.Z += (float)0.05f * (float)(MathLibrary.GlobalRandom.NextDouble() * 2.0 - 1.0); stack.Velocity.Y = 0.2f + (float)0.05f * (float)(MathLibrary.GlobalRandom.NextDouble() * 2.0 - 1.0); World.Instance.SpawnStack(stack); throwStackDelay = 20; }
internal Recepe Output(int id, int count) { Product = new EntityStack(id, count); return(this); }
internal void ThrowStack(EntityStack stack) { // drop items in crafting table and in hand... if (stack.IsEmpty) return; stack.Position = Position + EyePosition; stack.Position.Y -= (float)(MathLibrary.GlobalRandom.NextDouble() * 0.5f); stack.Velocity = Direction * 0.1f; stack.Yaw = (float)(MathLibrary.GlobalRandom.NextDouble() * Math.PI); stack.Pitch = (float)(MathLibrary.GlobalRandom.NextDouble() * Math.PI); stack.Velocity.X += (float)0.05f * (float)(MathLibrary.GlobalRandom.NextDouble() * 2.0 - 1.0); stack.Velocity.Z += (float)0.05f * (float)(MathLibrary.GlobalRandom.NextDouble() * 2.0 - 1.0); stack.Velocity.Y = 0.2f + (float)0.05f * (float)(MathLibrary.GlobalRandom.NextDouble() * 2.0 - 1.0); World.Instance.SpawnStack(stack); throwStackDelay = 20; }
internal void TransferEntities(EntityStack destinationStack, int transferCount) { if (!Compatible(destinationStack)) return; destinationStack.Id = this.Id; if (destinationStack.Count + transferCount > 64) { transferCount = 64 - destinationStack.Count; } destinationStack.Add(transferCount); Remove(transferCount); }
internal bool TransferAll(EntityStack destinationStack) { if (destinationStack.Count + Count > 64) return false; TransferEntities(destinationStack, Count); return true; }
internal void ReplaceWithEmptyCompatibleStack(EntityStack stackInHand) { ReplaceWith(stackInHand.Id, 0); }
internal void ReplaceWith(EntityStack newStack) { Id = newStack.Id; count = newStack.Count; }
internal bool Compatible(EntityStack otherStack) { return otherStack.Id == Id || this.Id == 0 || otherStack.Id == 0; }
internal void SpawnStack(EntityStack stack) { PositionChunk positionChunk = PositionChunk.CreateFrom(stack.Position); Chunk chunk = GetChunk(positionChunk); chunk.AddEntity(stack); }
internal Recepe Output(int id, int count) { Product = new EntityStack(id, count); return this; }
internal bool Compatible(EntityStack otherStack) { return(otherStack.Id == Id || this.Id == 0 || otherStack.Id == 0); }