Applied-Energistics-2-tiler.../src/main/java/appeng/helpers/MetaRotation.java

116 lines
2.8 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
2015-05-18 00:33:04 +02:00
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
2014-11-14 12:02:52 +01:00
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
2014-09-24 02:26:27 +02:00
package appeng.helpers;
import net.minecraft.block.properties.IProperty;
2015-06-16 02:44:59 +02:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.math.BlockPos;
2014-09-24 02:26:27 +02:00
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
2015-12-24 02:07:03 +01:00
2014-09-24 02:26:27 +02:00
import appeng.api.util.IOrientable;
2015-06-16 02:44:59 +02:00
import appeng.block.AEBaseBlock;
import appeng.decorative.solid.BlockQuartzPillar;
2014-09-24 02:26:27 +02:00
2014-09-24 02:26:27 +02:00
public class MetaRotation implements IOrientable
{
private final IProperty<EnumFacing> facingProp;
private final IBlockAccess w;
private final BlockPos pos;
2014-09-24 02:26:27 +02:00
public MetaRotation( final IBlockAccess world, final BlockPos pos, final IProperty<EnumFacing> facingProp )
{
2014-12-29 15:13:47 +01:00
this.w = world;
2015-06-16 02:44:59 +02:00
this.pos = pos;
this.facingProp = facingProp;
2014-09-24 02:26:27 +02:00
}
@Override
public boolean canBeRotated()
2014-09-24 02:26:27 +02:00
{
return true;
2014-09-24 02:26:27 +02:00
}
@Override
2015-06-16 02:44:59 +02:00
public EnumFacing getForward()
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
if( this.getUp().getFrontOffsetY() == 0 )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
return EnumFacing.UP;
2015-04-29 02:30:53 +02:00
}
2015-06-16 02:44:59 +02:00
return EnumFacing.SOUTH;
2014-09-24 02:26:27 +02:00
}
@Override
2015-06-16 02:44:59 +02:00
public EnumFacing getUp()
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:26:54 +02:00
final IBlockState state = this.w.getBlockState( this.pos );
if( this.facingProp != null )
2015-06-16 02:44:59 +02:00
{
return state.getValue( facingProp );
2015-06-16 02:44:59 +02:00
}
//TODO 1.10.2-R - Temp
Axis a = state.getValue( BlockQuartzPillar.AXIS_ORIENTATION );
if( a == null )
2015-12-24 02:11:17 +01:00
{
2015-06-16 02:44:59 +02:00
a = Axis.Y;
2015-12-24 02:11:17 +01:00
}
2015-06-16 02:44:59 +02:00
switch( a )
{
case X:
return EnumFacing.EAST;
case Z:
return EnumFacing.SOUTH;
default:
case Y:
return EnumFacing.UP;
}
2014-09-24 02:26:27 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public void setOrientation( final EnumFacing forward, final EnumFacing up )
2014-09-24 02:26:27 +02:00
{
if( this.w instanceof World )
2015-04-29 02:30:53 +02:00
{
if( facingProp != null )
2015-12-24 02:11:17 +01:00
{
( (World) this.w ).setBlockState( this.pos, this.w.getBlockState( this.pos ).withProperty( facingProp, up ) );
2015-12-24 02:11:17 +01:00
}
2015-06-16 02:44:59 +02:00
else
2015-12-24 02:11:17 +01:00
{
//TODO 1.10.2-R - Temp
( (World) this.w ).setBlockState( this.pos, this.w.getBlockState( this.pos ).withProperty( BlockQuartzPillar.AXIS_ORIENTATION, up.getAxis() ) );
2015-12-24 02:11:17 +01:00
}
2015-04-29 02:30:53 +02:00
}
else
2015-04-29 02:30:53 +02:00
{
throw new IllegalStateException( this.w.getClass().getName() + " received, expected World" );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
}