2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-05-08 22:42:09 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockLiquid;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-05-13 08:46:17 +02:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-05-08 22:42:09 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-11-19 15:41:00 +01:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
2016-11-25 14:25:51 +01:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.IFluidBlock;
|
2016-11-19 15:41:00 +01:00
|
|
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
2016-08-10 01:29:47 +02:00
|
|
|
import reborncore.common.powerSystem.PowerSystem;
|
2016-08-10 01:45:07 +02:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2016-05-08 22:42:09 +02:00
|
|
|
import reborncore.common.util.Tank;
|
|
|
|
import techreborn.config.ConfigTechReborn;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by modmuss50 on 08/05/2016.
|
|
|
|
*/
|
2016-11-19 15:41:00 +01:00
|
|
|
public class TilePump extends TilePowerAcceptor {
|
2016-05-08 22:42:09 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public Tank tank = new Tank("TilePump", 10000, this);
|
|
|
|
|
|
|
|
public TilePump() {
|
|
|
|
super(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity() {
|
|
|
|
super.updateEntity();
|
2016-11-19 13:50:08 +01:00
|
|
|
if (!world.isRemote && world.getTotalWorldTime() % 10 == 0 && !tank.isFull() && tank.getCapacity() - tank.getFluidAmount() >= 1000 && canUseEnergy(ConfigTechReborn.pumpExtractEU)) {
|
|
|
|
FluidStack fluidStack = drainBlock(world, pos.down(), false);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (fluidStack != null) {
|
2016-11-19 13:50:08 +01:00
|
|
|
tank.fill(drainBlock(world, pos.down(), true), true);
|
2016-10-08 21:46:16 +02:00
|
|
|
useEnergy(ConfigTechReborn.pumpExtractEU);
|
|
|
|
}
|
|
|
|
tank.compareAndUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInfo(List<String> info, boolean isRealTile) {
|
|
|
|
super.addInfo(info, isRealTile);
|
|
|
|
info.add(TextFormatting.LIGHT_PURPLE + "Eu per extract " + TextFormatting.GREEN
|
|
|
|
+ PowerSystem.getLocaliszedPower(ConfigTechReborn.pumpExtractEU));
|
|
|
|
info.add(TextFormatting.LIGHT_PURPLE + "Speed: " + TextFormatting.GREEN
|
|
|
|
+ "1000mb/5 sec");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FluidStack drainBlock(World world, BlockPos pos, boolean doDrain) {
|
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
Block block = state.getBlock();
|
|
|
|
Fluid fluid = FluidRegistry.lookupFluidForBlock(block);
|
|
|
|
|
|
|
|
if (fluid != null && FluidRegistry.isFluidRegistered(fluid)) {
|
|
|
|
if (block instanceof IFluidBlock) {
|
|
|
|
IFluidBlock fluidBlock = (IFluidBlock) block;
|
|
|
|
if (!fluidBlock.canDrain(world, pos)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return fluidBlock.drain(world, pos, doDrain);
|
|
|
|
} else {
|
|
|
|
//Checks if source
|
|
|
|
int level = state.getValue(BlockLiquid.LEVEL);
|
|
|
|
if (level != 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (doDrain) {
|
|
|
|
world.setBlockToAir(pos);
|
|
|
|
}
|
|
|
|
return new FluidStack(fluid, 1000);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public double getBaseMaxPower() {
|
2016-10-08 21:46:16 +02:00
|
|
|
return 10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canProvideEnergy(EnumFacing direction) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public double getBaseMaxOutput() {
|
2016-10-08 21:46:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public double getBaseMaxInput() {
|
2016-10-08 21:46:16 +02:00
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
readFromNBTWithoutCoords(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
|
|
|
|
tank.readFromNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
writeToNBTWithoutCoords(tagCompound);
|
|
|
|
return tagCompound;
|
|
|
|
}
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBTWithoutCoords(NBTTagCompound tagCompound) {
|
|
|
|
tank.writeToNBT(tagCompound);
|
|
|
|
return tagCompound;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-19 15:41:00 +01:00
|
|
|
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
2016-11-25 14:25:51 +01:00
|
|
|
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
2016-11-19 15:41:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.hasCapability(capability, facing);
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-19 15:41:00 +01:00
|
|
|
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
2016-11-25 14:25:51 +01:00
|
|
|
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
2016-11-19 15:41:00 +01:00
|
|
|
return (T) tank;
|
|
|
|
}
|
|
|
|
return super.getCapability(capability, facing);
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
2016-05-08 22:42:09 +02:00
|
|
|
}
|