use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.
the class BindingRecipeMaker method getRecipes.
@Nonnull
public static List<BindingRecipeJEI> getRecipes() {
Map<List<ItemStack>, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> alchemyArrayRecipeMap = AlchemyArrayRecipeRegistry.getRecipes();
ArrayList<BindingRecipeJEI> recipes = new ArrayList<>();
for (Map.Entry<List<ItemStack>, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> itemStackAlchemyArrayRecipeEntry : alchemyArrayRecipeMap.entrySet()) {
List<ItemStack> input = itemStackAlchemyArrayRecipeEntry.getValue().getInput();
BiMap<ItemStackWrapper, AlchemyArrayEffect> catalystMap = itemStackAlchemyArrayRecipeEntry.getValue().catalystMap;
for (Map.Entry<ItemStackWrapper, AlchemyArrayEffect> entry : catalystMap.entrySet()) {
ItemStack catalyst = entry.getKey().toStack();
if (AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(input, catalyst) instanceof AlchemyArrayEffectBinding) {
ItemStack output = ((AlchemyArrayEffectBinding) itemStackAlchemyArrayRecipeEntry.getValue().getAlchemyArrayEffectForCatalyst(catalyst)).outputStack;
BindingRecipeJEI recipe = new BindingRecipeJEI(input, catalyst, output);
recipes.add(recipe);
}
}
}
return recipes;
}
use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.
the class ItemBoundTool method dropStacks.
protected static void dropStacks(Multiset<ItemStackWrapper> drops, World world, BlockPos posToDrop) {
for (Multiset.Entry<ItemStackWrapper> entry : drops.entrySet()) {
int count = entry.getCount();
ItemStackWrapper stack = entry.getElement();
int maxStackSize = stack.item.getItemStackLimit(stack.toStack(1));
while (count >= maxStackSize) {
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(maxStackSize)));
count -= maxStackSize;
}
if (count > 0)
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(count)));
}
}
use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.
the class AlchemyArrayRecipeRegistry method getRecipeForOutputStack.
/**
* @param stack of the recipe
* @return an array of two ItemStacks - first index is the input stack,
* second is the catalyst stack. Returns {null, null} if no recipe
* is valid.
*/
public static ItemStack[] getRecipeForOutputStack(ItemStack stack) {
for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
AlchemyArrayRecipe recipe = entry.getValue();
if (recipe != null && entry.getKey().size() > 0) {
for (Entry<ItemStackWrapper, AlchemyArrayEffect> effectEntry : recipe.catalystMap.entrySet()) {
if (effectEntry.getValue() instanceof AlchemyArrayEffectCrafting) {
AlchemyArrayEffectCrafting craftingEffect = (AlchemyArrayEffectCrafting) effectEntry.getValue();
ItemStack resultStack = craftingEffect.outputStack;
if (!resultStack.isEmpty()) {
if (resultStack.getItem() == stack.getItem() && resultStack.getItemDamage() == stack.getItemDamage()) {
return new ItemStack[] { entry.getKey().get(0), effectEntry.getKey().toStack() };
}
}
}
}
}
}
return new ItemStack[] { null, null };
}
use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.
the class ItemBoundPickaxe method onBoundRelease.
@Override
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
if (world.isRemote)
return;
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
// Charge is a max of 30 - want 5 to be the max
int range = (charge / 6);
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
BlockPos playerPos = player.getPosition();
for (int i = -range; i <= range; i++) {
for (int j = 0; j <= 2 * range; j++) {
for (int k = -range; k <= range; k++) {
BlockPos blockPos = playerPos.add(i, j, k);
BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
continue;
if (blockStack.getState().getMaterial() != Material.ROCK && !EFFECTIVE_ON.contains(blockStack.getBlock()))
continue;
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
continue;
if (blockStack.getBlock() != null && blockStack.getBlock().getBlockHardness(blockStack.getState(), world, blockPos) != -1) {
float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos)) {
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
drops.add(new ItemStackWrapper(blockStack));
else {
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
for (ItemStack stacks : itemDrops) drops.add(ItemStackWrapper.getHolder(stacks));
}
world.setBlockToAir(blockPos);
}
}
}
}
}
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
dropStacks(drops, world, playerPos.add(0, 1, 0));
}
use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.
the class ItemBoundAxe method onBoundRelease.
@Override
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
if (world.isRemote)
return;
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
// Charge is a max of 30 - want 5 to be the max
int range = charge / 6;
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
BlockPos playerPos = player.getPosition();
for (int i = -range; i <= range; i++) {
for (int j = 0; j <= 2 * range; j++) {
for (int k = -range; k <= range; k++) {
BlockPos blockPos = playerPos.add(i, j, k);
BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
continue;
if (blockStack.getState().getMaterial() != Material.WOOD && !EFFECTIVE_ON.contains(blockStack.getBlock()))
continue;
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
continue;
if (blockStack.getState().getBlockHardness(world, blockPos) != -1.0F) {
float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
if (strengthVsBlock > 1.1F || blockStack.getBlock() instanceof BlockLeaves && world.canMineBlockBody(player, blockPos)) {
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
drops.add(new ItemStackWrapper(blockStack));
else {
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
for (ItemStack stacks : itemDrops) drops.add(ItemStackWrapper.getHolder(stacks));
}
world.setBlockToAir(blockPos);
}
}
}
}
}
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.1F, false);
dropStacks(drops, world, playerPos.add(0, 1, 0));
}
Aggregations