Trap blocks are no longer mixed in a single trap spot
This commit is contained in:
parent
7ba899b576
commit
614c8e0ac4
7 changed files with 76 additions and 3 deletions
1
TODO.txt
1
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
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -48,6 +48,13 @@ public class MQuicksand
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTrapType( )
|
||||
{
|
||||
return "quicksand";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MapColor getMapColor( IBlockState state )
|
||||
{
|
||||
|
|
|
@ -8,6 +8,9 @@ import net.minecraft.block.state.IBlockState;
|
|||
public interface I_UTrapBlock
|
||||
{
|
||||
|
||||
public String getTrapType( );
|
||||
|
||||
|
||||
public IBlockState[] getReplacedBlocks( );
|
||||
|
||||
}
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue