TechReborn/src/main/java/techreborn/tiles/idsu/TileIDSU.java

170 lines
3.7 KiB
Java
Raw Normal View History

package techreborn.tiles.idsu;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.Core;
2015-06-21 15:17:47 +02:00
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
2015-07-26 17:01:27 +02:00
import techreborn.lib.Functions;
import techreborn.powerSystem.TilePowerAcceptor;
public class TileIDSU extends TilePowerAcceptor {
2015-07-26 17:01:27 +02:00
public String ownerUdid;
2015-07-26 17:01:27 +02:00
@Override
2015-06-21 15:17:47 +02:00
public double getEnergy() {
2015-07-26 17:01:27 +02:00
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower;
}
2015-07-26 17:01:27 +02:00
@Override
2015-06-21 15:17:47 +02:00
public void setEnergy(double energy) {
2015-07-26 17:01:27 +02:00
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower = energy;
}
2015-07-26 17:01:27 +02:00
@Override
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
}
@Override
public void writeToNBTWithoutCoords(NBTTagCompound tag) {
}
@Override
public double getMaxPower() {
2015-07-26 17:01:27 +02:00
return 1000000000;
}
@Override
public boolean canAcceptEnergy(ForgeDirection direction) {
2015-07-26 17:01:27 +02:00
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != Functions.getIntDirFromDirection(direction);
}
@Override
public boolean canProvideEnergy(ForgeDirection direction) {
2015-07-26 17:01:27 +02:00
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == Functions.getIntDirFromDirection(direction);
}
@Override
public double getMaxOutput() {
2015-07-26 17:01:27 +02:00
return output;
}
@Override
public double getMaxInput() {
2015-07-26 17:01:27 +02:00
return maxStorage;
}
public int tier;
public int output;
public double maxStorage;
2015-06-21 15:17:47 +02:00
private double euLastTick = 0;
private double euChange;
private int ticks;
public TileIDSU(int tier1, int output1, int maxStorage1) {
super(tier1);
this.tier = tier1;
this.output = output1;
this.maxStorage = maxStorage1;
}
public TileIDSU(){
this(5, 2048, 100000000);
}
public float getChargeLevel() {
2015-06-21 15:17:47 +02:00
float ret = (float) this.getEnergy() / (float) this.maxStorage;
if (ret > 1.0F) {
ret = 1.0F;
}
return ret;
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
2015-07-26 17:01:27 +02:00
this.ownerUdid = nbttagcompound.getString("ownerUdid");
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
2015-07-26 17:01:27 +02:00
nbttagcompound.setString("ownerUdid", this.ownerUdid);
}
public void updateEntity() {
super.updateEntity();
2015-06-21 15:17:47 +02:00
if (ticks == ConfigTechReborn.aveargeEuOutTickTime) {
euChange = -1;
ticks = 0;
} else {
ticks++;
2015-07-26 17:01:27 +02:00
euChange += getEnergy() - euLastTick;
if (euLastTick == getEnergy()) {
2015-06-21 15:17:47 +02:00
euChange = 0;
}
}
2015-07-26 17:01:27 +02:00
euLastTick = getEnergy();
2015-06-21 15:17:47 +02:00
boolean needsInvUpdate = false;
2015-06-21 15:17:47 +02:00
if (needsInvUpdate) {
this.markDirty();
}
}
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
2015-06-21 15:17:47 +02:00
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.Idsu, 1);
writeToNBT(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
2015-06-21 15:17:47 +02:00
public double getEuChange() {
if (euChange == -1) {
return -1;
}
return (euChange / ticks);
}
2015-07-26 17:01:27 +02:00
public void handleGuiInputFromClient(int id){
if(id == 0){
output += 256;
}
if(id == 1){
output += 64;
}
if(id == 2){
output -= 64;
}
if(id == 3){
output -= 256;
}
if(output > 4096){
output = 4096;
}
if(output <= -1){
output = 0;
}
}
}