2015-06-17 18:01:26 +02:00
|
|
|
package techreborn.tiles.idsu;
|
|
|
|
|
2016-02-26 14:03:30 +01:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
2015-06-17 18:01:26 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-06-18 19:34:39 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-02-24 09:18:21 +01:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2015-06-21 15:17:47 +02:00
|
|
|
import techreborn.config.ConfigTechReborn;
|
|
|
|
import techreborn.init.ModBlocks;
|
2015-06-17 18:01:26 +02:00
|
|
|
|
2015-07-23 17:19:07 +02:00
|
|
|
public class TileIDSU extends TilePowerAcceptor {
|
2015-06-17 18:01:26 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public String ownerUdid;
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-07-26 17:01:27 +02:00
|
|
|
@Override
|
2015-08-09 12:05:32 +02:00
|
|
|
public double getEnergy() {
|
2015-11-08 13:15:45 +01:00
|
|
|
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
2015-10-22 13:34:11 +02:00
|
|
|
return 0.0;
|
2015-10-08 09:24:48 +02:00
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower;
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-07-26 17:01:27 +02:00
|
|
|
@Override
|
2015-08-09 12:05:32 +02:00
|
|
|
public void setEnergy(double energy) {
|
2015-11-08 13:15:45 +01:00
|
|
|
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
2015-10-08 09:24:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower = energy;
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-07-26 17:01:27 +02:00
|
|
|
@Override
|
|
|
|
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBTWithoutCoords(NBTTagCompound tag) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-23 17:19:07 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxPower() {
|
2015-07-26 17:01:27 +02:00
|
|
|
return 1000000000;
|
2015-07-23 17:19:07 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 20:51:40 +01:00
|
|
|
|
2015-07-23 17:19:07 +02:00
|
|
|
@Override
|
2015-11-23 15:45:16 +01:00
|
|
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
2015-11-26 18:35:31 +01:00
|
|
|
return getFacingEnum() != direction;
|
2015-07-23 17:19:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 15:45:16 +01:00
|
|
|
public boolean canProvideEnergy(EnumFacing direction) {
|
2015-11-26 18:35:31 +01:00
|
|
|
return getFacingEnum() == direction;
|
2015-07-23 17:19:07 +02:00
|
|
|
}
|
|
|
|
|
2015-11-26 18:35:31 +01:00
|
|
|
|
2015-07-23 17:19:07 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxOutput() {
|
2015-07-26 17:01:27 +02:00
|
|
|
return output;
|
2015-07-23 17:19:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxInput() {
|
2015-07-26 17:01:27 +02:00
|
|
|
return maxStorage;
|
2015-07-23 17:19:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int tier;
|
2015-08-09 12:05:32 +02:00
|
|
|
public int output;
|
|
|
|
public double maxStorage;
|
|
|
|
private double euLastTick = 0;
|
|
|
|
private double euChange;
|
|
|
|
private int ticks;
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public TileIDSU(int tier1, int output1, int maxStorage1) {
|
2015-07-23 17:19:07 +02:00
|
|
|
super(tier1);
|
2015-08-09 12:05:32 +02:00
|
|
|
this.tier = tier1;
|
|
|
|
this.output = output1;
|
|
|
|
this.maxStorage = maxStorage1;
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public TileIDSU() {
|
2015-07-13 14:54:44 +02:00
|
|
|
this(5, 2048, 100000000);
|
|
|
|
}
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public float getChargeLevel() {
|
|
|
|
float ret = (float) this.getEnergy() / (float) this.maxStorage;
|
|
|
|
if (ret > 1.0F) {
|
|
|
|
ret = 1.0F;
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
|
|
|
super.readFromNBT(nbttagcompound);
|
|
|
|
this.ownerUdid = nbttagcompound.getString("ownerUdid");
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
|
|
|
super.writeToNBT(nbttagcompound);
|
2015-11-08 13:15:45 +01:00
|
|
|
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
2015-10-08 09:24:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
nbttagcompound.setString("ownerUdid", this.ownerUdid);
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public void updateEntity() {
|
|
|
|
super.updateEntity();
|
2015-06-21 15:17:47 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
if (ticks == ConfigTechReborn.aveargeEuOutTickTime) {
|
|
|
|
euChange = -1;
|
|
|
|
ticks = 0;
|
2015-06-21 15:17:47 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
} else {
|
|
|
|
ticks++;
|
|
|
|
euChange += getEnergy() - euLastTick;
|
|
|
|
if (euLastTick == getEnergy()) {
|
|
|
|
euChange = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-06-21 15:17:47 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
euLastTick = getEnergy();
|
2015-06-21 15:17:47 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
boolean needsInvUpdate = false;
|
2015-06-18 19:34:39 +02:00
|
|
|
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
if (needsInvUpdate) {
|
|
|
|
this.markDirty();
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
|
|
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
|
|
|
ItemStack dropStack = new ItemStack(ModBlocks.Idsu, 1);
|
|
|
|
writeToNBT(tileEntity);
|
|
|
|
dropStack.setTagCompound(new NBTTagCompound());
|
2015-11-23 19:41:29 +01:00
|
|
|
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
|
2015-08-09 12:05:32 +02:00
|
|
|
return dropStack;
|
|
|
|
}
|
2015-06-18 19:34:39 +02:00
|
|
|
|
2015-06-21 15:17:47 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public double getEuChange() {
|
|
|
|
if (euChange == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (euChange / ticks);
|
|
|
|
}
|
2015-07-26 17:01:27 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public void handleGuiInputFromClient(int id) {
|
|
|
|
if (id == 0) {
|
2015-07-26 17:01:27 +02:00
|
|
|
output += 256;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
if (id == 1) {
|
2015-07-26 17:01:27 +02:00
|
|
|
output += 64;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
if (id == 2) {
|
2015-07-26 17:01:27 +02:00
|
|
|
output -= 64;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
if (id == 3) {
|
2015-07-26 17:01:27 +02:00
|
|
|
output -= 256;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
if (output > 4096) {
|
2015-07-26 17:01:27 +02:00
|
|
|
output = 4096;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
if (output <= -1) {
|
2015-07-26 17:01:27 +02:00
|
|
|
output = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-06-17 18:01:26 +02:00
|
|
|
}
|