Fixed blocks state <-> meta conversion (#31)
-Added missing state <-> meta conversion methods to blocks. Fixes #23.
This commit is contained in:
parent
2208083b03
commit
8ddff3f459
|
@ -67,7 +67,7 @@ import appeng.util.Platform;
|
||||||
public abstract class AEBaseBlock extends Block implements IAEFeature
|
public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final PropertyEnum AXIS_ORIENTATION = PropertyEnum.create( "axis", EnumFacing.Axis.class );
|
public static final PropertyEnum<EnumFacing.Axis> AXIS_ORIENTATION = PropertyEnum.create( "axis", EnumFacing.Axis.class );
|
||||||
|
|
||||||
private final String featureFullName;
|
private final String featureFullName;
|
||||||
private final Optional<String> featureSubName;
|
private final Optional<String> featureSubName;
|
||||||
|
|
|
@ -25,9 +25,9 @@ import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockTorch;
|
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.properties.IProperty;
|
import net.minecraft.block.properties.IProperty;
|
||||||
|
import net.minecraft.block.properties.PropertyDirection;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
@ -52,10 +52,15 @@ import appeng.helpers.MetaRotation;
|
||||||
|
|
||||||
public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, ICustomCollision
|
public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, ICustomCollision
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Cannot use the vanilla FACING property here because it excludes facing DOWN
|
||||||
|
public static final PropertyDirection FACING = PropertyDirection.create("facing");
|
||||||
|
|
||||||
public BlockQuartzTorch()
|
public BlockQuartzTorch()
|
||||||
{
|
{
|
||||||
super( Material.CIRCUITS );
|
super( Material.CIRCUITS );
|
||||||
|
|
||||||
|
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.UP));
|
||||||
this.setFeature( EnumSet.of( AEFeature.DecorativeLights ) );
|
this.setFeature( EnumSet.of( AEFeature.DecorativeLights ) );
|
||||||
this.setLightLevel( 0.9375F );
|
this.setLightLevel( 0.9375F );
|
||||||
this.setLightOpacity( 0 );
|
this.setLightOpacity( 0 );
|
||||||
|
@ -66,19 +71,20 @@ public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, I
|
||||||
@Override
|
@Override
|
||||||
public int getMetaFromState( final IBlockState state )
|
public int getMetaFromState( final IBlockState state )
|
||||||
{
|
{
|
||||||
return 0;
|
return state.getValue(FACING).ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBlockState getStateFromMeta( final int meta )
|
public IBlockState getStateFromMeta( final int meta )
|
||||||
{
|
{
|
||||||
return this.getDefaultState();
|
EnumFacing facing = EnumFacing.values()[meta];
|
||||||
|
return getDefaultState().withProperty(FACING, facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IProperty[] getAEStates()
|
protected IProperty[] getAEStates()
|
||||||
{
|
{
|
||||||
return new IProperty[] { BlockTorch.FACING };
|
return new IProperty[] { FACING };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -180,6 +186,6 @@ public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, I
|
||||||
@Override
|
@Override
|
||||||
public IOrientable getOrientable( final IBlockAccess w, final BlockPos pos )
|
public IOrientable getOrientable( final IBlockAccess w, final BlockPos pos )
|
||||||
{
|
{
|
||||||
return new MetaRotation( w, pos, true );
|
return new MetaRotation( w, pos, FACING );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.EnumSet;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.properties.IProperty;
|
import net.minecraft.block.properties.IProperty;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
|
||||||
|
@ -34,7 +35,6 @@ import appeng.core.features.AEFeature;
|
||||||
import appeng.helpers.MetaRotation;
|
import appeng.helpers.MetaRotation;
|
||||||
|
|
||||||
|
|
||||||
// TODO Quartz Rotation.
|
|
||||||
public class QuartzPillarBlock extends AEBaseBlock implements IOrientableBlock
|
public class QuartzPillarBlock extends AEBaseBlock implements IOrientableBlock
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -47,13 +47,15 @@ public class QuartzPillarBlock extends AEBaseBlock implements IOrientableBlock
|
||||||
@Override
|
@Override
|
||||||
public int getMetaFromState( final IBlockState state )
|
public int getMetaFromState( final IBlockState state )
|
||||||
{
|
{
|
||||||
return 0;
|
return state.getValue(AXIS_ORIENTATION).ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBlockState getStateFromMeta( final int meta )
|
public IBlockState getStateFromMeta( final int meta )
|
||||||
{
|
{
|
||||||
return this.getDefaultState();
|
// Simply use the ordinal here
|
||||||
|
EnumFacing.Axis axis = EnumFacing.Axis.values()[meta];
|
||||||
|
return this.getDefaultState().withProperty(AXIS_ORIENTATION, axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,7 +73,7 @@ public class QuartzPillarBlock extends AEBaseBlock implements IOrientableBlock
|
||||||
@Override
|
@Override
|
||||||
public IOrientable getOrientable( final IBlockAccess w, final BlockPos pos )
|
public IOrientable getOrientable( final IBlockAccess w, final BlockPos pos )
|
||||||
{
|
{
|
||||||
return new MetaRotation( w, pos, false );
|
return new MetaRotation( w, pos, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
package appeng.helpers;
|
package appeng.helpers;
|
||||||
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockTorch;
|
import net.minecraft.block.properties.IProperty;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumFacing.Axis;
|
import net.minecraft.util.EnumFacing.Axis;
|
||||||
|
@ -34,15 +34,15 @@ import appeng.block.AEBaseBlock;
|
||||||
public class MetaRotation implements IOrientable
|
public class MetaRotation implements IOrientable
|
||||||
{
|
{
|
||||||
|
|
||||||
private final boolean useFacing;
|
private final IProperty<EnumFacing> facingProp;
|
||||||
private final IBlockAccess w;
|
private final IBlockAccess w;
|
||||||
private final BlockPos pos;
|
private final BlockPos pos;
|
||||||
|
|
||||||
public MetaRotation( final IBlockAccess world, final BlockPos pos, final boolean FullFacing )
|
public MetaRotation( final IBlockAccess world, final BlockPos pos, final IProperty<EnumFacing> facingProp )
|
||||||
{
|
{
|
||||||
this.w = world;
|
this.w = world;
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.useFacing = FullFacing;
|
this.facingProp = facingProp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,13 +66,12 @@ public class MetaRotation implements IOrientable
|
||||||
{
|
{
|
||||||
final IBlockState state = this.w.getBlockState( this.pos );
|
final IBlockState state = this.w.getBlockState( this.pos );
|
||||||
|
|
||||||
if( this.useFacing )
|
if( this.facingProp != null )
|
||||||
{
|
{
|
||||||
final EnumFacing f = state == null ? EnumFacing.UP : (EnumFacing) state.getValue( BlockTorch.FACING );
|
return state.getValue( facingProp );
|
||||||
return f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Axis a = state == null ? null : (Axis) state.getValue( AEBaseBlock.AXIS_ORIENTATION );
|
Axis a = state.getValue( AEBaseBlock.AXIS_ORIENTATION );
|
||||||
|
|
||||||
if( a == null )
|
if( a == null )
|
||||||
{
|
{
|
||||||
|
@ -96,9 +95,9 @@ public class MetaRotation implements IOrientable
|
||||||
{
|
{
|
||||||
if( this.w instanceof World )
|
if( this.w instanceof World )
|
||||||
{
|
{
|
||||||
if( this.useFacing )
|
if( facingProp != null )
|
||||||
{
|
{
|
||||||
( (World) this.w ).setBlockState( this.pos, this.w.getBlockState( this.pos ).withProperty( BlockTorch.FACING, up ) );
|
( (World) this.w ).setBlockState( this.pos, this.w.getBlockState( this.pos ).withProperty( facingProp, up ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue