Skip to content

Commit f64f743

Browse files
authored
Implement crafting and fix Tags SourceGeneration (#494)
1 parent 5ad2954 commit f64f743

File tree

63 files changed

+671
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+671
-324
lines changed

Obsidian.API/Containers/BaseContainer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public abstract class BaseContainer : IEnumerable<ItemStack>
77
{
88
protected ItemStack?[] items;
99

10-
public int Size => this.items.Length;
10+
public short Size => (short)this.items.Length;
1111

1212
public InventoryType Type { get; }
1313

@@ -117,8 +117,8 @@ public virtual bool RemoveItem(int slot, int amount, out ItemStack? removedItem)
117117
return this.RemoveItem(slot, amount);
118118
}
119119

120-
public virtual (int slot, bool forPlayer) GetDifference(int clickedSlot) =>
121-
clickedSlot > this.Size ? (clickedSlot - this.Size + 9, true) : (clickedSlot, false);
120+
public virtual (short slot, bool forPlayer) GetDifference(short clickedSlot) =>
121+
clickedSlot > this.Size ? ((short)(clickedSlot - this.Size + 9), true) : (clickedSlot, false);
122122

123123
public virtual void Resize(int newSize) => Array.Resize(ref this.items, newSize);
124124

Obsidian.API/Containers/CraftingTable.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@ namespace Obsidian.API.Containers;
44

55
public sealed class CraftingTable : ResultContainer
66
{
7-
public CraftingTable() : base(10, InventoryType.Crafting)
8-
{
9-
this.Title = "Crafting Table";
10-
}
11-
12-
public override void SetResult(ItemStack? result) => throw new NotImplementedException();
13-
public override ItemStack? GetResult() => throw new NotImplementedException();
14-
}
15-
16-
public sealed class Crafter : ResultContainer
17-
{
18-
public Crafter() : base(3 * 3, InventoryType.Crafter)
7+
public CraftingTable(InventoryType type = InventoryType.Crafting) : base(10, type)
198
{
9+
if(type != InventoryType.Crafting || type != InventoryType.Crafter)
10+
throw new ArgumentException("CraftingTable must be of type InventoryType.Crafting or InventoryType.Crafter", nameof(type));
2011

12+
this.Title = type == InventoryType.Crafting ? "Crafting Table" : "Crafter";
2113
}
2214

23-
public override ItemStack? GetResult() => throw new NotImplementedException();
2415
public override void SetResult(ItemStack? result) => throw new NotImplementedException();
16+
public override ItemStack? GetResult() => throw new NotImplementedException();
2517
}

Obsidian.API/Crafting/Ingredient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ public Ingredient()
1818

1919
public void Remove(ItemStack item) => this.items.Remove(item);
2020

21-
/// <inheritdoc/>
2221
public IEnumerator<ItemStack> GetEnumerator() => new IngredientEnumerator(this.items);
2322

2423
IEnumerator IEnumerable.GetEnumerator() => (IEnumerator)this;
2524

25+
public bool CanBe(ItemStack item) => this.items.Any(x => x.Equals(item));
26+
2627
private class IngredientEnumerator : IEnumerator<ItemStack>
2728
{
2829
public int Position { get; set; } = -1;

Obsidian.API/Effects/ConsumeEffect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace Obsidian.API.Effects;
2-
public readonly struct ConsumeEffect
2+
public readonly record struct ConsumeEffect
33
{
44
public required string Type { get; init; }
55

Obsidian.API/Events/ContainerClickEventArgs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public sealed class ContainerClickEventArgs : ContainerEventArgs, ICancellable
77
/// <summary>
88
/// Gets the current item that was clicked. />
99
/// </summary>
10-
public ItemStack? Item => this.Container.GetItem(this.ClickedSlot);
10+
public ItemStack? Item => this.ClickedSlot != -999 ? this.Container.GetItem(this.ClickedSlot) : null;
1111

1212
public bool IsPlayerInventory => this.ContainerId == 0;
1313

@@ -22,7 +22,7 @@ public sealed class ContainerClickEventArgs : ContainerEventArgs, ICancellable
2222
/// <summary>
2323
/// Gets the slot that was clicked
2424
/// </summary>
25-
public required int ClickedSlot { get; init; }
25+
public required short ClickedSlot { get; init; }
2626

2727
/// <summary>
2828
/// The button that was clicked in the inventory. Can vary depending on the inventory type.

Obsidian.API/Inventory/AttributeModifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace Obsidian.API.Inventory;
2-
public readonly struct AttributeModifier : INetworkSerializable<AttributeModifier>
2+
public readonly record struct AttributeModifier : INetworkSerializable<AttributeModifier>
33
{
44
public required int Id { get; init; }
55

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Obsidian.API.Inventory;
2+
public abstract record DataComponent
3+
{
4+
public abstract DataComponentType Type { get; }
5+
6+
public abstract string Identifier { get; }
7+
8+
public virtual void Write(INetStreamWriter writer) { }
9+
10+
public virtual void Read(INetStreamReader reader) { }
11+
}

Obsidian.API/Inventory/DataComponents/BlockPredicatesDataComponent.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
1-
namespace Obsidian.API.Inventory.DataComponents;
2-
public abstract class BlockPredicatesDataComponent : IDataComponent
1+
using Obsidian.Nbt;
2+
3+
namespace Obsidian.API.Inventory.DataComponents;
4+
public abstract record class BlockPredicatesDataComponent : DataComponent
35
{
4-
public abstract DataComponentType Type { get; }
6+
public override DataComponentType Type { get; }
57

6-
public abstract string Identifier { get; }
8+
public override string Identifier { get; }
79

810
public List<BlockPredicate> Predicates { get; init; }
911

1012
public bool ShowInTooltip { get; init; }
1113

12-
public virtual void Read(INetStreamReader reader) => throw new NotImplementedException();
13-
public virtual void Write(INetStreamWriter writer) => throw new NotImplementedException();
1414
public void WriteHashed(INetStreamWriter writer) => throw new NotImplementedException();
1515
}
1616

1717

18-
public readonly struct BlockPredicate
18+
public readonly record struct BlockPredicate
1919
{
2020
public bool HasBlocks => this.BlockIds.Count > 0;
2121

2222
public List<string> BlockIds { get; init; }
2323

24-
2524
public bool HasProperties => this.Properties.Count > 0;
2625

2726
public List<BlockProperty> Properties { get; init; }
2827

2928
public bool HasNbt => this.Nbt != null;
3029

31-
//WE NEED NBT PAIN
32-
public object? Nbt { get; init; }
30+
public NbtCompound? Nbt { get; init; }
3331
}
3432

35-
public readonly struct BlockProperty
33+
public readonly record struct BlockProperty
3634
{
3735
public required string Name { get; init; }
3836

Obsidian.API/Inventory/DataComponents/CanPlaceOnDataComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace Obsidian.API.Inventory.DataComponents;
2-
public sealed class CanPlaceOnDataComponent : BlockPredicatesDataComponent
2+
public sealed record class CanPlaceOnDataComponent : BlockPredicatesDataComponent
33
{
44
public override DataComponentType Type => DataComponentType.CanPlaceOn;
55

66
public override string Identifier => "minecraft:can_place_on";
77
}
88

9-
public sealed class CanBreakDataComponent : BlockPredicatesDataComponent
9+
public sealed record class CanBreakDataComponent : BlockPredicatesDataComponent
1010
{
1111
public override DataComponentType Type => DataComponentType.CanPlaceOn;
1212

Obsidian.API/Inventory/DataComponents/ComponentBuilder.Map.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Obsidian.API.Inventory.DataComponents;
44
public partial class ComponentBuilder
55
{
66
//TODO SOURCE GENERATE THIS
7-
internal static ImmutableArray<Func<IDataComponent?>> ComponentsMap { get; } = new List<Func<IDataComponent?>>
7+
internal static ImmutableArray<Func<DataComponent?>> ComponentsMap { get; } = new List<Func<DataComponent?>>
88
{
99
() => CustomData,
1010
() => MaxStackSize,

0 commit comments

Comments
 (0)