Skip to content

Instantly share code, notes, and snippets.

@alcatrazEscapee
Last active August 26, 2019 01:14
Show Gist options
  • Save alcatrazEscapee/d86148ba3d9af480c810da482fc8102d to your computer and use it in GitHub Desktop.
Save alcatrazEscapee/d86148ba3d9af480c810da482fc8102d to your computer and use it in GitHub Desktop.
Fix spacing
@Nullable
IBlockState findSlabVariant(World world, BlockPos pos, IBlockState stateIn)
{
ItemStack stackIn = stateIn.getBlock().getPickBlock(stateIn, null, world, pos, null);
if (!stackIn.isEmpty())
{
// Slab inventory shape
InventoryCrafting craftMatrix = new InventoryCraftingEmpty();
// todo: figure out which index positions match to a slab pattern
for (int index : SLAB_INDEXES)
{
craftMatrix.setInventorySlotContents(index, stackIn.copy());
}
for (IRecipe recipe : ForgeRegistries.RECIPES.getValuesCollection())
{
if (recipe.matches(craftMatrix, world))
{
// Found matching recipe, try and extract a slab block
ItemStack stackOut = recipe.getCraftingResult(craftMatrix);
if (stackOut.getItem() instanceof ItemBlock)
{
Block blockOut = ((ItemBlock) stackOut.getItem()).getBlock();
if (blockOut instanceof BlockSlab)
{
return blockOut.getDefaultState();
}
}
// Don't continue searching recipes
return null;
}
}
}
return null;
}
@Nullable
IBlockState findStairVariant(World world, BlockPos pos, IBlockState stateIn)
{
ItemStack stackIn = stateIn.getBlock().getPickBlock(stateIn, null, world, pos, null);
if (!stackIn.isEmpty())
{
// Slab inventory shape
InventoryCrafting craftMatrix = new InventoryCraftingEmpty();
// todo: figure out which index positions match to a stair pattern
for (int index : STAIR_INDEXES)
{
craftMatrix.setInventorySlotContents(index, stackIn.copy());
}
for (IRecipe recipe : ForgeRegistries.RECIPES.getValuesCollection())
{
if (recipe.matches(craftMatrix, world))
{
// Found matching recipe, try and extract a slab block
ItemStack stackOut = recipe.getCraftingResult(craftMatrix);
if (stackOut.getItem() instanceof ItemBlock)
{
Block blockOut = ((ItemBlock) stackOut.getItem()).getBlock();
if (blockOut instanceof BlockStairs)
{
return blockOut.getDefaultState();
}
}
return null;
}
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment