From fa79a85fd966cb2e046b415738062c0ebf8c2e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 29 Jun 2016 11:49:44 +0200 Subject: [PATCH] Alloy furnace - Preserve custom name when removed ... And that should be all for the fucking alloy furnace. Nice (if true). --- TODO.txt | 2 -- .../tech/base/alloy_furnace/AlloyFurnace.java | 4 +-- .../tech/base/alloy_furnace/TBAFBlock.java | 32 +++++++++++++++++++ .../base/alloy_furnace/TBAFTileEntity.java | 32 ++++++++++++++++++- src/resources/assets/mmm/lang/en_US.lang | 2 +- 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/TODO.txt b/TODO.txt index ab992ef..3aa6569 100644 --- a/TODO.txt +++ b/TODO.txt @@ -43,8 +43,6 @@ materials.ores No Rock salt materials.ores No Tin materials.ores No Zinc ------------------------------------------------------------------------------------------------------- -tech.base No Alloy furnace - -> check item behaviour tech.base No Coke oven ------------------------------------------------------------------------------------------------------- animals ??? Goats diff --git a/src/java/mmm/tech/base/alloy_furnace/AlloyFurnace.java b/src/java/mmm/tech/base/alloy_furnace/AlloyFurnace.java index 256b0a5..49eeaee 100644 --- a/src/java/mmm/tech/base/alloy_furnace/AlloyFurnace.java +++ b/src/java/mmm/tech/base/alloy_furnace/AlloyFurnace.java @@ -5,7 +5,7 @@ import mmm.utils.UNetwork; import mmm.utils.URegistry; import mmm.utils.gui.GUIUtils; import net.minecraft.item.Item; -import net.minecraft.item.ItemBlockSpecial; +import net.minecraft.item.ItemBlock; import net.minecraftforge.fml.common.registry.GameRegistry; @@ -24,7 +24,7 @@ public enum AlloyFurnace { this.INACTIVE = new TBAFBlock( false ); this.ACTIVE = new TBAFBlock( true ); - this.ITEM = new ItemBlockSpecial( this.INACTIVE )// + this.ITEM = new ItemBlock( this.INACTIVE )// .setMaxStackSize( 16 )// .setCreativeTab( this.INACTIVE.getCreativeTabToDisplayOn( ) ); URegistry.setIdentifiers( this.ITEM , "tech" , "base" , "alloy_furnace" ); diff --git a/src/java/mmm/tech/base/alloy_furnace/TBAFBlock.java b/src/java/mmm/tech/base/alloy_furnace/TBAFBlock.java index 4c2c33c..f3839e3 100644 --- a/src/java/mmm/tech/base/alloy_furnace/TBAFBlock.java +++ b/src/java/mmm/tech/base/alloy_furnace/TBAFBlock.java @@ -1,6 +1,7 @@ package mmm.tech.base.alloy_furnace; +import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -267,6 +268,14 @@ public class TBAFBlock } + @Override + public List< ItemStack > getDrops( final IBlockAccess world , final BlockPos pos , final IBlockState state , + final int fortune ) + { + return new ArrayList< ItemStack >( ); + } + + // ************************************************************************************************* // DIRECTION // ************************************************************************************************* @@ -304,6 +313,23 @@ public class TBAFBlock } + @Override + public void onBlockPlacedBy( final World worldIn , final BlockPos pos , final IBlockState state , + final EntityLivingBase placer , final ItemStack stack ) + { + worldIn.setBlockState( pos , state.withProperty( // + TBAFBlock.FACING , placer.getHorizontalFacing( ).getOpposite( ) ) , 2 ); + + if ( stack.hasDisplayName( ) ) { + System.err.println( "HAZ A NAME!" ); + final TileEntity tileentity = worldIn.getTileEntity( pos ); + if ( tileentity instanceof TBAFTileEntity ) { + ( (TBAFTileEntity) tileentity ).setCustomName( stack.getDisplayName( ) ); + } + } + } + + @Override public IBlockState onBlockPlaced( final World worldIn , final BlockPos pos , final EnumFacing facing , final float hitX , final float hitY , final float hitZ , final int meta , final EntityLivingBase placer ) @@ -368,6 +394,12 @@ public class TBAFBlock InventoryHelper.dropInventoryItems( worldIn , pos , afte.input ); InventoryHelper.dropInventoryItems( worldIn , pos , afte.fuel ); InventoryHelper.dropInventoryItems( worldIn , pos , afte.output ); + + final ItemStack stack = new ItemStack( AlloyFurnace.INSTANCE.ITEM , 1 ); + if ( afte.hasCustomName( ) ) { + stack.setStackDisplayName( afte.getName( ) ); + } + InventoryHelper.spawnItemStack( worldIn , pos.getX( ) , pos.getY( ) , pos.getZ( ) , stack ); } worldIn.updateComparatorOutputLevel( pos , this ); } diff --git a/src/java/mmm/tech/base/alloy_furnace/TBAFTileEntity.java b/src/java/mmm/tech/base/alloy_furnace/TBAFTileEntity.java index 3322733..b5af8cb 100644 --- a/src/java/mmm/tech/base/alloy_furnace/TBAFTileEntity.java +++ b/src/java/mmm/tech/base/alloy_furnace/TBAFTileEntity.java @@ -19,6 +19,7 @@ import net.minecraft.util.ITickable; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.world.IWorldNameable; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.Constants.NBT; @@ -30,7 +31,7 @@ import net.minecraftforge.items.wrapper.InvWrapper; public class TBAFTileEntity extends TileEntity - implements ITickable , I_TBConfigurableActivation + implements ITickable , I_TBConfigurableActivation , IWorldNameable { /** Input hopper allows invalid input? */ public static final int F_IH_INVALID = 1 << 0; @@ -91,6 +92,8 @@ public class TBAFTileEntity public final UInventoryGrid fuel; public final UInventoryGrid output; + private String customName; + public MAlloyRecipe recipe; private MAlloyRecipe alloying; @@ -122,6 +125,26 @@ public class TBAFTileEntity } + @Override + public String getName( ) + { + return this.hasCustomName( ) ? this.customName : "tile.mmm.tech.base.alloy_furnace.inactive.name"; + } + + + @Override + public boolean hasCustomName( ) + { + return this.customName != null && !this.customName.isEmpty( ); + } + + + public void setCustomName( final String name ) + { + this.customName = name; + } + + @Override public boolean shouldRefresh( final World world , final BlockPos pos , final IBlockState oldState , final IBlockState newSate ) @@ -134,6 +157,9 @@ public class TBAFTileEntity public void readFromNBT( final NBTTagCompound compound ) { super.readFromNBT( compound ); + if ( compound.hasKey( "CustomName" , 8 ) ) { + this.customName = compound.getString( "CustomName" ); + } this.input.deserializeNBT( compound.getTagList( "Input" , NBT.TAG_COMPOUND ) ); this.fuel.deserializeNBT( compound.getTagList( "Fuel" , NBT.TAG_COMPOUND ) ); this.output.deserializeNBT( compound.getTagList( "Output" , NBT.TAG_COMPOUND ) ); @@ -145,6 +171,9 @@ public class TBAFTileEntity public NBTTagCompound writeToNBT( final NBTTagCompound compound ) { super.writeToNBT( compound ); + if ( this.hasCustomName( ) ) { + compound.setString( "CustomName" , this.customName ); + } compound.setTag( "Input" , this.input.serializeNBT( ) ); compound.setTag( "Fuel" , this.fuel.serializeNBT( ) ); compound.setTag( "Output" , this.output.serializeNBT( ) ); @@ -650,4 +679,5 @@ public class TBAFTileEntity final float ratio = total / ( 15.0f * nValues ); return MathHelper.floor_float( ratio * 14.0f ) + ( total == 0 ? 0 : 1 ); } + } diff --git a/src/resources/assets/mmm/lang/en_US.lang b/src/resources/assets/mmm/lang/en_US.lang index b8cfbca..a0e5426 100644 --- a/src/resources/assets/mmm/lang/en_US.lang +++ b/src/resources/assets/mmm/lang/en_US.lang @@ -22,7 +22,7 @@ gui.mmm.tech.base.am.powered=Redstone Activates gui.mmm.tech.base.am.unpowered=Redstone Disables gui.mmm.tech.base.am.disabled=Deactivated -item.mmm.tech.base.alloy_furnace.name=Alloy Furnace +tile.mmm.tech.base.alloy_furnace.inactive.name=Alloy Furnace container.mmm.alloy_furnace.contents=Furnace Contents container.mmm.alloy_furnace.recipe=Alloy Selection container.mmm.alloy_furnace.select=Select Alloy