2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
2018-02-11 15:08:08 +01:00
|
|
|
* Copyright (c) 2018 TechReborn
|
2017-02-23 13:29:43 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-06-29 19:03:40 +02:00
|
|
|
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;
|
2017-12-28 15:53:56 +01:00
|
|
|
import net.minecraftforge.energy.CapabilityEnergy;
|
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
2017-12-25 01:18:43 +01:00
|
|
|
import reborncore.api.IToolDrop;
|
2017-12-28 15:53:56 +01:00
|
|
|
import reborncore.api.power.IEnergyItemInfo;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2017-12-28 15:53:56 +01:00
|
|
|
import reborncore.common.RebornCoreConfig;
|
|
|
|
import reborncore.common.powerSystem.PoweredItem;
|
2016-08-10 01:45:07 +02:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2017-06-09 04:12:58 +02:00
|
|
|
import reborncore.common.registration.RebornRegistry;
|
|
|
|
import reborncore.common.registration.impl.ConfigRegistry;
|
2016-02-24 09:18:21 +01:00
|
|
|
import reborncore.common.util.Inventory;
|
2017-01-08 20:34:46 +01:00
|
|
|
import techreborn.client.container.IContainerProvider;
|
|
|
|
import techreborn.client.container.builder.BuiltContainer;
|
|
|
|
import techreborn.client.container.builder.ContainerBuilder;
|
2017-12-28 15:53:56 +01:00
|
|
|
import techreborn.compat.CompatManager;
|
2016-02-24 09:18:21 +01:00
|
|
|
import techreborn.init.ModBlocks;
|
2017-06-09 04:12:58 +02:00
|
|
|
import techreborn.lib.ModInfo;
|
2017-12-28 15:53:56 +01:00
|
|
|
import techreborn.utils.IC2ItemCharger;
|
2015-06-29 19:03:40 +02:00
|
|
|
|
2017-06-09 04:12:58 +02:00
|
|
|
@RebornRegistry(modID = ModInfo.MOD_ID)
|
2017-06-14 01:49:52 +02:00
|
|
|
public class TileChargeOMat extends TilePowerAcceptor
|
2017-12-25 01:18:43 +01:00
|
|
|
implements IToolDrop, IInventoryProvider, IContainerProvider {
|
2017-06-09 04:12:58 +02:00
|
|
|
|
|
|
|
@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() {
|
2017-06-09 15:53:24 +02:00
|
|
|
super();
|
2016-08-10 01:45:07 +02:00
|
|
|
}
|
2016-07-21 17:22:56 +02:00
|
|
|
|
2018-03-31 23:39:58 +02:00
|
|
|
// TilePowerAcceptor
|
2016-08-10 01:45:07 +02:00
|
|
|
@Override
|
2017-09-22 03:03:20 +02:00
|
|
|
public void update() {
|
|
|
|
super.update();
|
2016-08-10 01:45:07 +02:00
|
|
|
|
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++) {
|
2017-01-08 20:34:46 +01:00
|
|
|
if (this.inventory.getStackInSlot(i) != ItemStack.EMPTY) {
|
|
|
|
if (this.getEnergy() > 0) {
|
|
|
|
final ItemStack stack = this.inventory.getStackInSlot(i);
|
2017-12-28 15:53:56 +01:00
|
|
|
if (stack.getItem() instanceof IEnergyItemInfo) {
|
2018-03-19 00:35:22 +01:00
|
|
|
IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem();
|
2017-12-28 15:53:56 +01:00
|
|
|
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;
|
2017-12-28 15:53:56 +01:00
|
|
|
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() {
|
2017-06-09 04:12:58 +02:00
|
|
|
return maxEnergy;
|
2016-08-10 01:45:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canAcceptEnergy(final EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canProvideEnergy(final EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public double getBaseMaxOutput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-11 20:12:32 +02:00
|
|
|
public double getBaseMaxInput() {
|
2017-06-09 04:12:58 +02:00
|
|
|
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
|
2016-04-11 18:43:54 +02:00
|
|
|
public Inventory getInventory() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.inventory;
|
|
|
|
}
|
|
|
|
|
2018-03-31 23:39:58 +02:00
|
|
|
// IContainerProvider
|
2017-01-08 20:34:46 +01:00
|
|
|
@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()
|
2017-06-09 04:12:58 +02:00
|
|
|
.tile(this).energySlot(0, 62, 25).energySlot(1, 98, 25).energySlot(2, 62, 45).energySlot(3, 98, 45)
|
2017-09-08 21:39:46 +02:00
|
|
|
.energySlot(4, 62, 65).energySlot(5, 98, 65).syncEnergyValue().addInventory().create(this);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2015-06-29 19:03:40 +02:00
|
|
|
}
|