From 99f1736614378dc74c997d0fda0a5cfce9f59686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 24 Jun 2016 09:39:03 +0200 Subject: [PATCH] Alloy furnace - Basic hoppers --- TODO.txt | 3 +- .../tech/base/TBAlloyFurnaceTileEntity.java | 46 +++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/TODO.txt b/TODO.txt index 2daa507..45a4a36 100644 --- a/TODO.txt +++ b/TODO.txt @@ -41,11 +41,12 @@ materials.ores No Tin materials.ores No Zinc ------------------------------------------------------------------------------------------------------- tech.base No Alloy furnace - -> support hoppers -> comparator output -> search recipe + -> crafting recipe -> I18n -> XP + -> let output hoppers take empty buckets / invalid input -> code clean-up tech.base No Coke oven ------------------------------------------------------------------------------------------------------- diff --git a/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java b/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java index c7e8abf..ecd0efe 100644 --- a/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java +++ b/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java @@ -11,9 +11,14 @@ import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.Constants.NBT; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.InvWrapper; @@ -33,6 +38,10 @@ public class TBAlloyFurnaceTileEntity private int burnCurrent; private int burnTotal; + private final IItemHandler inputHopper; + private final IItemHandler fuelHopper; + private final IItemHandler outputHopper; + public TBAlloyFurnaceTileEntity( ) { @@ -40,6 +49,10 @@ public class TBAlloyFurnaceTileEntity this.fuel = new UInventoryGrid( "Fuel" , 2 , 2 ); this.output = new UInventoryGrid( "Output" , 2 , 5 ); this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 ); + + this.inputHopper = new InvWrapper( this.input ); + this.fuelHopper = new InvWrapper( this.fuel ); + this.outputHopper = new InvWrapper( this.output ); } @@ -127,7 +140,7 @@ public class TBAlloyFurnaceTileEntity if ( this.burnCurrent == 0 ) { if ( this.alloying != null ) { if ( !this.startBurning( this.alloyCurrent ) ) { - cancelAlloying( ); + this.cancelAlloying( ); this.burnCurrent = this.burnTotal = 0; } } else { @@ -152,6 +165,31 @@ public class TBAlloyFurnaceTileEntity } + @Override + public boolean hasCapability( final Capability< ? > capability , final EnumFacing facing ) + { + return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && facing != null + || super.hasCapability( capability , facing ); + } + + + @SuppressWarnings( "unchecked" ) + @Override + public < T > T getCapability( final Capability< T > capability , final EnumFacing facing ) + { + if ( facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ) { + if ( facing == EnumFacing.DOWN ) { + return (T) this.outputHopper; + } else if ( facing == EnumFacing.UP ) { + return (T) this.inputHopper; + } else { + return (T) this.fuelHopper; + } + } + return super.getCapability( capability , facing ); + } + + public void cancelAlloying( ) { if ( this.alloying != null ) { @@ -188,7 +226,7 @@ public class TBAlloyFurnaceTileEntity } - public int getBurnProgress( int max ) + public int getBurnProgress( final int max ) { int t = this.burnTotal; if ( t == 0 ) { @@ -286,7 +324,7 @@ public class TBAlloyFurnaceTileEntity } - public int getAlloyingProgress( int max ) + public int getAlloyingProgress( final int max ) { if ( this.alloying == null ) { return max; @@ -337,7 +375,7 @@ public class TBAlloyFurnaceTileEntity } - private void addOutput( ItemStack wanted ) + private void addOutput( final ItemStack wanted ) { final int maxStackSize = Math.min( this.output.getInventoryStackLimit( ) , wanted.getMaxStackSize( ) ); int added = 0;