Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.

Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
This commit is contained in:
Lex Manos committed 2014-11-26 00:00:54 -08:00
1 parent 0e91787efb
commit 53659fca06
410 files changed
+8717 -14103

No files matched your search

@@ -12,7 +12,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import cpw.mods.fml.common.FMLLog;
import net.minecraftforge.fml.common.FMLLog;
/**
@@ -4,12 +4,14 @@ package net.minecraftforge.common.util;
import java.io.Serializable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry.UniqueIdentifier;
/**
* Represents a captured snapshot of a block which will not change
@@ -23,29 +25,25 @@ public class BlockSnapshot implements Serializable
{
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockSnapshot", "false"));
public final int x;
public final int y;
public final int z;
public final BlockPos pos;
public final int dimId;
public transient Block replacedBlock;
public final int meta;
public transient IBlockState replacedBlock;
public int flag;
private final NBTTagCompound nbt;
public transient World world;
public final UniqueIdentifier blockIdentifier;
public final int meta;
public BlockSnapshot(World world, int x, int y, int z, Block block, int meta)
public BlockSnapshot(World world, BlockPos pos, IBlockState state)
{
this.world = world;
this.dimId = world.provider.dimensionId;
this.x = x;
this.y = y;
this.z = z;
this.replacedBlock = block;
this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(block);
this.meta = meta;
this.dimId = world.provider.getDimensionId();
this.pos = pos;
this.replacedBlock = state;
this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(state.getBlock());
this.meta = state.getBlock().getMetaFromState(state);
this.flag = 3;
TileEntity te = world.getTileEntity(x, y, z);
TileEntity te = world.getTileEntity(pos);
if (te != null)
{
nbt = new NBTTagCompound();
@@ -54,57 +52,53 @@ public class BlockSnapshot implements Serializable
else nbt = null;
if (DEBUG)
{
System.out.printf("Created BlockSnapshot - [World: %s ][Location: %d,%d,%d ][Block: %s ][Meta: %d ]", world.getWorldInfo().getWorldName(), x, y, z, block, meta);
System.out.printf("Created BlockSnapshot - [World: %s ][Location: %d,%d,%d ][Block: %s ][Meta: %d ]", world.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ(), blockIdentifier, meta);
}
}
public BlockSnapshot(World world, int x, int y, int z, Block block, int meta, NBTTagCompound nbt)
public BlockSnapshot(World world, BlockPos pos, IBlockState state, NBTTagCompound nbt)
{
this.world = world;
this.dimId = world.provider.dimensionId;
this.x = x;
this.y = y;
this.z = z;
this.replacedBlock = block;
this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(block);
this.meta = meta;
this.dimId = world.provider.getDimensionId();
this.pos = pos;
this.replacedBlock = state;
this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(state.getBlock());
this.meta = state.getBlock().getMetaFromState(state);
this.flag = 3;
this.nbt = nbt;
if (DEBUG)
{
System.out.printf("Created BlockSnapshot - [World: %s ][Location: %d,%d,%d ][Block: %s ][Meta: %d ]", world.getWorldInfo().getWorldName(), x, y, z, block, meta);
System.out.printf("Created BlockSnapshot - [World: %s ][Location: %d,%d,%d ][Block: %s ][Meta: %d ]", world.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ(), blockIdentifier, meta);
}
}
public BlockSnapshot(World world, int x, int y, int z, Block block, int meta, int flag)
public BlockSnapshot(World world, BlockPos pos, IBlockState state, int flag)
{
this(world, x, y, z, block, meta);
this(world, pos, state);
this.flag = flag;
}
/**
* Raw constructor designed for serialization usages.
*/
public BlockSnapshot(int dimension, int x, int y, int z, String modid, String blockName, int meta, int flag, NBTTagCompound nbt)
public BlockSnapshot(int dimension, BlockPos pos, String modid, String blockName, int meta, int flag, NBTTagCompound nbt)
{
this.dimId = dimension;
this.x = x;
this.y = y;
this.z = z;
this.meta = meta;
this.pos = pos;
this.flag = flag;
this.blockIdentifier = new UniqueIdentifier(modid + ":" + blockName);
this.meta = meta;
this.nbt = nbt;
}
public static BlockSnapshot getBlockSnapshot(World world, int x, int y, int z)
public static BlockSnapshot getBlockSnapshot(World world, BlockPos pos)
{
return new BlockSnapshot(world, x, y, z, world.getBlock(x, y, z), world.getBlockMetadata(x, y,z));
return new BlockSnapshot(world, pos, world.getBlockState(pos));
}
public static BlockSnapshot getBlockSnapshot(World world, int x, int y, int z, int flag)
public static BlockSnapshot getBlockSnapshot(World world, BlockPos pos, int flag)
{
return new BlockSnapshot(world, x, y, z, world.getBlock(x, y, z), world.getBlockMetadata(x, y,z), flag);
return new BlockSnapshot(world, pos, world.getBlockState(pos), flag);
}
public static BlockSnapshot readFromNBT(NBTTagCompound tag)
@@ -113,9 +107,7 @@ public class BlockSnapshot implements Serializable
return new BlockSnapshot(
tag.getInteger("dimension"),
tag.getInteger("posX"),
tag.getInteger("posY"),
tag.getInteger("posZ"),
new BlockPos(tag.getInteger("posX"), tag.getInteger("posY"), tag.getInteger("posZ")),
tag.getString("blockMod"),
tag.getString("blockName"),
tag.getInteger("metadata"),
@@ -123,25 +115,25 @@ public class BlockSnapshot implements Serializable
nbt);
}
public Block getCurrentBlock()
public IBlockState getCurrentBlock()
{
return world.getBlock(x, y, z);
return world.getBlockState(pos);
}
public World getWorld()
public World getWorld()
{
if (this.world == null)
if (this.world == null)
{
this.world = DimensionManager.getWorld(dimId);
}
return this.world;
}
public Block getReplacedBlock()
public IBlockState getReplacedBlock()
{
if (this.replacedBlock == null)
if (this.replacedBlock == null)
{
this.replacedBlock = GameRegistry.findBlock(this.blockIdentifier.modId, this.blockIdentifier.name);
this.replacedBlock = GameRegistry.findBlock(this.blockIdentifier.modId, this.blockIdentifier.name).getStateFromMeta(meta);
}
return this.replacedBlock;
}
@@ -153,69 +145,38 @@ public class BlockSnapshot implements Serializable
else return null;
}
public boolean restore()
public boolean restore()
{
return restore(false);
}
public boolean restore(boolean force)
public boolean restore(boolean force)
{
return restore(force, true);
}
public boolean restore(boolean force, boolean applyPhysics)
public boolean restore(boolean force, boolean applyPhysics)
{
if (getCurrentBlock() != getReplacedBlock() || world.getBlockMetadata(x & 15, y, z & 15) != meta)
IBlockState current = getCurrentBlock();
IBlockState replaced = getReplacedBlock();
if (current.getBlock() != replaced.getBlock() || current.getBlock().getMetaFromState(current) != replaced.getBlock().getMetaFromState(replaced))
{
if (force)
{
world.setBlock(x, y, z, getReplacedBlock(), meta, applyPhysics ? 3 : 2);
world.setBlockState(pos, replaced, applyPhysics ? 3 : 2);
}
else
{
return false;
}
}
world.setBlockMetadataWithNotify(x, y, z, meta, applyPhysics ? 3 : 2);
world.markBlockForUpdate(x, y, z);
TileEntity te = null;
if (nbt != null)
{
te = world.getTileEntity(x, y, z);
if (te != null)
{
te.readFromNBT(nbt);
}
}
if (DEBUG)
{
System.out.printf("Restored BlockSnapshot with data [World: %s ][Location: %d,%d,%d ][Meta: %d ][Block: %s ][TileEntity: %s ][force: %s ][applyPhysics: %s]", world.getWorldInfo().getWorldName(), x, y, z, meta, getReplacedBlock(), te, force, applyPhysics);
}
return true;
}
public boolean restoreToLocation(World world, int x, int y, int z, boolean force, boolean applyPhysics)
{
if (getCurrentBlock() != getReplacedBlock() || world.getBlockMetadata(x & 15, y, z & 15) != meta)
{
if (force)
{
world.setBlock(x, y, z, getReplacedBlock(), meta, applyPhysics ? 3 : 2);
}
else
{
return false;
}
}
world.setBlockMetadataWithNotify(x, y, z, meta, applyPhysics ? 3 : 2);
world.markBlockForUpdate(x, y, z);
world.setBlockState(pos, replaced, applyPhysics ? 3 : 2);
world.markBlockForUpdate(pos);
TileEntity te = null;
if (nbt != null)
{
te = world.getTileEntity(x, y, z);
te = world.getTileEntity(pos);
if (te != null)
{
te.readFromNBT(nbt);
@@ -224,7 +185,42 @@ public class BlockSnapshot implements Serializable
if (DEBUG)
{
System.out.printf("Restored BlockSnapshot with data [World: %s ][Location: %d,%d,%d ][Meta: %d ][Block: %s ][TileEntity: %s ][force: %s ][applyPhysics: %s]", world.getWorldInfo().getWorldName(), x, y, z, meta, getReplacedBlock(), te, force, applyPhysics);
System.out.printf("Restored BlockSnapshot with data [World: %s ][Location: %d,%d,%d ][Meta: %d ][Block: %s ][TileEntity: %s ][force: %s ][applyPhysics: %s]", world.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ(), replaced.getBlock().getMetaFromState(replaced), replaced.getBlock().delegate.name(), te, force, applyPhysics);
}
return true;
}
public boolean restoreToLocation(World world, BlockPos pos, boolean force, boolean applyPhysics)
{
IBlockState current = getCurrentBlock();
IBlockState replaced = getReplacedBlock();
if (current.getBlock() != replaced.getBlock() || current.getBlock().getMetaFromState(current) != replaced.getBlock().getMetaFromState(replaced))
{
if (force)
{
world.setBlockState(pos, replaced, applyPhysics ? 3 : 2);
}
else
{
return false;
}
}
world.setBlockState(pos, replaced, applyPhysics ? 3 : 2);
world.markBlockForUpdate(pos);
TileEntity te = null;
if (nbt != null)
{
te = world.getTileEntity(pos);
if (te != null)
{
te.readFromNBT(nbt);
}
}
if (DEBUG)
{
System.out.printf("Restored BlockSnapshot with data [World: %s ][Location: %d,%d,%d ][Meta: %d ][Block: %s ][TileEntity: %s ][force: %s ][applyPhysics: %s]", world.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ(), replaced.getBlock().getMetaFromState(replaced), replaced.getBlock().delegate.name(), te, force, applyPhysics);
}
return true;
}
@@ -233,9 +229,9 @@ public class BlockSnapshot implements Serializable
{
compound.setString("blockMod", blockIdentifier.modId);
compound.setString("blockName", blockIdentifier.name);
compound.setInteger("posX", x);
compound.setInteger("posY", y);
compound.setInteger("posZ", z);
compound.setInteger("posX", pos.getX());
compound.setInteger("posY", pos.getY());
compound.setInteger("posZ", pos.getZ());
compound.setInteger("flag", flag);
compound.setInteger("dimension", dimId);
compound.setInteger("metadata", meta);
@@ -249,7 +245,7 @@ public class BlockSnapshot implements Serializable
}
@Override
public boolean equals(Object obj)
public boolean equals(Object obj)
{
if (obj == null)
{
@@ -260,15 +256,7 @@ public class BlockSnapshot implements Serializable
return false;
}
final BlockSnapshot other = (BlockSnapshot) obj;
if (this.x != other.x)
{
return false;
}
if (this.y != other.y)
{
return false;
}
if (this.z != other.z)
if (!this.pos.equals(other.pos))
{
return false;
}
@@ -299,9 +287,9 @@ public class BlockSnapshot implements Serializable
public int hashCode()
{
int hash = 7;
hash = 73 * hash + this.x;
hash = 73 * hash + this.y;
hash = 73 * hash + this.z;
hash = 73 * hash + this.pos.getX();
hash = 73 * hash + this.pos.getY();
hash = 73 * hash + this.pos.getZ();
hash = 73 * hash + this.meta;
hash = 73 * hash + this.dimId;
hash = 73 * hash + (this.nbt != null ? this.nbt.hashCode() : 0);
@@ -3,11 +3,10 @@ package net.minecraftforge.common.util;
import java.lang.reflect.*;
import java.util.*;
import cpw.mods.fml.common.FMLLog;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraft.block.BlockPressurePlate.Sensitivity;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.entity.Entity.EnumEntitySize;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.item.EntityPainting.EnumArt;
@@ -42,7 +41,6 @@ public class EnumHelper
{EnumCreatureType.class, Class.class, int.class, Material.class, boolean.class, boolean.class},
{Door.class},
{EnumEnchantmentType.class},
{EnumEntitySize.class},
{Sensitivity.class},
{MovingObjectType.class},
{EnumSkyBlock.class, int.class},
@@ -80,10 +78,6 @@ public class EnumHelper
{
return addEnum(EnumEnchantmentType.class, name);
}
public static EnumEntitySize addEntitySize(String name)
{
return addEnum(EnumEntitySize.class, name);
}
public static Sensitivity addSensitivity(String name)
{
return addEnum(Sensitivity.class, name);
@@ -2,19 +2,19 @@ package net.minecraftforge.common.util;
import com.mojang.authlib.GameProfile;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.client.C15PacketClientSettings;
import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.stats.StatBase;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
//Preliminary, simple Fake Player class
//Preliminary, simple Fake Player class
public class FakePlayer extends EntityPlayerMP
{
public FakePlayer(WorldServer world, GameProfile name)
@@ -22,19 +22,15 @@ public class FakePlayer extends EntityPlayerMP
super(FMLCommonHandler.instance().getMinecraftServerInstance(), world, name, new ItemInWorldManager(world));
}
@Override public Vec3 getPositionVector(){ return new Vec3(0, 0, 0); }
@Override public boolean canCommandSenderUseCommand(int i, String s){ return false; }
@Override public ChunkCoordinates getPlayerCoordinates()
{
return new ChunkCoordinates(0,0,0);
}
@Override public void addChatComponentMessage(IChatComponent chatmessagecomponent){}
@Override public void addStat(StatBase par1StatBase, int par2){}
@Override public void openGui(Object mod, int modGuiId, World world, int x, int y, int z){}
@Override public boolean isEntityInvulnerable(){ return true; }
@Override public boolean func_180431_b(DamageSource source){ return true; }
@Override public boolean canAttackPlayer(EntityPlayer player){ return false; }
@Override public void onDeath(DamageSource source){ return; }
@Override public void onUpdate(){ return; }
@Override public void travelToDimension(int dim){ return; }
@Override public void func_147100_a(C15PacketClientSettings pkt){ return; }
@Override public void handleClientSettings(C15PacketClientSettings pkt){ return; }
}
@@ -1,71 +0,0 @@
package net.minecraftforge.common.util;
public enum ForgeDirection
{
/** -Y */
DOWN(0, -1, 0),
/** +Y */
UP(0, 1, 0),
/** -Z */
NORTH(0, 0, -1),
/** +Z */
SOUTH(0, 0, 1),
/** -X */
WEST(-1, 0, 0),
/** +X */
EAST(1, 0, 0),
/**
* Used only by getOrientation, for invalid inputs
*/
UNKNOWN(0, 0, 0);
public final int offsetX;
public final int offsetY;
public final int offsetZ;
public final int flag;
public static final ForgeDirection[] VALID_DIRECTIONS = {DOWN, UP, NORTH, SOUTH, WEST, EAST};
public static final int[] OPPOSITES = {1, 0, 3, 2, 5, 4, 6};
// Left hand rule rotation matrix for all possible axes of rotation
public static final int[][] ROTATION_MATRIX = {
{0, 1, 4, 5, 3, 2, 6},
{0, 1, 5, 4, 2, 3, 6},
{5, 4, 2, 3, 0, 1, 6},
{4, 5, 2, 3, 1, 0, 6},
{2, 3, 1, 0, 4, 5, 6},
{3, 2, 0, 1, 4, 5, 6},
{0, 1, 2, 3, 4, 5, 6},
};
private ForgeDirection(int x, int y, int z)
{
offsetX = x;
offsetY = y;
offsetZ = z;
flag = 1 << ordinal();
}
public static ForgeDirection getOrientation(int id)
{
if (id >= 0 && id < VALID_DIRECTIONS.length)
{
return VALID_DIRECTIONS[id];
}
return UNKNOWN;
}
public ForgeDirection getOpposite()
{
return getOrientation(OPPOSITES[ordinal()]);
}
public ForgeDirection getRotation(ForgeDirection axis)
{
return getOrientation(ROTATION_MATRIX[axis.ordinal()][ordinal()]);
}
}
@@ -1,439 +0,0 @@
package net.minecraftforge.common.util;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAnvil;
import net.minecraft.block.BlockBed;
import net.minecraft.block.BlockButton;
import net.minecraft.block.BlockChest;
import net.minecraft.block.BlockCocoa;
import net.minecraft.block.BlockDispenser;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.BlockEndPortalFrame;
import net.minecraft.block.BlockEnderChest;
import net.minecraft.block.BlockFenceGate;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.BlockHopper;
import net.minecraft.block.BlockHugeMushroom;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockLever;
import net.minecraft.block.BlockLog;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.BlockPistonExtension;
import net.minecraft.block.BlockPumpkin;
import net.minecraft.block.BlockRail;
import net.minecraft.block.BlockRailDetector;
import net.minecraft.block.BlockRailPowered;
import net.minecraft.block.BlockRedstoneComparator;
import net.minecraft.block.BlockRedstoneRepeater;
import net.minecraft.block.BlockSkull;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.BlockTorch;
import net.minecraft.block.BlockTrapDoor;
import net.minecraft.block.BlockTripWireHook;
import net.minecraft.block.BlockVine;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import java.util.HashMap;
import java.util.Map;
import static net.minecraftforge.common.util.ForgeDirection.*;
/**
* This class is a helper function for vanilla blocks, and should not be called by Modders.
* Refer to block.rotateBlock and block.getValidRotations instead.
*
*/
public class RotationHelper {
/**
* Some blocks have the same rotation.
* The first of these blocks (sorted by itemID) should be listed as a type.
* Some of the types aren't actual blocks (helper types).
*/
private static enum BlockType {
LOG,
DISPENSER,
BED,
RAIL,
RAIL_POWERED,
RAIL_ASCENDING,
RAIL_CORNER,
TORCH,
STAIR,
CHEST,
SIGNPOST,
DOOR,
LEVER,
BUTTON,
REDSTONE_REPEATER,
TRAPDOOR,
MUSHROOM_CAP,
MUSHROOM_CAP_CORNER,
MUSHROOM_CAP_SIDE,
VINE,
SKULL,
ANVIL
}
private static final ForgeDirection[] UP_DOWN_AXES = new ForgeDirection[] { UP, DOWN };
private static final Map<BlockType, BiMap<Integer, ForgeDirection>> MAPPINGS = new HashMap<BlockType, BiMap<Integer, ForgeDirection>>();
public static ForgeDirection[] getValidVanillaBlockRotations(Block block)
{
return (block instanceof BlockBed ||
block instanceof BlockPumpkin ||
block instanceof BlockFenceGate ||
block instanceof BlockEndPortalFrame ||
block instanceof BlockTripWireHook ||
block instanceof BlockCocoa ||
block instanceof BlockRailPowered ||
block instanceof BlockRailDetector ||
block instanceof BlockStairs ||
block instanceof BlockChest ||
block instanceof BlockEnderChest ||
block instanceof BlockFurnace ||
block instanceof BlockLadder ||
block == Blocks.wall_sign ||
block == Blocks.standing_sign ||
block instanceof BlockDoor ||
block instanceof BlockRail ||
block instanceof BlockButton ||
block instanceof BlockRedstoneRepeater ||
block instanceof BlockRedstoneComparator ||
block instanceof BlockTrapDoor ||
block instanceof BlockHugeMushroom ||
block instanceof BlockVine ||
block instanceof BlockSkull ||
block instanceof BlockAnvil) ? UP_DOWN_AXES : VALID_DIRECTIONS;
}
public static boolean rotateVanillaBlock(Block block, World worldObj, int x, int y, int z, ForgeDirection axis)
{
if (worldObj.isRemote)
{
return false;
}
if (axis == UP || axis == DOWN)
{
if (block instanceof BlockBed || block instanceof BlockPumpkin || block instanceof BlockFenceGate || block instanceof BlockEndPortalFrame || block instanceof BlockTripWireHook || block instanceof BlockCocoa)
{
return rotateBlock(worldObj, x, y, z, axis, 0x3, BlockType.BED);
}
if (block instanceof BlockRail)
{
return rotateBlock(worldObj, x, y, z, axis, 0xF, BlockType.RAIL);
}
if (block instanceof BlockRailPowered || block instanceof BlockRailDetector)
{
return rotateBlock(worldObj, x, y, z, axis, 0x7, BlockType.RAIL_POWERED);
}
if (block instanceof BlockStairs)
{
return rotateBlock(worldObj, x, y, z, axis, 0x3, BlockType.STAIR);
}
if (block instanceof BlockChest || block instanceof BlockEnderChest || block instanceof BlockFurnace || block instanceof BlockLadder || block == Blocks.wall_sign)
{
return rotateBlock(worldObj, x, y, z, axis, 0x7, BlockType.CHEST);
}
if (block == Blocks.standing_sign)
{
return rotateBlock(worldObj, x, y, z, axis, 0xF, BlockType.SIGNPOST);
}
if (block instanceof BlockDoor)
{
return rotateBlock(worldObj, x, y, z, axis, 0x3, BlockType.DOOR);
}
if (block instanceof BlockButton)
{
return rotateBlock(worldObj, x, y, z, axis, 0x7, BlockType.BUTTON);
}
if (block instanceof BlockRedstoneRepeater || block instanceof BlockRedstoneComparator)
{
return rotateBlock(worldObj, x, y, z, axis, 0x3, BlockType.REDSTONE_REPEATER);
}
if (block instanceof BlockTrapDoor)
{
return rotateBlock(worldObj, x, y, z, axis, 0x3, BlockType.TRAPDOOR);
}
if (block instanceof BlockHugeMushroom)
{
return rotateBlock(worldObj, x, y, z, axis, 0xF, BlockType.MUSHROOM_CAP);
}
if (block instanceof BlockVine)
{
return rotateBlock(worldObj, x, y, z, axis, 0xF, BlockType.VINE);
}
if (block instanceof BlockSkull)
{
return rotateBlock(worldObj, x, y, z, axis, 0x7, BlockType.SKULL);
}
if (block instanceof BlockAnvil)
{
return rotateBlock(worldObj, x, y, z, axis, 0x1, BlockType.ANVIL);
}
}
if (block instanceof BlockLog)
{
return rotateBlock(worldObj, x, y, z, axis, 0xC, BlockType.LOG);
}
if (block instanceof BlockDispenser || block instanceof BlockPistonBase || block instanceof BlockPistonExtension || block instanceof BlockHopper)
{
return rotateBlock(worldObj, x, y, z, axis, 0x7, BlockType.DISPENSER);
}
if (block instanceof BlockTorch)
{
return rotateBlock(worldObj, x, y, z, axis, 0xF, BlockType.TORCH);
}
if (block instanceof BlockLever)
{
return rotateBlock(worldObj, x, y, z, axis, 0x7, BlockType.LEVER);
}
return false;
}
private static boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis, int mask, BlockType blockType)
{
int rotMeta = worldObj.getBlockMetadata(x, y, z);
if (blockType == BlockType.DOOR && (rotMeta & 0x8) == 0x8)
{
return false;
}
int masked = rotMeta & ~mask;
int meta = rotateMetadata(axis, blockType, rotMeta & mask);
if (meta == -1)
{
return false;
}
worldObj.setBlockMetadataWithNotify(x, y, z, meta & mask | masked, 3);
return true;
}
private static int rotateMetadata(ForgeDirection axis, BlockType blockType, int meta)
{
if (blockType == BlockType.RAIL || blockType == BlockType.RAIL_POWERED)
{
if (meta == 0x0 || meta == 0x1)
{
return ~meta & 0x1;
}
if (meta >= 0x2 && meta <= 0x5)
{
blockType = BlockType.RAIL_ASCENDING;
}
if (meta >= 0x6 && meta <= 0x9 && blockType == BlockType.RAIL)
{
blockType = BlockType.RAIL_CORNER;
}
}
if (blockType == BlockType.SIGNPOST)
{
return (axis == UP) ? (meta + 0x4) % 0x10 : (meta + 0xC) % 0x10;
}
if (blockType == BlockType.LEVER && (axis == UP || axis == DOWN))
{
switch (meta)
{
case 0x5:
return 0x6;
case 0x6:
return 0x5;
case 0x7:
return 0x0;
case 0x0:
return 0x7;
}
}
if (blockType == BlockType.MUSHROOM_CAP)
{
if (meta % 0x2 == 0)
{
blockType = BlockType.MUSHROOM_CAP_SIDE;
}
else
{
blockType = BlockType.MUSHROOM_CAP_CORNER;
}
}
if (blockType == BlockType.VINE)
{
return ((meta << 1) | ((meta & 0x8) >> 3));
}
ForgeDirection orientation = metadataToDirection(blockType, meta);
ForgeDirection rotated = orientation.getRotation(axis);
return directionToMetadata(blockType, rotated);
}
private static ForgeDirection metadataToDirection(BlockType blockType, int meta)
{
if (blockType == BlockType.LEVER)
{
if (meta == 0x6)
{
meta = 0x5;
}
else if (meta == 0x0)
{
meta = 0x7;
}
}
if (MAPPINGS.containsKey(blockType))
{
BiMap<Integer, ForgeDirection> biMap = MAPPINGS.get(blockType);
if (biMap.containsKey(meta))
{
return biMap.get(meta);
}
}
if (blockType == BlockType.TORCH)
{
return ForgeDirection.getOrientation(6 - meta);
}
if (blockType == BlockType.STAIR)
{
return ForgeDirection.getOrientation(5 - meta);
}
if (blockType == BlockType.CHEST || blockType == BlockType.DISPENSER || blockType == BlockType.SKULL)
{
return ForgeDirection.getOrientation(meta);
}
if (blockType == BlockType.BUTTON)
{
return ForgeDirection.getOrientation(6 - meta);
}
if (blockType == BlockType.TRAPDOOR)
{
return ForgeDirection.getOrientation(meta + 2).getOpposite();
}
return ForgeDirection.UNKNOWN;
}
private static int directionToMetadata(BlockType blockType, ForgeDirection direction)
{
if ((blockType == BlockType.LOG || blockType == BlockType.ANVIL) && (direction.offsetX + direction.offsetY + direction.offsetZ) < 0)
{
direction = direction.getOpposite();
}
if (MAPPINGS.containsKey(blockType))
{
BiMap<ForgeDirection, Integer> biMap = MAPPINGS.get(blockType).inverse();
if (biMap.containsKey(direction))
{
return biMap.get(direction);
}
}
if (blockType == BlockType.TORCH)
{
if (direction.ordinal() >= 1)
{
return 6 - direction.ordinal();
}
}
if (blockType == BlockType.STAIR)
{
return 5 - direction.ordinal();
}
if (blockType == BlockType.CHEST || blockType == BlockType.DISPENSER || blockType == BlockType.SKULL)
{
return direction.ordinal();
}
if (blockType == BlockType.BUTTON)
{
if (direction.ordinal() >= 2)
{
return 6 - direction.ordinal();
}
}
if (blockType == BlockType.TRAPDOOR)
{
return direction.getOpposite().ordinal() - 2;
}
return -1;
}
static
{
BiMap<Integer, ForgeDirection> biMap;
biMap = HashBiMap.create(3);
biMap.put(0x0, UP);
biMap.put(0x4, EAST);
biMap.put(0x8, SOUTH);
MAPPINGS.put(BlockType.LOG, biMap);
biMap = HashBiMap.create(4);
biMap.put(0x0, SOUTH);
biMap.put(0x1, WEST);
biMap.put(0x2, NORTH);
biMap.put(0x3, EAST);
MAPPINGS.put(BlockType.BED, biMap);
biMap = HashBiMap.create(4);
biMap.put(0x2, EAST);
biMap.put(0x3, WEST);
biMap.put(0x4, NORTH);
biMap.put(0x5, SOUTH);
MAPPINGS.put(BlockType.RAIL_ASCENDING, biMap);
biMap = HashBiMap.create(4);
biMap.put(0x6, WEST);
biMap.put(0x7, NORTH);
biMap.put(0x8, EAST);
biMap.put(0x9, SOUTH);
MAPPINGS.put(BlockType.RAIL_CORNER, biMap);
biMap = HashBiMap.create(6);
biMap.put(0x1, EAST);
biMap.put(0x2, WEST);
biMap.put(0x3, SOUTH);
biMap.put(0x4, NORTH);
biMap.put(0x5, UP);
biMap.put(0x7, DOWN);
MAPPINGS.put(BlockType.LEVER, biMap);
biMap = HashBiMap.create(4);
biMap.put(0x0, WEST);
biMap.put(0x1, NORTH);
biMap.put(0x2, EAST);
biMap.put(0x3, SOUTH);
MAPPINGS.put(BlockType.DOOR, biMap);
biMap = HashBiMap.create(4);
biMap.put(0x0, NORTH);
biMap.put(0x1, EAST);
biMap.put(0x2, SOUTH);
biMap.put(0x3, WEST);
MAPPINGS.put(BlockType.REDSTONE_REPEATER, biMap);
biMap = HashBiMap.create(4);
biMap.put(0x1, EAST);
biMap.put(0x3, SOUTH);
biMap.put(0x7, NORTH);
biMap.put(0x9, WEST);
MAPPINGS.put(BlockType.MUSHROOM_CAP_CORNER, biMap);
biMap = HashBiMap.create(4);
biMap.put(0x2, NORTH);
biMap.put(0x4, WEST);
biMap.put(0x6, EAST);
biMap.put(0x8, SOUTH);
MAPPINGS.put(BlockType.MUSHROOM_CAP_SIDE, biMap);
biMap = HashBiMap.create(2);
biMap.put(0x0, SOUTH);
biMap.put(0x1, EAST);
MAPPINGS.put(BlockType.ANVIL, biMap);
}
}