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-04-28 00:51:06 +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-08-30 22:57:14 +02:00
import reborncore.api.IToolDrop ;
2017-12-25 01:18:43 +01:00
import reborncore.api.tile.IInventoryProvider ;
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 ;
2015-11-08 13:15:45 +01:00
import reborncore.common.util.Inventory ;
import reborncore.common.util.ItemUtils ;
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-03-13 11:22:06 +01:00
import techreborn.init.IC2Duplicates ;
2015-04-28 00:51:06 +02:00
import techreborn.init.ModBlocks ;
2015-06-22 12:32:30 +02:00
import techreborn.init.ModItems ;
2016-03-27 19:56:27 +02:00
import techreborn.items.ItemParts ;
2017-06-09 04:12:58 +02:00
import techreborn.lib.ModInfo ;
2015-06-22 12:32:30 +02:00
2017-06-09 04:12:58 +02:00
@RebornRegistry ( modID = ModInfo . MOD_ID )
2017-01-08 20:34:46 +01:00
public class TileMatterFabricator extends TilePowerAcceptor
2017-08-30 22:57:14 +02:00
implements IToolDrop , IInventoryProvider , IContainerProvider {
2016-03-25 10:47:34 +01:00
2017-06-09 04:12:58 +02:00
@ConfigRegistry ( config = " machines " , category = " matter_fabricator " , key = " MatterFabricatorMaxInput " , comment = " Matter Fabricator Max Input (Value in EU) " )
public static int maxInput = 8192 ;
@ConfigRegistry ( config = " machines " , category = " matter_fabricator " , key = " MatterFabricatorMaxEnergy " , comment = " Matter Fabricator Max Energy (Value in EU) " )
2018-03-31 23:39:58 +02:00
public static int maxEnergy = 100_000_000 ;
2017-08-09 09:53:19 +02:00
@ConfigRegistry ( config = " machines " , category = " matter_fabricator " , key = " MatterFabricatorFabricationRate " , comment = " Matter Fabricator Fabrication Rate, amount of amplifier units per UUM " )
2018-04-13 17:27:46 +02:00
public static int fabricationRate = 6_000 ;
2017-08-09 09:53:19 +02:00
@ConfigRegistry ( config = " machines " , category = " matter_fabricator " , key = " MatterFabricatorEnergyPerAmp " , comment = " Matter Fabricator EU per amplifier unit, multiply this with the rate for total EU " )
2018-04-13 17:27:46 +02:00
public static int energyPerAmp = 5 ;
2017-06-09 04:12:58 +02:00
2017-09-15 23:50:43 +02:00
public Inventory inventory = new Inventory ( 12 , " TileMatterFabricator " , 64 , this ) ;
2016-03-25 10:47:34 +01:00
private int amplifier = 0 ;
2016-10-08 21:46:16 +02:00
public TileMatterFabricator ( ) {
2017-06-09 17:31:19 +02:00
super ( ) ;
2016-03-25 10:47:34 +01:00
}
2018-03-31 23:39:58 +02:00
2016-10-08 21:46:16 +02:00
private boolean spaceForOutput ( ) {
2017-06-02 21:36:02 +02:00
for ( int i = 6 ; i < 11 ; i + + ) {
2017-06-09 04:12:58 +02:00
if ( spaceForOutput ( i ) ) {
2017-05-23 14:28:35 +02:00
return true ;
}
}
return false ;
}
private boolean spaceForOutput ( int slot ) {
2017-06-02 21:20:56 +02:00
return this . inventory . getStackInSlot ( slot ) . isEmpty ( )
2017-05-23 14:28:35 +02:00
| | ItemUtils . isItemEqual ( this . inventory . getStackInSlot ( slot ) , new ItemStack ( ModItems . UU_MATTER ) , true , true )
2017-06-02 21:20:56 +02:00
& & this . inventory . getStackInSlot ( slot ) . getCount ( ) < 64 ;
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
private void addOutputProducts ( ) {
2017-06-02 21:36:02 +02:00
for ( int i = 6 ; i < 11 ; i + + ) {
2017-06-09 04:12:58 +02:00
if ( spaceForOutput ( i ) ) {
2017-05-23 14:28:35 +02:00
addOutputProducts ( i ) ;
break ;
}
}
}
private void addOutputProducts ( int slot ) {
2017-06-02 21:20:56 +02:00
if ( this . inventory . getStackInSlot ( slot ) . isEmpty ( ) ) {
2017-05-23 14:28:35 +02:00
this . inventory . setInventorySlotContents ( slot , new ItemStack ( ModItems . UU_MATTER ) ) ;
} else if ( ItemUtils . isItemEqual ( this . inventory . getStackInSlot ( slot ) , new ItemStack ( ModItems . UU_MATTER ) , true , true ) ) {
2017-06-02 21:20:56 +02:00
this . inventory . getStackInSlot ( slot ) . setCount ( ( Math . min ( 64 , 1 + this . inventory . getStackInSlot ( slot ) . getCount ( ) ) ) ) ;
2016-03-25 10:47:34 +01:00
}
}
2017-01-08 15:22:59 +01:00
public boolean decreaseStoredEnergy ( final double aEnergy , final boolean aIgnoreTooLessEnergy ) {
2016-10-08 21:46:16 +02:00
if ( this . getEnergy ( ) - aEnergy < 0 & & ! aIgnoreTooLessEnergy ) {
2016-03-25 10:47:34 +01:00
return false ;
2016-10-08 21:46:16 +02:00
} else {
2017-01-08 15:22:59 +01:00
this . setEnergy ( this . getEnergy ( ) - aEnergy ) ;
2016-10-08 21:46:16 +02:00
if ( this . getEnergy ( ) < 0 ) {
2017-01-08 15:22:59 +01:00
this . setEnergy ( 0 ) ;
2016-03-25 10:47:34 +01:00
return false ;
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
return true ;
}
}
}
2017-01-08 15:22:59 +01:00
public int getValue ( final ItemStack itemStack ) {
2017-01-01 08:29:32 +01:00
if ( itemStack . getItem ( ) = = ModItems . PARTS & & itemStack . getItemDamage ( ) = = ItemParts . getPartByName ( " scrap " ) . getItemDamage ( ) ) {
2017-03-13 11:22:06 +01:00
return 200 ;
2017-01-01 08:29:32 +01:00
} else if ( itemStack . getItem ( ) = = ModItems . SCRAP_BOX ) {
2017-03-13 11:22:06 +01:00
return 2000 ;
}
2017-04-08 16:03:46 +02:00
if ( IC2Duplicates . SCRAP . hasIC2Stack ( ) ) {
if ( ItemUtils . isInputEqual ( itemStack , IC2Duplicates . SCRAP . getIc2Stack ( ) , true , true , true ) ) {
2017-03-13 11:22:06 +01:00
return 200 ;
}
2016-03-27 19:56:27 +02:00
}
2016-03-25 10:47:34 +01:00
return 0 ;
}
2018-03-31 23:39:58 +02:00
public int getProgress ( ) {
return this . amplifier ;
}
public void setProgress ( final int progress ) {
this . amplifier = progress ;
}
public int getProgressScaled ( final int scale ) {
if ( this . amplifier ! = 0 ) {
return Math . min ( this . amplifier * scale / fabricationRate , 100 ) ;
}
return 0 ;
}
// TilePowerAcceptor
@Override
public void update ( ) {
if ( world . isRemote ) { return ; }
super . update ( ) ;
this . charge ( 11 ) ;
for ( int i = 0 ; i < 6 ; i + + ) {
final ItemStack stack = this . inventory . getStackInSlot ( i ) ;
if ( ! stack . isEmpty ( ) & & spaceForOutput ( ) ) {
final int amp = this . getValue ( stack ) ;
final int euNeeded = amp * energyPerAmp ;
if ( amp ! = 0 & & this . canUseEnergy ( euNeeded ) ) {
this . useEnergy ( euNeeded ) ;
this . amplifier + = amp ;
this . inventory . decrStackSize ( i , 1 ) ;
}
}
}
if ( amplifier > = fabricationRate ) {
if ( spaceForOutput ( ) ) {
this . addOutputProducts ( ) ;
amplifier - = fabricationRate ;
}
}
}
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
}
2016-10-08 21:46:16 +02:00
@Override
2017-01-08 15:22:59 +01:00
public boolean canAcceptEnergy ( final EnumFacing direction ) {
2016-08-10 01:45:07 +02:00
return true ;
}
2016-10-08 21:46:16 +02:00
@Override
2017-01-08 15:22:59 +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
2016-04-11 18:43:54 +02:00
@Override
2018-03-31 23:39:58 +02:00
public boolean canBeUpgraded ( ) {
return false ;
2017-01-08 15:22:59 +01:00
}
2018-03-31 23:39:58 +02:00
// IToolDrop
@Override
public ItemStack getToolDrop ( final EntityPlayer entityPlayer ) {
return new ItemStack ( ModBlocks . MATTER_FABRICATOR , 1 ) ;
2017-01-08 15:22:59 +01:00
}
2018-03-31 23:39:58 +02:00
// IInventoryProvider
@Override
public Inventory getInventory ( ) {
return this . inventory ;
2016-04-11 18:43:54 +02:00
}
2017-01-08 20:34:46 +01:00
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-09-15 23:50:43 +02:00
return new ContainerBuilder ( " matterfabricator " ) . player ( player . inventory ) . inventory ( ) . hotbar ( ) . addInventory ( )
. tile ( this ) . slot ( 0 , 30 , 20 ) . slot ( 1 , 50 , 20 ) . slot ( 2 , 70 , 20 ) . slot ( 3 , 90 , 20 ) . slot ( 4 , 110 , 20 )
. slot ( 5 , 130 , 20 ) . outputSlot ( 6 , 40 , 66 ) . outputSlot ( 7 , 60 , 66 ) . outputSlot ( 8 , 80 , 66 )
. outputSlot ( 9 , 100 , 66 ) . outputSlot ( 10 , 120 , 66 ) . energySlot ( 11 , 8 , 72 ) . syncEnergyValue ( )
. syncIntegerValue ( this : : getProgress , this : : setProgress ) . addInventory ( ) . create ( this ) ;
2017-01-08 20:34:46 +01:00
}
2015-04-28 00:51:06 +02:00
}