2015-06-17 18:01:26 +02:00
|
|
|
package techreborn.tiles.idsu;
|
|
|
|
|
|
|
|
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-03-13 16:37:55 +01:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2016-03-08 18:34:04 +01:00
|
|
|
import reborncore.api.power.EnumPowerTier;
|
2016-10-08 21:46:16 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2016-08-10 01:45:07 +02: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
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public class TileIDSU extends TilePowerAcceptor implements IWrenchable {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
public String ownerUdid;
|
|
|
|
public int tier;
|
|
|
|
public int output;
|
|
|
|
public double maxStorage;
|
|
|
|
private double euLastTick = 0;
|
|
|
|
private double euChange;
|
|
|
|
private int ticks;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileIDSU(int tier1, int output1, int maxStorage1) {
|
2016-08-10 01:45:07 +02:00
|
|
|
super(tier1);
|
2016-03-25 10:47:34 +01:00
|
|
|
this.tier = tier1;
|
|
|
|
this.output = output1;
|
|
|
|
this.maxStorage = maxStorage1;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileIDSU() {
|
2016-03-25 10:47:34 +01:00
|
|
|
this(5, 2048, 100000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getEnergy() {
|
|
|
|
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 0.0;
|
|
|
|
}
|
2016-11-19 13:50:08 +01:00
|
|
|
return IDSUManager.INSTANCE.getSaveDataForWorld(world, ownerUdid).storedPower;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void setEnergy(double energy) {
|
|
|
|
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-11-19 13:50:08 +01:00
|
|
|
IDSUManager.INSTANCE.getSaveDataForWorld(world, ownerUdid).storedPower = energy;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
|
2016-08-10 01:45:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxPower() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 1000000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return getFacingEnum() != direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canProvideEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return getFacingEnum() == direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxOutput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxInput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return maxStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumPowerTier getTier() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return EnumPowerTier.EXTREME;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public float getChargeLevel() {
|
2016-03-25 10:47:34 +01:00
|
|
|
float ret = (float) this.getEnergy() / (float) this.maxStorage;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (ret > 1.0F) {
|
2016-03-25 10:47:34 +01:00
|
|
|
ret = 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.readFromNBT(nbttagcompound);
|
|
|
|
this.ownerUdid = nbttagcompound.getString("ownerUdid");
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.writeToNBT(nbttagcompound);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (ownerUdid == null && StringUtils.isBlank(ownerUdid) || StringUtils.isEmpty(ownerUdid)) {
|
2016-05-18 17:53:54 +02:00
|
|
|
return nbttagcompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
nbttagcompound.setString("ownerUdid", this.ownerUdid);
|
2016-05-18 17:53:54 +02:00
|
|
|
return nbttagcompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateEntity() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super.updateEntity();
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (ticks == ConfigTechReborn.AverageEuOutTickTime) {
|
2016-03-25 10:47:34 +01:00
|
|
|
euChange = -1;
|
|
|
|
ticks = 0;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
ticks++;
|
|
|
|
euChange += getEnergy() - euLastTick;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (euLastTick == getEnergy()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
euChange = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
euLastTick = getEnergy();
|
|
|
|
|
2016-08-10 01:51:44 +02:00
|
|
|
boolean needsInvUpdate = false;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (needsInvUpdate) {
|
2016-08-10 01:51:44 +02:00
|
|
|
this.markDirty();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-08-10 01:30:08 +02:00
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer p0, EnumFacing p1) {
|
2016-03-29 21:27:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public EnumFacing getFacing() {
|
2016-03-29 21:27:23 +02:00
|
|
|
return getFacingEnum();
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean wrenchCanRemove(EntityPlayer p0) {
|
2016-03-29 21:27:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public float getWrenchDropRate() {
|
2016-03-29 21:27:23 +02:00
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
2016-03-25 10:47:34 +01:00
|
|
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
2017-01-01 08:29:32 +01:00
|
|
|
ItemStack dropStack = new ItemStack(ModBlocks.INTERDIMENSIONAL_SU, 1);
|
2016-03-25 10:47:34 +01:00
|
|
|
writeToNBT(tileEntity);
|
|
|
|
dropStack.setTagCompound(new NBTTagCompound());
|
|
|
|
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
|
|
|
|
return dropStack;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getEuChange() {
|
|
|
|
if (euChange == -1) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (euChange / ticks);
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void handleGuiInputFromClient(int id) {
|
|
|
|
if (id == 0) {
|
2016-03-25 10:47:34 +01:00
|
|
|
output += 256;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (id == 1) {
|
2016-03-25 10:47:34 +01:00
|
|
|
output += 64;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (id == 2) {
|
2016-03-25 10:47:34 +01:00
|
|
|
output -= 64;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (id == 3) {
|
2016-03-25 10:47:34 +01:00
|
|
|
output -= 256;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (output > 4096) {
|
2016-03-25 10:47:34 +01:00
|
|
|
output = 4096;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (output <= -1) {
|
2016-03-25 10:47:34 +01:00
|
|
|
output = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-06-17 18:01:26 +02:00
|
|
|
}
|