2017-02-23 13:29:43 +01:00
/ *
* This file is part of TechReborn , licensed under the MIT License ( MIT ) .
*
* Copyright ( c ) 2017 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 .
* /
2015-05-09 20:13:43 +02:00
package techreborn.tiles ;
import net.minecraft.entity.player.EntityPlayer ;
2015-06-09 00:30:42 +02:00
import net.minecraft.inventory.ISidedInventory ;
2015-05-09 20:13:43 +02:00
import net.minecraft.item.ItemStack ;
2015-05-09 21:29:26 +02:00
import net.minecraft.nbt.NBTTagCompound ;
2015-11-23 15:45:16 +01:00
import net.minecraft.util.EnumFacing ;
2016-04-11 18:50:00 +02:00
import reborncore.api.recipe.IRecipeCrafterProvider ;
2016-04-11 18:43:54 +02:00
import reborncore.api.tile.IInventoryProvider ;
2017-08-30 22:57:14 +02:00
import reborncore.api.IToolDrop ;
2016-08-10 01:45:07 +02:00
import reborncore.common.powerSystem.TilePowerAcceptor ;
2016-04-11 18:23:57 +02:00
import reborncore.common.recipes.RecipeCrafter ;
2017-06-09 04:12:58 +02:00
import reborncore.common.registration.RebornRegistry ;
import reborncore.common.registration.impl.ConfigRegistry ;
2016-04-11 18:50:00 +02:00
import reborncore.common.util.Inventory ;
2017-02-03 16:57:34 +01:00
import reborncore.common.util.ItemUtils ;
2016-04-03 15:07:45 +02:00
import techreborn.api.Reference ;
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 ;
2016-04-11 18:50:00 +02:00
import techreborn.init.ModBlocks ;
2017-02-03 16:57:34 +01:00
import techreborn.items.DynamicCell ;
2017-06-09 04:12:58 +02:00
import techreborn.lib.ModInfo ;
2015-05-09 20:13:43 +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 TileIndustrialElectrolyzer extends TilePowerAcceptor
2017-08-30 22:57:14 +02:00
implements IToolDrop , IInventoryProvider , ISidedInventory , IRecipeCrafterProvider , IContainerProvider {
2017-06-09 04:12:58 +02:00
@ConfigRegistry ( config = " machines " , category = " industrial_electrolyzer " , key = " IndustrialElectrolyzerMaxInput " , comment = " Industrial Electrolyzer Max Input (Value in EU) " )
public static int maxInput = 128 ;
@ConfigRegistry ( config = " machines " , category = " industrial_electrolyzer " , key = " IndustrialElectrolyzerMaxEnergy " , comment = " Industrial Electrolyzer Max Energy (Value in EU) " )
public static int maxEnergy = 1000 ;
// @ConfigRegistry(config = "machines", category = "industrial_electrolyzer", key = "IndustrialElectrolyzerWrenchDropRate", comment = "Industrial Electrolyzer Wrench Drop Rate")
public static float wrenchDropRate = 1 . 0F ;
2016-03-25 10:47:34 +01:00
public int tickTime ;
public Inventory inventory = new Inventory ( 8 , " TileIndustrialElectrolyzer " , 64 , this ) ;
public RecipeCrafter crafter ;
2016-10-08 21:46:16 +02:00
public TileIndustrialElectrolyzer ( ) {
2017-06-09 17:31:19 +02:00
super ( ) ;
2016-03-25 10:47:34 +01:00
// Input slots
2017-01-08 20:34:46 +01:00
final int [ ] inputs = new int [ 2 ] ;
2016-03-25 10:47:34 +01:00
inputs [ 0 ] = 0 ;
inputs [ 1 ] = 1 ;
2017-09-13 02:40:38 +02:00
// Output slots
2017-01-08 20:34:46 +01:00
final int [ ] outputs = new int [ 4 ] ;
2016-03-25 10:47:34 +01:00
outputs [ 0 ] = 2 ;
outputs [ 1 ] = 3 ;
outputs [ 2 ] = 4 ;
outputs [ 3 ] = 5 ;
2017-01-08 20:34:46 +01:00
this . crafter = new RecipeCrafter ( Reference . industrialElectrolyzerRecipe , this , 2 , 4 , this . inventory , inputs , outputs ) ;
2016-03-25 10:47:34 +01:00
}
@Override
2017-09-13 02:40:38 +02:00
public void update ( ) {
2017-09-15 23:50:43 +02:00
if ( this . world . isRemote ) { return ; }
2017-09-13 02:40:38 +02:00
super . update ( ) ;
2017-01-08 20:34:46 +01:00
this . charge ( 6 ) ;
2016-03-25 10:47:34 +01:00
}
@Override
2017-08-30 22:57:14 +02:00
public ItemStack getToolDrop ( final EntityPlayer entityPlayer ) {
2017-01-01 08:29:32 +01:00
return new ItemStack ( ModBlocks . INDUSTRIAL_ELECTROLYZER , 1 ) ;
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
public boolean isComplete ( ) {
2016-03-25 10:47:34 +01:00
return false ;
}
@Override
2017-01-08 20:34:46 +01:00
public void readFromNBT ( final NBTTagCompound tagCompound ) {
2016-03-25 10:47:34 +01:00
super . readFromNBT ( tagCompound ) ;
2017-01-08 20:34:46 +01:00
this . crafter . readFromNBT ( tagCompound ) ;
2016-03-25 10:47:34 +01:00
}
@Override
2017-01-08 20:34:46 +01:00
public NBTTagCompound writeToNBT ( final NBTTagCompound tagCompound ) {
2016-03-25 10:47:34 +01:00
super . writeToNBT ( tagCompound ) ;
2017-01-08 20:34:46 +01:00
this . crafter . writeToNBT ( tagCompound ) ;
2016-05-18 17:53:54 +02:00
return tagCompound ;
2016-03-25 10:47:34 +01:00
}
// @Override
// public void addWailaInfo(List<String> info)
// {
// super.addWailaInfo(info);
// info.add("Power Stored " + energy.getEnergyStored() +" EU");
// if(crafter.currentRecipe !=null){
// info.add("Power Usage " + crafter.currentRecipe.euPerTick() + " EU/t");
// }
// }
// ISidedInventory
@Override
2017-01-08 20:34:46 +01:00
public int [ ] getSlotsForFace ( final EnumFacing side ) {
2016-03-25 10:47:34 +01:00
return side = = EnumFacing . DOWN ? new int [ ] { 0 , 1 , 2 , 3 , 4 , 5 } : new int [ ] { 0 , 1 , 2 , 3 , 4 , 5 } ;
}
@Override
2017-02-03 16:57:34 +01:00
public boolean canInsertItem ( final int slotIndex , final ItemStack stack , final EnumFacing side ) {
if ( slotIndex > 1 )
2016-03-25 10:47:34 +01:00
return false ;
2017-06-09 04:12:58 +02:00
if ( slotIndex = = 1 )
2017-02-03 16:57:34 +01:00
return ItemUtils . isItemEqual ( stack , DynamicCell . getEmptyCell ( 1 ) , true , true ) ;
return ! ItemUtils . isItemEqual ( stack , DynamicCell . getEmptyCell ( 1 ) , true , true ) ;
2016-03-25 10:47:34 +01:00
}
@Override
2017-01-08 20:34:46 +01:00
public boolean canExtractItem ( final int slotIndex , final ItemStack itemStack , final EnumFacing side ) {
2016-03-25 10:47:34 +01:00
return slotIndex = = 2 | | slotIndex = = 3 | | slotIndex = = 4 | | slotIndex = = 5 ;
}
2017-01-08 20:34:46 +01:00
public int getProgressScaled ( final int scale ) {
if ( this . crafter . currentTickTime ! = 0 ) {
return this . crafter . currentTickTime * scale / this . crafter . currentNeededTicks ;
2016-03-25 10:47:34 +01:00
}
return 0 ;
}
@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
}
2016-04-11 18:43:54 +02:00
@Override
public Inventory getInventory ( ) {
2017-01-08 20:34:46 +01:00
return this . inventory ;
2016-04-11 18:43:54 +02:00
}
2016-04-11 18:50:00 +02:00
@Override
public RecipeCrafter getRecipeCrafter ( ) {
2017-01-08 20:34:46 +01:00
return this . crafter ;
}
@Override
public BuiltContainer createContainer ( final EntityPlayer player ) {
2017-09-13 02:40:38 +02:00
return new ContainerBuilder ( " industrialelectrolyzer " ) . player ( player . inventory ) . inventory ( ) . hotbar ( )
2017-06-09 04:12:58 +02:00
. addInventory ( ) . tile ( this )
2017-09-13 02:40:38 +02:00
. filterSlot ( 1 , 47 , 72 , stack - > ItemUtils . isItemEqual ( stack , DynamicCell . getEmptyCell ( 1 ) , true , true ) )
. filterSlot ( 0 , 81 , 72 , stack - > ! ItemUtils . isItemEqual ( stack , DynamicCell . getEmptyCell ( 1 ) , true , true ) )
. outputSlot ( 2 , 51 , 24 ) . outputSlot ( 3 , 71 , 24 ) . outputSlot ( 4 , 91 , 24 ) . outputSlot ( 5 , 111 , 24 )
2017-09-15 23:50:43 +02:00
. energySlot ( 6 , 8 , 72 ) . syncEnergyValue ( ) . syncCrafterValue ( ) . addInventory ( ) . create ( this ) ;
2016-04-11 18:50:00 +02:00
}
2015-05-09 20:13:43 +02:00
}