TechReborn/src/main/java/techreborn/tiles/TileChargeOMat.java

149 lines
5 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;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
2015-11-23 15:45:16 +01:00
import net.minecraft.util.EnumFacing;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import reborncore.api.IToolDrop;
import reborncore.api.power.IEnergyItemInfo;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.RebornCoreConfig;
import reborncore.common.powerSystem.PoweredItem;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry;
2016-02-24 09:18:21 +01:00
import reborncore.common.util.Inventory;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.compat.CompatManager;
2016-02-24 09:18:21 +01:00
import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo;
import techreborn.utils.IC2ItemCharger;
@RebornRegistry(modID = ModInfo.MOD_ID)
2017-06-14 01:49:52 +02:00
public class TileChargeOMat extends TilePowerAcceptor
implements IToolDrop, IInventoryProvider, IContainerProvider {
@ConfigRegistry(config = "machines", category = "charge_bench", key = "ChargeBenchMaxInput", comment = "Charge Bench Max Input (Value in EU)")
public static int maxInput = 512;
@ConfigRegistry(config = "machines", category = "charge_bench", key = "ChargeBenchMaxEnergy", comment = "Charge Bench Max Energy (Value in EU)")
2018-04-07 21:26:28 +02:00
public static int maxEnergy = 100_000_000;
2016-03-25 10:47:34 +01:00
2017-06-14 01:49:52 +02:00
public Inventory inventory = new Inventory(6, "TileChargeOMat", 64, this);
2016-03-25 10:47:34 +01:00
2017-06-14 01:49:52 +02:00
public TileChargeOMat() {
super();
}
2018-03-31 23:39:58 +02:00
// TilePowerAcceptor
@Override
public void update() {
super.update();
2018-03-19 00:35:22 +01:00
if(world.isRemote){
return;
}
2016-10-08 21:46:16 +02:00
for (int i = 0; i < 6; i++) {
if (this.inventory.getStackInSlot(i) != ItemStack.EMPTY) {
if (this.getEnergy() > 0) {
final ItemStack stack = this.inventory.getStackInSlot(i);
if (stack.getItem() instanceof IEnergyItemInfo) {
2018-03-19 00:35:22 +01:00
IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem();
if (PoweredItem.getEnergy(stack) != PoweredItem.getMaxPower(stack)) {
if (canUseEnergy(item.getMaxTransfer(stack))) {
useEnergy(item.getMaxTransfer(stack));
PoweredItem.setEnergy(PoweredItem.getEnergy(stack) + item.getMaxTransfer(stack), stack);
}
}
}
if(CompatManager.isIC2Loaded){
IC2ItemCharger.chargeIc2Item(this, stack);
}
if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
IEnergyStorage energyStorage = stack.getCapability(CapabilityEnergy.ENERGY, null);
2018-03-23 10:05:22 +01:00
int max = Math.min(maxInput, (int) getEnergy()) * RebornCoreConfig.euPerFU;
useEnergy(energyStorage.receiveEnergy(max, false) / RebornCoreConfig.euPerFU);
2016-03-25 10:47:34 +01:00
}
}
}
}
}
2018-03-31 23:39:58 +02:00
2016-03-25 10:47:34 +01:00
@Override
2017-04-11 20:12:32 +02:00
public double getBaseMaxPower() {
return maxEnergy;
}
@Override
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@Override
2017-04-11 20:12:32 +02:00
public double getBaseMaxOutput() {
return 0;
}
@Override
2017-04-11 20:12:32 +02:00
public double getBaseMaxInput() {
return maxInput;
2016-03-25 10:47:34 +01:00
}
2018-03-31 23:39:58 +02:00
// TileLegacyMachineBase
@Override
public boolean canBeUpgraded() {
return false;
}
// IToolDrop
@Override
public ItemStack getToolDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.CHARGE_O_MAT, 1);
}
2016-03-25 10:47:34 +01:00
2018-03-31 23:39:58 +02:00
// IInventoryProvider
2016-03-25 10:47:34 +01:00
@Override
public Inventory getInventory() {
return this.inventory;
}
2018-03-31 23:39:58 +02:00
// IContainerProvider
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
2017-01-08 23:27:45 +01:00
return new ContainerBuilder("chargebench").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).energySlot(0, 62, 25).energySlot(1, 98, 25).energySlot(2, 62, 45).energySlot(3, 98, 45)
.energySlot(4, 62, 65).energySlot(5, 98, 65).syncEnergyValue().addInventory().create(this);
2016-03-25 10:47:34 +01:00
}
}