From 88676c015e513bd3194dae0975a40e0b681f2760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sun, 19 Jun 2016 10:52:38 +0200 Subject: [PATCH] Started work on alloy furnace --- src/java/mmm/proxy/PCommon.java | 4 +- src/java/mmm/tech/Tech.java | 22 ++ .../mmm/tech/base/TBAlloyFurnaceBlock.java | 231 ++++++++++++++++++ .../tech/base/TBAlloyFurnaceTileEntity.java | 12 + src/java/mmm/tech/base/TechBase.java | 35 +++ .../tech/tools/{Tools.java => TechTools.java} | 2 +- 6 files changed, 303 insertions(+), 3 deletions(-) create mode 100644 src/java/mmm/tech/Tech.java create mode 100644 src/java/mmm/tech/base/TBAlloyFurnaceBlock.java create mode 100644 src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java create mode 100644 src/java/mmm/tech/base/TechBase.java rename src/java/mmm/tech/tools/{Tools.java => TechTools.java} (95%) diff --git a/src/java/mmm/proxy/PCommon.java b/src/java/mmm/proxy/PCommon.java index 771fe50..605bc51 100644 --- a/src/java/mmm/proxy/PCommon.java +++ b/src/java/mmm/proxy/PCommon.java @@ -5,7 +5,7 @@ import mmm.Mmm; import mmm.deco.DecorativeBlocks; import mmm.food.Food; import mmm.materials.Materials; -import mmm.tech.tools.Tools; +import mmm.tech.Tech; import mmm.utils.UAccessors; import mmm.utils.URegistry; import mmm.utils.USeat; @@ -23,7 +23,7 @@ public abstract class PCommon UAccessors.preInit( ); Materials.preInit( ); - Tools.preInit( ); + Tech.preInit( ); Food.preInit( ); DecorativeBlocks.preInit( ); diff --git a/src/java/mmm/tech/Tech.java b/src/java/mmm/tech/Tech.java new file mode 100644 index 0000000..8621b25 --- /dev/null +++ b/src/java/mmm/tech/Tech.java @@ -0,0 +1,22 @@ +package mmm.tech; + + +import mmm.tech.base.TechBase; +import mmm.tech.tools.TechTools; + + + +public class Tech +{ + static { + TechBase.preInit( ); + TechTools.preInit( ); + } + + + public static void preInit( ) + { + // EMPTY + } + +} diff --git a/src/java/mmm/tech/base/TBAlloyFurnaceBlock.java b/src/java/mmm/tech/base/TBAlloyFurnaceBlock.java new file mode 100644 index 0000000..2f3a342 --- /dev/null +++ b/src/java/mmm/tech/base/TBAlloyFurnaceBlock.java @@ -0,0 +1,231 @@ +package mmm.tech.base; + + +import java.util.Random; + +import javax.annotation.Nullable; + +import mmm.utils.I_USupportBlock; +import mmm.utils.URegistry; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.BlockHorizontal; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyDirection; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.Mirror; +import net.minecraft.util.Rotation; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + + + +public class TBAlloyFurnaceBlock + extends BlockContainer +{ + public static final PropertyDirection FACING = BlockHorizontal.FACING; + + public final boolean active; + + + public TBAlloyFurnaceBlock( final boolean active ) + { + super( Material.ROCK ); + this.active = active; + this.setCreativeTab( CreativeTabs.DECORATIONS ); + this.setResistance( 17.5f ); + this.setHardness( 3.5f ); + this.setHarvestLevel( "pickaxe" , 0 ); + URegistry.setIdentifiers( this , "tech" , "base" , "alloy_furnace" , active ? "active" : "inactive" ); + } + + + // ************************************************************************************************* + // TILE ENTITY + // ************************************************************************************************* + + @Override + public TileEntity createNewTileEntity( final World worldIn , final int meta ) + { + return new TBAlloyFurnaceTileEntity( ); + } + + + // ************************************************************************************************* + // RENDERING + // ************************************************************************************************* + + @Override + public boolean isOpaqueCube( final IBlockState state ) + { + return false; + } + + + @Override + public boolean isFullCube( final IBlockState state ) + { + return false; + } + + + @Override + @SideOnly( Side.CLIENT ) + public BlockRenderLayer getBlockLayer( ) + { + return BlockRenderLayer.CUTOUT; + } + + + @Override + @SideOnly( Side.CLIENT ) + public void randomDisplayTick( final IBlockState stateIn , final World worldIn , final BlockPos pos , + final Random rand ) + { + // XXX stolen from Blocks.FURNACE, will need adjustments (e.g. positions) + if ( this.active ) { + final EnumFacing enumfacing = stateIn.getValue( TBAlloyFurnaceBlock.FACING ); + final double d0 = pos.getX( ) + 0.5D; + final double d1 = pos.getY( ) + rand.nextDouble( ) * 6.0D / 16.0D; + final double d2 = pos.getZ( ) + 0.5D; + final double d3 = 0.52D; + final double d4 = rand.nextDouble( ) * 0.6D - 0.3D; + + if ( rand.nextDouble( ) < 0.1D ) { + worldIn.playSound( pos.getX( ) + 0.5D , pos.getY( ) , pos.getZ( ) + 0.5D , + SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE , SoundCategory.BLOCKS , 1.0F , 1.0F , false ); + } + + switch ( enumfacing ) { + case WEST: + worldIn.spawnParticle( EnumParticleTypes.SMOKE_NORMAL , d0 - d3 , d1 , d2 + d4 , 0.0D , 0.0D , + 0.0D , new int[ 0 ] ); + worldIn.spawnParticle( EnumParticleTypes.FLAME , d0 - d3 , d1 , d2 + d4 , 0.0D , 0.0D , 0.0D , + new int[ 0 ] ); + break; + case EAST: + worldIn.spawnParticle( EnumParticleTypes.SMOKE_NORMAL , d0 + d3 , d1 , d2 + d4 , 0.0D , 0.0D , + 0.0D , new int[ 0 ] ); + worldIn.spawnParticle( EnumParticleTypes.FLAME , d0 + d3 , d1 , d2 + d4 , 0.0D , 0.0D , 0.0D , + new int[ 0 ] ); + break; + case NORTH: + worldIn.spawnParticle( EnumParticleTypes.SMOKE_NORMAL , d0 + d4 , d1 , d2 - d3 , 0.0D , 0.0D , + 0.0D , new int[ 0 ] ); + worldIn.spawnParticle( EnumParticleTypes.FLAME , d0 + d4 , d1 , d2 - d3 , 0.0D , 0.0D , 0.0D , + new int[ 0 ] ); + break; + case SOUTH: + worldIn.spawnParticle( EnumParticleTypes.SMOKE_NORMAL , d0 + d4 , d1 , d2 + d3 , 0.0D , 0.0D , + 0.0D , new int[ 0 ] ); + worldIn.spawnParticle( EnumParticleTypes.FLAME , d0 + d4 , d1 , d2 + d3 , 0.0D , 0.0D , 0.0D , + new int[ 0 ] ); + break; + default: + break; + } + } + } + + + // ************************************************************************************************* + // ITEM + // ************************************************************************************************* + + @Override + @Nullable + public Item getItemDropped( final IBlockState state , final Random rand , final int fortune ) + { + return TechBase.ALLOY_FURNACE_ITEM; + } + + + // ************************************************************************************************* + // DIRECTION + // ************************************************************************************************* + + @Override + protected BlockStateContainer createBlockState( ) + { + return new BlockStateContainer( this , new IProperty[] { + TBAlloyFurnaceBlock.FACING + } ); + } + + + @Override + public IBlockState getStateFromMeta( final int meta ) + { + EnumFacing enumfacing = EnumFacing.getFront( meta ); + + if ( enumfacing.getAxis( ) == EnumFacing.Axis.Y ) { + enumfacing = EnumFacing.NORTH; + } + + return this.getDefaultState( ).withProperty( TBAlloyFurnaceBlock.FACING , enumfacing ); + } + + + @Override + public int getMetaFromState( final IBlockState state ) + { + return state.getValue( TBAlloyFurnaceBlock.FACING ).getIndex( ); + } + + + @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 ) + { + return this.getDefaultState( ).withProperty( TBAlloyFurnaceBlock.FACING , + placer.getHorizontalFacing( ).getOpposite( ) ); + } + + + @Override + public IBlockState withRotation( final IBlockState state , final Rotation rot ) + { + return state.withProperty( TBAlloyFurnaceBlock.FACING , + rot.rotate( state.getValue( TBAlloyFurnaceBlock.FACING ) ) ); + } + + + @Override + public IBlockState withMirror( final IBlockState state , final Mirror mirrorIn ) + { + return state.withRotation( mirrorIn.toRotation( state.getValue( TBAlloyFurnaceBlock.FACING ) ) ); + } + + + // ************************************************************************************************* + // SUPPORT REQUIREMENT + // ************************************************************************************************* + + @Override + public void neighborChanged( final IBlockState state , final World worldIn , final BlockPos pos , + final Block blockIn ) + { + I_USupportBlock.dropIfUnsupported( state , worldIn , pos , this ); + } + + + @Override + public boolean canPlaceBlockAt( final World worldIn , final BlockPos pos ) + { + return super.canPlaceBlockAt( worldIn , pos ) && I_USupportBlock.check( worldIn , pos ); + } + +} diff --git a/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java b/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java new file mode 100644 index 0000000..c716a2a --- /dev/null +++ b/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java @@ -0,0 +1,12 @@ +package mmm.tech.base; + + +import net.minecraft.tileentity.TileEntity; + + + +public class TBAlloyFurnaceTileEntity + extends TileEntity +{ + +} diff --git a/src/java/mmm/tech/base/TechBase.java b/src/java/mmm/tech/base/TechBase.java new file mode 100644 index 0000000..aa023a2 --- /dev/null +++ b/src/java/mmm/tech/base/TechBase.java @@ -0,0 +1,35 @@ +package mmm.tech.base; + + +import mmm.utils.URegistry; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlockSpecial; +import net.minecraftforge.fml.common.registry.GameRegistry; + + + +public class TechBase +{ + public static final TBAlloyFurnaceBlock ALLOY_FURNACE_BLOCK_INACTIVE; + public static final TBAlloyFurnaceBlock ALLOY_FURNACE_BLOCK_ACTIVE; + public static final Item ALLOY_FURNACE_ITEM; + + static { + ALLOY_FURNACE_BLOCK_INACTIVE = new TBAlloyFurnaceBlock( false ); + ALLOY_FURNACE_BLOCK_ACTIVE = new TBAlloyFurnaceBlock( true ); + ALLOY_FURNACE_ITEM = new ItemBlockSpecial( TechBase.ALLOY_FURNACE_BLOCK_INACTIVE )// + .setMaxStackSize( 16 )// + .setCreativeTab( ALLOY_FURNACE_BLOCK_INACTIVE.getCreativeTabToDisplayOn( ) ); + URegistry.setIdentifiers( ALLOY_FURNACE_ITEM , "tech" , "base" , "alloy_furnace" ); + URegistry.addBlock( TechBase.ALLOY_FURNACE_BLOCK_INACTIVE , TechBase.ALLOY_FURNACE_ITEM ); + URegistry.addBlock( TechBase.ALLOY_FURNACE_BLOCK_ACTIVE , null ); + GameRegistry.registerTileEntity( TBAlloyFurnaceTileEntity.class , "mmm:tech/base/alloy_furnace" ); + } + + + public static void preInit( ) + { + // EMPTY + } + +} diff --git a/src/java/mmm/tech/tools/Tools.java b/src/java/mmm/tech/tools/TechTools.java similarity index 95% rename from src/java/mmm/tech/tools/Tools.java rename to src/java/mmm/tech/tools/TechTools.java index 7f7bd96..b3c202f 100644 --- a/src/java/mmm/tech/tools/Tools.java +++ b/src/java/mmm/tech/tools/TechTools.java @@ -6,7 +6,7 @@ import net.minecraft.init.SoundEvents; -public class Tools +public class TechTools { public static final TTToolSet COPPER_TOOLS; public static final TTArmorSet COPPER_ARMOR;