Skip to content

Commit

Permalink
Implemented simple connected textures example in RedCottonBlockDefini…
Browse files Browse the repository at this point in the history
…tion (#325)
  • Loading branch information
jvbsl authored Nov 1, 2023
1 parent 1905756 commit d80745e
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using OctoAwesome.Basics.Definitions.Materials;
using System;
using OctoAwesome.Basics.Definitions.Materials;
using OctoAwesome.Chunking;
using OctoAwesome.Definitions;
using OctoAwesome.Location;

namespace OctoAwesome.Basics.Definitions.Blocks
{
Expand All @@ -15,7 +18,25 @@ public sealed class RedCottonBlockDefinition : BlockDefinition
public override string Icon => "cotton_red";

/// <inheritdoc />
public override string[] Textures { get; } = { "cotton_red" };
public override string[] Textures =>
new[]{
"cotton_red_0",
"cotton_red_1",
"cotton_red_2",
"cotton_red_3",
"cotton_red_4",
"cotton_red_5",
"cotton_red_6",
"cotton_red_7",
"cotton_red_8",
"cotton_red_9",
"cotton_red_10",
"cotton_red_11",
"cotton_red_12",
"cotton_red_13",
"cotton_red_14",
"cotton_red_15",
};

/// <inheritdoc />
public override IMaterialDefinition Material { get; }
Expand All @@ -28,5 +49,46 @@ public RedCottonBlockDefinition(CottonMaterialDefinition material)
{
Material = material;
}

/// <inheritdoc />
public override int GetTextureIndex(Wall wall, ILocalChunkCache manager, int x, int y, int z)
{
int fullBlockTextureIndex = 15;
var centerBlock = new Index3(x, y, z);
var baseBlockIndex = manager.GetBlock(centerBlock);

var (firstAxis, secondAxis) = wall switch
{
Wall.Top => (Index3.UnitX, Index3.UnitY),
Wall.Bottom => (-Index3.UnitX, Index3.UnitY),
Wall.Left => (Index3.UnitY, -Index3.UnitZ),
Wall.Right => (-Index3.UnitY, -Index3.UnitZ),
Wall.Front => (Index3.UnitX, -Index3.UnitZ),
Wall.Back => (-Index3.UnitX, -Index3.UnitZ),
_ => throw new ArgumentOutOfRangeException(nameof(wall), wall, null)
};

fullBlockTextureIndex = RemoveEdgesOnAxis(manager, centerBlock, firstAxis, 0, baseBlockIndex, fullBlockTextureIndex);
fullBlockTextureIndex = RemoveEdgesOnAxis(manager, centerBlock, secondAxis, 1, baseBlockIndex, fullBlockTextureIndex);

return fullBlockTextureIndex;
}

private static int RemoveEdgesOnAxis(ILocalChunkCache manager, Index3 centerBlock, Index3 axis, int sideOffset, ushort baseBlockIndex,
int fullBlockTextureIndex)
{
for (int i = -1; i <= 1; i+=2)
{
var otherIndex = manager.GetBlock(centerBlock + axis * i);

if (otherIndex == baseBlockIndex)
{
var bitOffset = (i + 1) + sideOffset;
fullBlockTextureIndex &= ~(1 << bitOffset);
}
}

return fullBlockTextureIndex;
}
}
}
10 changes: 10 additions & 0 deletions OctoAwesome/OctoAwesome/Location/Index3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ public double Length()
public int LengthSquared()
=> X * X + Y * Y + Z * Z;

/// <summary>
/// Calculates the componentwise factorization with -1.
/// </summary>
/// <param name="val">The calculated factorization with -1.</param>
/// <returns>The componentwise factorized result.</returns>
public static Index3 operator -(Index3 val)
{
return new Index3(-val.X, -val.Y, -val.Z);
}

/// <summary>
/// Calculates the sum of two <see cref="Index3"/> componentwise.
/// </summary>
Expand Down

0 comments on commit d80745e

Please sign in to comment.