Added a default transformer for EnumFacing properties
This commit is contained in:
parent
a3fafc3d5d
commit
991f9817a9
3 changed files with 52 additions and 39 deletions
|
@ -1,11 +1,14 @@
|
|||
package cr0s.warpdrive.api;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -55,4 +58,48 @@ public interface IBlockTransformer {
|
|||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
// default rotation using EnumFacing properties used in many blocks
|
||||
@SuppressWarnings("unchecked")
|
||||
static int rotateFirstEnumFacingProperty(final Block block, final int metadata, final byte rotationSteps) {
|
||||
// find first property using EnumFacing
|
||||
final IBlockState blockState = block.getStateFromMeta(metadata);
|
||||
PropertyEnum<EnumFacing> propertyFacing = null;
|
||||
for (final IProperty<?> propertyKey : blockState.getPropertyKeys()) {
|
||||
if ( propertyKey instanceof PropertyEnum<?>
|
||||
&& propertyKey.getValueClass() == EnumFacing.class ) {
|
||||
propertyFacing = (PropertyEnum<EnumFacing>) propertyKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (propertyFacing != null) {
|
||||
final EnumFacing facingOld = blockState.getValue(propertyFacing);
|
||||
// skip vertical facings
|
||||
if ( facingOld == EnumFacing.DOWN
|
||||
|| facingOld == EnumFacing.UP ) {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
// turn horizontal facings
|
||||
final EnumFacing facingNew;
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
facingNew = facingOld.rotateY();
|
||||
break;
|
||||
case 2:
|
||||
facingNew = facingOld.rotateY().rotateY();
|
||||
break;
|
||||
case 3:
|
||||
facingNew = facingOld.rotateY().rotateY().rotateY();
|
||||
break;
|
||||
default:
|
||||
facingNew = facingOld;
|
||||
break;
|
||||
}
|
||||
final IBlockState blockStateNew = blockState.withProperty(propertyFacing, facingNew);
|
||||
return block.getMetaFromState(blockStateNew);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
|
@ -326,45 +326,8 @@ D- micdoodle8.mods.galacticraft.planets.mars.BlockTelemetry
|
|||
}
|
||||
}
|
||||
|
||||
// generic rotation based on EnumFacing properties
|
||||
final IBlockState blockState = block.getStateFromMeta(metadata);
|
||||
PropertyEnum<EnumFacing> propertyFacing = null;
|
||||
for (final IProperty<?> propertyKey : blockState.getPropertyKeys()) {
|
||||
if ( propertyKey instanceof PropertyEnum<?>
|
||||
&& propertyKey.getValueClass() == EnumFacing.class ) {
|
||||
propertyFacing = (PropertyEnum<EnumFacing>) propertyKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (propertyFacing != null) {
|
||||
final EnumFacing facingOld = blockState.getValue(propertyFacing);
|
||||
// skip vertical facings
|
||||
if ( facingOld == EnumFacing.DOWN
|
||||
|| facingOld == EnumFacing.UP ) {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
// turn horizontal facings
|
||||
final EnumFacing facingNew;
|
||||
switch (rotationSteps) {
|
||||
case 1:
|
||||
facingNew = facingOld.rotateY();
|
||||
break;
|
||||
case 2:
|
||||
facingNew = facingOld.rotateY().rotateY();
|
||||
break;
|
||||
case 3:
|
||||
facingNew = facingOld.rotateY().rotateY().rotateY();
|
||||
break;
|
||||
default:
|
||||
facingNew = facingOld;
|
||||
break;
|
||||
}
|
||||
final IBlockState blockStateNew = blockState.withProperty(propertyFacing, facingNew);
|
||||
return block.getMetaFromState(blockStateNew);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
// apply default transformer
|
||||
return IBlockTransformer.rotateFirstEnumFacingProperty(block, metadata, rotationSteps);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -259,6 +259,9 @@ public class JumpBlock {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// apply default transformer
|
||||
return IBlockTransformer.rotateFirstEnumFacingProperty(block, blockMeta, rotationSteps);
|
||||
}
|
||||
|
||||
switch (rotationSteps) {
|
||||
|
|
Loading…
Reference in a new issue