use of crafttweaker.api.item.IItemStack in project artisan-worktables by codetaylor.
the class CTArtisanRecipe method getStacksArray.
/**
* Sets the given stacks array to the matrix items re-ordered to match the recipe's ingredient list order.
*
* @return false if no recipe match
*/
private boolean getStacksArray(IItemStack[] stacks, int[] indices, List<IArtisanIngredient> ingredients, ICraftingMatrixStackHandler craftingMatrix, int startX, int startY, int width, int height, boolean mirror) {
for (int x = 0; x < craftingMatrix.getWidth(); ++x) {
for (int y = 0; y < craftingMatrix.getHeight(); ++y) {
int subX = x - startX;
int subY = y - startY;
IArtisanIngredient ingredient = ArtisanIngredient.EMPTY;
int index = 0;
if (subX >= 0 && subY >= 0 && subX < width && subY < height) {
if (mirror) {
index = width - subX - 1 + subY * width;
ingredient = ingredients.get(index);
} else {
index = subX + subY * width;
ingredient = ingredients.get(index);
}
}
int matrixIndex = x + y * craftingMatrix.getWidth();
ItemStack candidate = craftingMatrix.getStackInSlot(matrixIndex);
if (!ingredient.matches(candidate)) {
return false;
}
// index is the recipe's ingredient index
stacks[index] = CraftTweakerMC.getIItemStack(candidate);
indices[index] = matrixIndex;
}
}
return true;
}
use of crafttweaker.api.item.IItemStack in project artisan-worktables by codetaylor.
the class CTArtisanRecipe method getStacksShapeless.
/**
* @return the matrix items re-ordered to match the recipe's ingredient list order
*/
private MatchInfo getStacksShapeless(ICraftingContext context) {
List<IArtisanIngredient> ingredients = this.getIngredientList();
ICraftingMatrixStackHandler matrixHandler = context.getCraftingMatrixHandler();
List<ItemStack> itemList = new ArrayList<>(matrixHandler.getSlots());
List<Integer> indexList = new ArrayList<>(matrixHandler.getSlots());
IItemStack[] stacks = new IItemStack[ingredients.size()];
int[] indices = new int[ingredients.size()];
for (int i = 0; i < matrixHandler.getSlots(); i++) {
ItemStack itemStack = matrixHandler.getStackInSlot(i);
if (!itemStack.isEmpty()) {
itemList.add(itemStack);
indexList.add(i);
}
}
List<Ingredient> ingredientList = new ArrayList<>(ingredients.size());
for (IArtisanIngredient ingredient : ingredients) {
ingredientList.add(ingredient.toIngredient());
}
int[] matches = RecipeMatcher.findMatches(itemList, ingredientList);
for (int i = 0; i < matches.length; i++) {
stacks[matches[i]] = CraftTweakerMC.getIItemStack(itemList.get(i));
indices[matches[i]] = indexList.get(i);
}
return new MatchInfo(stacks, indices);
}
use of crafttweaker.api.item.IItemStack in project CraftTweaker by CraftTweaker.
the class MCMod method getItems.
@Override
public IItemStack[] getItems() {
List<IItemStack> stacks = new ArrayList<>();
List<Item> items = BracketHandlerItem.getItemNames().values().stream().filter(item -> item.getRegistryName().getResourceDomain().equals(mod.getModId())).collect(Collectors.toList());
for (Item item : items) {
if (item == null)
continue;
NonNullList<ItemStack> list = NonNullList.create();
item.getSubItems(CreativeTabs.SEARCH, list);
for (ItemStack stack : list) {
stacks.add(CraftTweakerMC.getIItemStack(stack));
}
}
return stacks.toArray(new IItemStack[0]);
}
use of crafttweaker.api.item.IItemStack in project CraftTweaker by CraftTweaker.
the class MCPlayer method give.
@Override
public void give(IItemStack stack) {
ItemStack itemstack = CraftTweakerMC.getItemStack(stack).copy();
boolean flag = player.inventory.addItemStackToInventory(itemstack);
if (flag) {
player.world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.getRNG().nextFloat() - player.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.inventoryContainer.detectAndSendChanges();
}
if (flag && itemstack.isEmpty()) {
itemstack.setCount(1);
EntityItem entityitem1 = player.dropItem(itemstack, false);
if (entityitem1 != null) {
entityitem1.makeFakeItem();
}
} else {
EntityItem entityitem = player.dropItem(itemstack, false);
if (entityitem != null) {
entityitem.setNoPickupDelay();
entityitem.setOwner(player.getName());
}
}
}
use of crafttweaker.api.item.IItemStack in project CraftTweaker by CraftTweaker.
the class VanillaBrewingPlus method getOutput.
@Override
public ItemStack getOutput(ItemStack input, ItemStack ingredient) {
IItemStack _input = CraftTweakerMC.getIItemStack(input);
IItemStack _ingredient = CraftTweakerMC.getIItemStack(ingredient);
if (removedRecipes.stream().anyMatch(t -> t.getFirst().matches(_input) && t.getSecond().matches(_ingredient))) {
return ItemStack.EMPTY;
}
return super.getOutput(input, ingredient);
}
Aggregations