use of WayofTime.bloodmagic.util.BlockStack in project BloodMagic by WayofTime.
the class RitualAltarBuilder method getBloodRune.
public BlockStack getBloodRune(TileEntity tileEntity) {
if (tileEntity != null) {
if (tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
if (itemHandler.getSlots() <= 0) {
return null;
}
for (int i = 0; i < itemHandler.getSlots(); i++) {
if (!itemHandler.getStackInSlot(i).isEmpty() && itemHandler.getStackInSlot(i).getItem() instanceof ItemBlock && Block.getBlockFromItem(itemHandler.getStackInSlot(i).getItem()) instanceof BlockBloodRune && itemHandler.extractItem(i, 1, true) != null) {
BlockStack blockStack = new BlockStack(Utils.getBlockForComponent(ComponentType.BLOODRUNE), itemHandler.getStackInSlot(i).getItemDamage());
itemHandler.extractItem(i, 1, false);
return blockStack;
}
}
} else if (tileEntity instanceof IInventory) {
IInventory inv = (IInventory) tileEntity;
for (int i = 0; i < inv.getSizeInventory(); i++) {
if (!inv.getStackInSlot(i).isEmpty() && inv.getStackInSlot(i).getItem() instanceof ItemBlock && Block.getBlockFromItem(inv.getStackInSlot(i).getItem()) instanceof BlockBloodRune) {
BlockStack blockStack = new BlockStack(Utils.getBlockForComponent(ComponentType.BLOODRUNE), inv.getStackInSlot(i).getItemDamage());
inv.decrStackSize(i, 1);
return blockStack;
}
}
}
}
return null;
}
use of WayofTime.bloodmagic.util.BlockStack in project BloodMagic by WayofTime.
the class RitualAltarBuilder method getMundaneBlock.
public BlockStack getMundaneBlock(TileEntity tileEntity) {
if (tileEntity != null) {
if (tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
if (itemHandler.getSlots() <= 0) {
return null;
}
for (int i = 0; i < itemHandler.getSlots(); i++) {
if (!itemHandler.getStackInSlot(i).isEmpty() && itemHandler.getStackInSlot(i).getItem() instanceof ItemBlock && !(Block.getBlockFromItem(itemHandler.getStackInSlot(i).getItem()) instanceof BlockBloodRune) && !itemHandler.extractItem(i, 1, true).isEmpty()) {
Block block = Block.getBlockFromItem(itemHandler.getStackInSlot(i).getItem());
if (block != Blocks.AIR && block != Blocks.GLOWSTONE && block != RegistrarBloodMagicBlocks.DECORATIVE_BRICK) {
BlockStack blockStack = new BlockStack(block, itemHandler.getStackInSlot(i).getItemDamage());
itemHandler.extractItem(i, 1, false);
return blockStack;
}
}
}
} else if (tileEntity instanceof IInventory) {
IInventory inv = (IInventory) tileEntity;
for (int i = 0; i < inv.getSizeInventory(); i++) {
if (!inv.getStackInSlot(i).isEmpty() && inv.getStackInSlot(i).getItem() instanceof ItemBlock && !(Block.getBlockFromItem(inv.getStackInSlot(i).getItem()) instanceof BlockBloodRune)) {
Block block = Block.getBlockFromItem(inv.getStackInSlot(i).getItem());
if (block != Blocks.GLOWSTONE && block != RegistrarBloodMagicBlocks.DECORATIVE_BRICK) {
BlockStack blockStack = new BlockStack(block, inv.getStackInSlot(i).getItemDamage());
inv.decrStackSize(i, 1);
return blockStack;
}
}
}
}
}
return null;
}
use of WayofTime.bloodmagic.util.BlockStack in project BloodMagic by WayofTime.
the class RitualAltarBuilder method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
TileEntity tileEntity = world.getTileEntity(masterRitualStone.getBlockPos().up());
BlockPos altarPos = masterRitualStone.getBlockPos().up(2);
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
if (currentEssence < getRefreshCost()) {
masterRitualStone.getOwnerNetwork().causeNausea();
return;
}
if (cycleDone) {
altarComponentsIterator = new ArrayList<>(AltarTier.SIX.getAltarComponents()).iterator();
}
if (world.getBlockState(altarPos).getBlock().isReplaceable(world, altarPos) && hasItem(tileEntity, Item.getItemFromBlock(RegistrarBloodMagicBlocks.ALTAR), 0, true)) {
world.setBlockState(altarPos, RegistrarBloodMagicBlocks.ALTAR.getDefaultState());
lightning(world, altarPos);
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
}
if (altarComponentsIterator.hasNext()) {
currentComponent = altarComponentsIterator.next();
currentPos = altarPos.add(currentComponent.getOffset());
if (world.getBlockState(currentPos).getBlock().isReplaceable(world, currentPos)) {
switch(currentComponent.getComponent()) {
case NOTAIR:
{
BlockStack blockStack = getMundaneBlock(tileEntity);
if (blockStack != null) {
world.setBlockState(currentPos, blockStack.getState(), 3);
lightning(world, currentPos);
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
}
break;
}
case BLOODRUNE:
{
BlockStack blockStack = getBloodRune(tileEntity);
if (blockStack != null) {
world.setBlockState(currentPos, blockStack.getState(), 3);
lightning(world, currentPos);
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
}
break;
}
default:
{
BlockStack blockStack = new BlockStack(Utils.getBlockForComponent(currentComponent.getComponent()), 0);
if (hasItem(tileEntity, Item.getItemFromBlock(blockStack.getBlock()), blockStack.getMeta(), true)) {
world.setBlockState(currentPos, blockStack.getState(), 3);
lightning(world, currentPos);
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
}
break;
}
}
}
} else {
cycleDone = true;
}
}
use of WayofTime.bloodmagic.util.BlockStack 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.BlockStack 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