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

123 lines
4.3 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
2018-02-11 15:08:08 +01:00
* Copyright (c) 2018 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.
*/
package techreborn.tiles.idsu;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import org.apache.commons.lang3.StringUtils;
2017-06-13 14:14:02 +02:00
import reborncore.api.power.EnumPowerTier;
2017-06-09 17:31:19 +02:00
import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry;
2017-06-13 14:14:02 +02:00
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
2015-06-21 15:17:47 +02:00
import techreborn.init.ModBlocks;
2017-06-09 17:31:19 +02:00
import techreborn.lib.ModInfo;
2017-06-13 14:14:02 +02:00
import techreborn.tiles.storage.TileEnergyStorage;
2017-06-09 17:31:19 +02:00
@RebornRegistry(modID = ModInfo.MOD_ID)
public class TileInterdimensionalSU extends TileEnergyStorage implements IContainerProvider {
2016-03-25 10:47:34 +01:00
2017-06-09 17:31:19 +02:00
@ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxInput", comment = "IDSU Max Input (Value in EU)")
public static int maxInput = 8192;
@ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxOutput", comment = "IDSU Max Output (Value in EU)")
public static int maxOutput = 8192;
@ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxEnergy", comment = "IDSU Max Energy (Value in EU)")
2018-06-22 17:22:16 +02:00
public static int maxEnergy = 100_000_000;
2017-06-09 17:31:19 +02:00
2016-03-25 10:47:34 +01:00
public String ownerUdid;
public TileInterdimensionalSU() {
2017-06-13 14:14:02 +02:00
super("IDSU", 2, ModBlocks.INTERDIMENSIONAL_SU, EnumPowerTier.EXTREME, maxInput, maxOutput, maxEnergy);
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public double getEnergy() {
if (ownerUdid == null || ownerUdid.isEmpty()) {
2016-03-25 10:47:34 +01:00
return 0.0;
}
2017-06-13 17:02:49 +02:00
return IDSUManager.getData(world).getStoredPower();
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 || ownerUdid.isEmpty()) {
2016-03-25 10:47:34 +01:00
return;
}
2017-06-13 17:02:49 +02:00
IDSUManager.getData(world).setStoredPower(energy);
2016-03-25 10:47:34 +01:00
}
@Override
public double useEnergy(double extract, boolean simulate) {
if (ownerUdid == null || ownerUdid.isEmpty()) {
return 0.0;
}
double energy = IDSUManager.getData(world).getStoredPower();
if (extract > energy) {
extract = energy;
}
if (!simulate) {
setEnergy(energy - extract);
}
return extract;
}
2017-10-08 01:41:54 +02:00
@Override
public boolean canUseEnergy(double input) {
if (ownerUdid == null || ownerUdid.isEmpty()) {
return false;
}
return input <= IDSUManager.getData(world).getStoredPower();
}
2016-03-25 10:47:34 +01:00
@Override
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");
}
@Override
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
@Override
2017-06-13 14:14:02 +02:00
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("idsu").player(player.inventory).inventory().hotbar().armor()
2017-06-13 14:14:02 +02:00
.complete(8, 18).addArmor().addInventory().tile(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create(this);
2016-03-25 10:47:34 +01:00
}
2017-06-13 20:43:27 +02:00
@Override
public boolean shouldHanldeEnergyNBT() {
return false;
}
}