use of WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTableRecipe in project BloodMagic by WayofTime.
the class RitualCrushing method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
if (currentEssence < getRefreshCost()) {
masterRitualStone.getOwnerNetwork().causeNausea();
return;
}
BlockPos pos = masterRitualStone.getBlockPos();
AreaDescriptor chestRange = getBlockRange(CHEST_RANGE);
TileEntity tile = world.getTileEntity(chestRange.getContainedPositions(pos).get(0));
if (tile != null && Utils.getNumberOfFreeSlots(tile, EnumFacing.DOWN) < 1) {
return;
}
List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
double rawWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DEFAULT, willConfig);
double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig);
double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig);
double destructiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DESTRUCTIVE, willConfig);
double vengefulWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.VENGEFUL, willConfig);
refreshTime = getRefreshTimeForRawWill(rawWill);
boolean consumeRawWill = rawWill >= rawWillDrain && refreshTime != defaultRefreshTime;
boolean isSilkTouch = steadfastWill >= steadfastWillDrain;
boolean useCuttingFluid = corrosiveWill > 0;
int fortune = destructiveWill > 0 ? 3 : 0;
AreaDescriptor crushingRange = getBlockRange(CRUSHING_RANGE);
boolean hasOperated = false;
double rawDrain = 0;
for (BlockPos newPos : crushingRange.getContainedPositions(pos)) {
if (world.isAirBlock(newPos)) {
continue;
}
IBlockState state = world.getBlockState(newPos);
Block block = state.getBlock();
if (block.equals(RegistrarBloodMagicBlocks.RITUAL_CONTROLLER) || block.equals(RegistrarBloodMagicBlocks.RITUAL_STONE) || block.getBlockHardness(state, world, newPos) == -1.0F || Utils.isBlockLiquid(state)) {
continue;
}
boolean isBlockClaimed = false;
if (useCuttingFluid) {
ItemStack checkStack = block.getItem(world, newPos, state);
if (checkStack.isEmpty()) {
continue;
}
ItemStack copyStack = checkStack.copy();
for (Entry<ItemStack, Integer> entry : cuttingFluidLPMap.entrySet()) {
ItemStack cuttingStack = entry.getKey();
int lpDrain = entry.getValue();
double willDrain = cuttingFluidWillMap.containsKey(cuttingStack) ? cuttingFluidWillMap.get(cuttingStack) : 0;
if (corrosiveWill < willDrain || currentEssence < lpDrain + getRefreshCost()) {
continue;
}
cuttingStack = cuttingStack.copy();
List<ItemStack> input = new ArrayList<>();
input.add(cuttingStack);
input.add(copyStack);
AlchemyTableRecipe recipe = AlchemyTableRecipeRegistry.getMatchingRecipe(input, world, pos);
if (recipe == null) {
continue;
}
ItemStack result = recipe.getRecipeOutput(input);
if (result.isEmpty()) {
continue;
}
if (tile != null) {
result = Utils.insertStackIntoTile(result, tile, EnumFacing.DOWN);
if (!result.isEmpty()) {
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, result);
}
} else {
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, result);
}
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, willDrain, true);
corrosiveWill -= willDrain;
masterRitualStone.getOwnerNetwork().syphon(lpDrain);
currentEssence -= lpDrain;
isBlockClaimed = true;
}
}
if (!isBlockClaimed && isSilkTouch && block.canSilkHarvest(world, newPos, state, null)) {
ItemStack checkStack = block.getItem(world, newPos, state);
if (checkStack.isEmpty()) {
continue;
}
ItemStack copyStack = checkStack.copy();
if (steadfastWill >= steadfastWillDrain) {
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.STEADFAST, steadfastWillDrain, true);
steadfastWill -= steadfastWillDrain;
} else {
continue;
}
if (tile != null)
copyStack = Utils.insertStackIntoTile(copyStack, tile, EnumFacing.DOWN);
else
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
if (!copyStack.isEmpty()) {
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
}
} else if (!isBlockClaimed) {
if (fortune > 0 && destructiveWill < destructiveWillDrain) {
fortune = 0;
}
List<ItemStack> stackList = block.getDrops(world, newPos, state, fortune);
for (ItemStack item : stackList) {
ItemStack copyStack = item.copy();
if (tile != null) {
copyStack = Utils.insertStackIntoTile(copyStack, tile, EnumFacing.DOWN);
} else {
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
continue;
}
if (!copyStack.isEmpty()) {
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
}
}
if (fortune > 0) {
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DESTRUCTIVE, destructiveWillDrain, true);
destructiveWill -= destructiveWillDrain;
}
}
world.destroyBlock(newPos, false);
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
hasOperated = true;
if (consumeRawWill) {
rawDrain += rawWillDrain;
rawWill -= rawWillDrain;
}
break;
}
if (hasOperated && tile != null && vengefulWill >= vengefulWillDrain) {
Pair<ItemStack, Boolean> pair = CompressionRegistry.compressInventory(tile, world);
if (pair.getRight()) {
ItemStack returned = pair.getLeft();
if (returned != null) {
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, returned);
}
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.VENGEFUL, vengefulWillDrain, true);
}
}
if (rawDrain > 0) {
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DEFAULT, rawDrain, true);
}
}
use of WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTableRecipe in project BloodMagic by WayofTime.
the class TileAlchemyTable method update.
@Override
public void update() {
if (isSlave()) {
return;
}
List<ItemStack> inputList = new ArrayList<>();
for (int i = 0; i < 6; i++) {
if (!getStackInSlot(i).isEmpty()) {
inputList.add(getStackInSlot(i));
}
}
int tier = getTierOfOrb();
// special recipes like dying
AlchemyTableRecipe recipe = AlchemyTableRecipeRegistry.getMatchingRecipe(inputList, getWorld(), getPos());
if (recipe != null && (burnTime > 0 || (!getWorld().isRemote && tier >= recipe.getTierRequired() && this.getContainedLp() >= recipe.getLpDrained()))) {
if (burnTime == 1)
notifyUpdate();
if (canCraft(recipe.getRecipeOutput(inputList))) {
ticksRequired = recipe.getTicksRequired();
burnTime++;
if (burnTime == ticksRequired) {
if (!getWorld().isRemote) {
int requiredLp = recipe.getLpDrained();
if (requiredLp > 0) {
if (!getWorld().isRemote) {
consumeLp(requiredLp);
}
}
if (!getWorld().isRemote) {
craftItem(inputList, recipe);
}
}
burnTime = 0;
IBlockState state = getWorld().getBlockState(pos);
getWorld().notifyBlockUpdate(getPos(), state, state, 3);
} else if (burnTime > ticksRequired + 10) {
burnTime = 0;
}
} else {
burnTime = 0;
}
} else {
// Simple recipes
RecipeAlchemyTable recipeAlchemyTable = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getAlchemyTable(inputList);
if (recipeAlchemyTable != null && (burnTime > 0 || (!getWorld().isRemote && tier >= recipeAlchemyTable.getMinimumTier() && getContainedLp() >= recipeAlchemyTable.getSyphon()))) {
if (burnTime == 1)
notifyUpdate();
if (canCraft(recipeAlchemyTable.getOutput())) {
ticksRequired = recipeAlchemyTable.getTicks();
burnTime++;
if (burnTime >= ticksRequired) {
if (!getWorld().isRemote) {
if (recipeAlchemyTable.getSyphon() > 0 && !getWorld().isRemote)
consumeLp(recipeAlchemyTable.getSyphon());
ItemStack outputSlotStack = getStackInSlot(outputSlot);
if (outputSlotStack.isEmpty())
setInventorySlotContents(outputSlot, recipeAlchemyTable.getOutput().copy());
else
outputSlotStack.grow(recipeAlchemyTable.getOutput().getCount());
for (int i = 0; i < 6; i++) {
ItemStack currentStack = getStackInSlot(i);
if (currentStack.getItem().hasContainerItem(currentStack))
setInventorySlotContents(i, currentStack.getItem().getContainerItem(currentStack));
else
currentStack.shrink(1);
}
burnTime = 0;
notifyUpdate();
}
}
}
} else {
burnTime = 0;
}
}
}
Aggregations