Rewrite Hymn of Syphoning for caps
Needs testing and needs to be optimized.
This commit is contained in:
parent
c4f92708b1
commit
3f24e464e6
|
@ -2,27 +2,32 @@ package WayofTime.bloodmagic.ritual;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.api.Constants;
|
import WayofTime.bloodmagic.api.Constants;
|
||||||
import WayofTime.bloodmagic.api.ritual.*;
|
import WayofTime.bloodmagic.api.ritual.*;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidBlock;
|
||||||
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||||
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||||
|
import net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper;
|
||||||
|
import net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class RitualPump extends Ritual
|
public class RitualPump extends Ritual
|
||||||
{
|
{
|
||||||
public static final String PUMP_RANGE = "pumpRange";
|
public static final String PUMP_RANGE = "pumpRange";
|
||||||
|
|
||||||
private ArrayList<BlockPos> liquidsCache;
|
private List<Pair<BlockPos, FluidStack>> liquidsCache;
|
||||||
private Iterator<BlockPos> blockPosIterator;
|
private Iterator<Pair<BlockPos, FluidStack>> blockPosIterator;
|
||||||
|
|
||||||
private boolean cached = false;
|
|
||||||
private BlockPos currentPos;
|
|
||||||
|
|
||||||
public RitualPump()
|
public RitualPump()
|
||||||
{
|
{
|
||||||
|
@ -30,7 +35,7 @@ public class RitualPump extends Ritual
|
||||||
addBlockRange(PUMP_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-16, -16, -16), new BlockPos(17, 17, 17)));
|
addBlockRange(PUMP_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-16, -16, -16), new BlockPos(17, 17, 17)));
|
||||||
|
|
||||||
setMaximumVolumeAndDistanceOfRange(PUMP_RANGE, 0, 16, 16);
|
setMaximumVolumeAndDistanceOfRange(PUMP_RANGE, 0, 16, 16);
|
||||||
liquidsCache = new ArrayList<BlockPos>();
|
liquidsCache = Lists.newArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,36 +51,39 @@ public class RitualPump extends Ritual
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tileEntity != null && tileEntity instanceof IFluidHandler)
|
if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
|
||||||
{
|
IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN);
|
||||||
IFluidHandler fluidHandler = (IFluidHandler) tileEntity;
|
IBlockState tankState = world.getBlockState(masterRitualStone.getBlockPos().up());
|
||||||
if (!cached || liquidsCache.isEmpty())
|
int maxDrain = fluidHandler.getTankProperties()[0].getCapacity();
|
||||||
{
|
|
||||||
if (fluidHandler.drain(EnumFacing.DOWN, 1000, false) != null)
|
if (fluidHandler.getTankProperties()[0].getContents() != null && fluidHandler.getTankProperties()[0].getContents().amount >= maxDrain)
|
||||||
{
|
return;
|
||||||
FluidStack fluidStack = fluidHandler.drain(EnumFacing.DOWN, 1000, false);
|
|
||||||
for (BlockPos blockPos : getBlockRange(PUMP_RANGE).getContainedPositions(masterRitualStone.getBlockPos()))
|
for (BlockPos pos : getBlockRange(PUMP_RANGE).getContainedPositions(masterRitualStone.getBlockPos())) {
|
||||||
{
|
IBlockState state = world.getBlockState(pos);
|
||||||
if (!liquidsCache.contains(blockPos))
|
IFluidHandler blockHandler = null;
|
||||||
{
|
if (state.getBlock() instanceof BlockLiquid)
|
||||||
if (!world.isAirBlock(blockPos) && world.getBlockState(blockPos).getBlock() == fluidStack.getFluid().getBlock() && world.getBlockState(blockPos).getValue(BlockLiquid.LEVEL) == 0)
|
blockHandler = new BlockLiquidWrapper((BlockLiquid) state.getBlock(), world, pos);
|
||||||
{
|
else if (state.getBlock() instanceof IFluidHandler)
|
||||||
liquidsCache.add(blockPos);
|
blockHandler = new FluidBlockWrapper((IFluidBlock) state.getBlock(), world, pos);
|
||||||
}
|
|
||||||
|
if (blockHandler != null) {
|
||||||
|
FluidStack blockDrain = blockHandler.drain(maxDrain, false);
|
||||||
|
if (blockDrain != null && fluidHandler.fill(blockDrain, false) == blockDrain.amount) {
|
||||||
|
Pair<BlockPos, FluidStack> posInfo = Pair.of(pos, blockHandler.drain(maxDrain, false));
|
||||||
|
if (!liquidsCache.contains(posInfo))
|
||||||
|
liquidsCache.add(posInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cached = true;
|
|
||||||
blockPosIterator = liquidsCache.iterator();
|
blockPosIterator = liquidsCache.iterator();
|
||||||
}
|
if (blockPosIterator.hasNext()) {
|
||||||
|
Pair<BlockPos, FluidStack> posInfo = blockPosIterator.next();
|
||||||
if (blockPosIterator.hasNext())
|
|
||||||
{
|
|
||||||
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
|
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
|
||||||
currentPos = blockPosIterator.next();
|
fluidHandler.fill(posInfo.getRight(), true);
|
||||||
fluidHandler.fill(EnumFacing.DOWN, fluidHandler.drain(EnumFacing.DOWN, 1000, false), true);
|
world.setBlockState(posInfo.getLeft(), Blocks.STONE.getDefaultState());
|
||||||
world.setBlockState(currentPos, Blocks.STONE.getDefaultState());
|
world.notifyBlockUpdate(posInfo.getLeft(), tankState, tankState, 3);
|
||||||
blockPosIterator.remove();
|
blockPosIterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -611,7 +611,7 @@ ritual.BloodMagic.meteorRitual=Mark of the Falling Tower
|
||||||
ritual.BloodMagic.cobblestoneRitual=Le Vulcanos Frigius
|
ritual.BloodMagic.cobblestoneRitual=Le Vulcanos Frigius
|
||||||
ritual.BloodMagic.placerRitual=Laying of the Filler
|
ritual.BloodMagic.placerRitual=Laying of the Filler
|
||||||
ritual.BloodMagic.fellingRitual=Crash of the Timberman
|
ritual.BloodMagic.fellingRitual=Crash of the Timberman
|
||||||
ritual.BloodMagic.pumpRitual=Hymn of Siphoning
|
ritual.BloodMagic.pumpRitual=Hymn of Syphoning
|
||||||
ritual.BloodMagic.altarBuilderRitual=The Assembly of the High Altar
|
ritual.BloodMagic.altarBuilderRitual=The Assembly of the High Altar
|
||||||
ritual.BloodMagic.portalRitual=The Gate of the Fold
|
ritual.BloodMagic.portalRitual=The Gate of the Fold
|
||||||
ritual.BloodMagic.downgradeRitual=Penance of the Leadened Soul
|
ritual.BloodMagic.downgradeRitual=Penance of the Leadened Soul
|
||||||
|
|
Loading…
Reference in a new issue