From 614c8e0ac4cd2ef5fc6c95590dd41103a842e9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sun, 10 Jul 2016 16:01:06 +0200 Subject: [PATCH] Trap blocks are no longer mixed in a single trap spot --- TODO.txt | 1 - src/java/mmm/materials/MMud.java | 7 ++++++ src/java/mmm/materials/MQuicksand.java | 7 ++++++ src/java/mmm/utils/I_UTrapBlock.java | 3 +++ src/java/mmm/utils/UTrapBlocks.java | 28 +++++++++++++++++++++ src/java/mmm/world/gen/WGTrapBlocks.java | 32 ++++++++++++++++++++++-- src/resources/assets/mmm/lang/en_US.lang | 1 + 7 files changed, 76 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index a671a8c..ced01fd 100644 --- a/TODO.txt +++ b/TODO.txt @@ -42,7 +42,6 @@ materials No Alloys materials No Metal from slag -> in metal recycler materials No Black sand URGENT -materials No Quicksand / quagmire URGENT materials No Metals Lead Aluminium diff --git a/src/java/mmm/materials/MMud.java b/src/java/mmm/materials/MMud.java index 48cb77f..9c0f2f0 100644 --- a/src/java/mmm/materials/MMud.java +++ b/src/java/mmm/materials/MMud.java @@ -44,6 +44,13 @@ public class MMud } + @Override + public String getTrapType( ) + { + return "slow"; + } + + @Override public AxisAlignedBB getCollisionBoundingBox( final IBlockState blockState , final World worldIn , final BlockPos pos ) diff --git a/src/java/mmm/materials/MQuicksand.java b/src/java/mmm/materials/MQuicksand.java index b565ecc..f7a8102 100644 --- a/src/java/mmm/materials/MQuicksand.java +++ b/src/java/mmm/materials/MQuicksand.java @@ -48,6 +48,13 @@ public class MQuicksand } + @Override + public String getTrapType( ) + { + return "quicksand"; + } + + @Override public MapColor getMapColor( IBlockState state ) { diff --git a/src/java/mmm/utils/I_UTrapBlock.java b/src/java/mmm/utils/I_UTrapBlock.java index a1481c5..d9e5064 100644 --- a/src/java/mmm/utils/I_UTrapBlock.java +++ b/src/java/mmm/utils/I_UTrapBlock.java @@ -8,6 +8,9 @@ import net.minecraft.block.state.IBlockState; public interface I_UTrapBlock { + public String getTrapType( ); + + public IBlockState[] getReplacedBlocks( ); } diff --git a/src/java/mmm/utils/UTrapBlocks.java b/src/java/mmm/utils/UTrapBlocks.java index 1344d3d..797e7d5 100644 --- a/src/java/mmm/utils/UTrapBlocks.java +++ b/src/java/mmm/utils/UTrapBlocks.java @@ -1,9 +1,12 @@ package mmm.utils; +import java.util.ArrayList; import java.util.List; import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.Lists; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -13,12 +16,16 @@ import net.minecraft.block.state.IBlockState; public enum UTrapBlocks { INSTANCE; + private final ArrayListMultimap< IBlockState , I_UTrapBlock > traps = ArrayListMultimap.create( ); private final ArrayListMultimap< IBlockState , IBlockState > replacements = ArrayListMultimap.create( ); + private final LinkedHashMultimap< IBlockState , String > trapTypes = LinkedHashMultimap.create( ); public void register( final I_UTrapBlock block ) { for ( IBlockState state : block.getReplacedBlocks( ) ) { + this.traps.put( state , block ); + this.trapTypes.put( state , block.getTrapType( ) ); this.replacements.put( state , ( (Block) block ).getDefaultState( ) ); } } @@ -29,4 +36,25 @@ public enum UTrapBlocks { return this.replacements.get( blockState ); } + + public List< IBlockState > getReplacements( final IBlockState blockState , final String trapType ) + { + ArrayList< IBlockState > out = Lists.newArrayList( ); + List< I_UTrapBlock > traps = this.traps.get( blockState ); + int nTraps = traps.size( ); + for ( int i = 0 ; i < nTraps ; i++ ) { + I_UTrapBlock trap = traps.get( i ); + if ( trap.getTrapType( ).equals( trapType ) ) { + out.add( ( (Block) trap ).getDefaultState( ) ); + } + } + return out; + } + + + public ArrayList< String > getTrapTypes( final IBlockState blockState ) + { + return Lists.newArrayList( this.trapTypes.get( blockState ) ); + } + } diff --git a/src/java/mmm/world/gen/WGTrapBlocks.java b/src/java/mmm/world/gen/WGTrapBlocks.java index 67d05b4..979c785 100644 --- a/src/java/mmm/world/gen/WGTrapBlocks.java +++ b/src/java/mmm/world/gen/WGTrapBlocks.java @@ -1,9 +1,12 @@ package mmm.world.gen; +import java.util.ArrayList; import java.util.List; import java.util.Random; +import com.google.common.collect.Lists; + import mmm.utils.UTrapBlocks; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -66,9 +69,34 @@ public class WGTrapBlocks check.setY( check.getY( ) - radius / 2 + rand.nextInt( radius ) ); } - // Replace blocks + // Find possible trap types BlockPos bp = new BlockPos( check ); int sqr = radius * radius; + ArrayList< String > types = Lists.newArrayList( ); + for ( int x = -radius ; x <= radius ; x++ ) { + for ( int y = -radius ; y <= radius ; y++ ) { + for ( int z = -radius ; z <= radius ; z++ ) { + if ( x * x + y * y + z * z > sqr + 1 ) { + continue; + } + + final BlockPos pos = bp.add( x , y , z ); + final IBlockState atPos = worldIn.getBlockState( pos ); + final List< String > trapTypes = UTrapBlocks.INSTANCE.getTrapTypes( atPos ); + for ( String rep : trapTypes ) { + if ( !types.contains( rep ) ) { + types.add( rep ); + } + } + } + } + } + if ( types.isEmpty( ) ) { + return false; + } + + String trapType = types.get( rand.nextInt( types.size( ) ) ); + System.err.println( "Trap at " + bp + " -> " + trapType ); for ( int x = -radius ; x <= radius ; x++ ) { for ( int y = -radius ; y <= radius ; y++ ) { for ( int z = -radius ; z <= radius ; z++ ) { @@ -78,7 +106,7 @@ public class WGTrapBlocks final BlockPos pos = bp.add( x , y , z ); final IBlockState atPos = worldIn.getBlockState( pos ); - final List< IBlockState > replacements = UTrapBlocks.INSTANCE.getReplacements( atPos ); + final List< IBlockState > replacements = UTrapBlocks.INSTANCE.getReplacements( atPos , trapType ); final int nReplacements = replacements.size( ); if ( nReplacements == 0 ) { continue; diff --git a/src/resources/assets/mmm/lang/en_US.lang b/src/resources/assets/mmm/lang/en_US.lang index cfc6043..105e1e8 100644 --- a/src/resources/assets/mmm/lang/en_US.lang +++ b/src/resources/assets/mmm/lang/en_US.lang @@ -77,6 +77,7 @@ tile.mmm.materials.planks.bamboo.name=Bamboo Wood Planks tile.mmm.materials.trap.sand.name=Quicksand tile.mmm.materials.trap.red_sand.name=Red Quicksand tile.mmm.materials.trap.mud.name=Mud +tile.mmm.materials.trap.swamp_pit.name=Silty Quicksand tile.mmm.tech.base.alloy_furnace.inactive.name=Alloy Furnace