下面列出了net.minecraft.util.EnumFacing#byIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public EnumFacing getAreaFacing(ItemStack stack, Mode mode)
{
NBTTagCompound tag = this.getSelectedTemplateTag(stack, mode, true);
if (tag.hasKey("Rotation", Constants.NBT.TAG_BYTE))
{
return EnumFacing.byIndex(tag.getByte("Rotation"));
}
else
{
BlockPosEU posStart = this.getPerTemplateAreaCorner(stack, mode, true);
BlockPosEU posEnd = this.getPerTemplateAreaCorner(stack, mode, false);
if (posStart != null && posEnd != null)
{
return PositionUtils.getFacingFromPositions(posStart, posEnd);
}
}
return null;
}
public static BlockPosEU readFromTag(NBTTagCompound tag)
{
if (tag == null ||
tag.hasKey("posX", Constants.NBT.TAG_INT) == false ||
tag.hasKey("posY", Constants.NBT.TAG_INT) == false ||
tag.hasKey("posZ", Constants.NBT.TAG_INT) == false ||
tag.hasKey("dim", Constants.NBT.TAG_INT) == false ||
tag.hasKey("face", Constants.NBT.TAG_BYTE) == false)
{
return null;
}
int x = tag.getInteger("posX");
int y = tag.getInteger("posY");
int z = tag.getInteger("posZ");
int dim = tag.getInteger("dim");
int face = tag.getByte("face");
return new BlockPosEU(x, y, z, dim, EnumFacing.byIndex(face));
}
public void readFromNBTCustom(NBTTagCompound nbt)
{
if (nbt.hasKey("Rotation", Constants.NBT.TAG_BYTE))
{
this.facing = EnumFacing.byIndex(nbt.getByte("Rotation"));
}
/*
if (nbt.hasKey("Camo", Constants.NBT.TAG_COMPOUND))
{
this.camoState = NBTUtils.readBlockStateFromTag(nbt.getCompoundTag("Camo"));
}
*/
if (nbt.hasKey("Camo", Constants.NBT.TAG_INT))
{
this.camoState = Block.getStateById(nbt.getInteger("Camo"));
}
if (nbt.hasKey("CamoData", Constants.NBT.TAG_COMPOUND))
{
this.camoData = nbt.getCompoundTag("CamoData");
}
this.ownerData = OwnerData.getOwnerDataFromNBT(nbt);
}
@SuppressWarnings("deprecation")
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing enumfacing = EnumFacing.byIndex(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing enumfacing = EnumFacing.byIndex(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing enumfacing = EnumFacing.byIndex(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing enumfacing = EnumFacing.byIndex(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(BlockHorizontal.FACING, enumfacing);
}
@Override
@SuppressWarnings("deprecation")
@Nonnull
public IBlockState getStateFromMeta(int meta) {
EnumFacing enumfacing = EnumFacing.byIndex(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(BlockHorizontal.FACING, enumfacing);
}
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing enumfacing = EnumFacing.byIndex(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing enumfacing = EnumFacing.byIndex(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState()
.withProperty(FACING, enumfacing);
}
private void initBlockBounds() {
float w = getBoundsWidth();
float h = getBoundsHeight();
float d = getBoundsDepth();
for (int i = 0; i < _boundsFromFacing.length; i++) {
EnumFacing facing = EnumFacing.byIndex(i + 2);
_boundsFromFacing[i] = ((facing.getAxis() == Axis.Z)
? new AxisAlignedBB(0.5F - w / 2, 0.0F, 0.5F - d / 2, 0.5F + w / 2, h, 0.5F + d / 2)
: new AxisAlignedBB(0.5F - d / 2, 0.0F, 0.5F - w / 2, 0.5F + d / 2, h, 0.5F + w / 2));
}
}
public EnumFacing getAreaFlipAxis(ItemStack stack, EnumFacing defaultFlipAxis)
{
NBTTagCompound tag = this.getModeTag(stack, Mode.getMode(stack));
if (tag.hasKey("FlipAxis", Constants.NBT.TAG_BYTE))
{
return EnumFacing.byIndex(tag.getByte("FlipAxis"));
}
return defaultFlipAxis;
}
public NBTTagCompound readTargetTagFromNBT(NBTTagCompound nbt)
{
if (nbtHasTargetTag(nbt) == false)
{
return null;
}
NBTTagCompound tag = nbt.getCompoundTag("Target");
this.pos = new BlockPos(tag.getInteger("posX"), tag.getInteger("posY"), tag.getInteger("posZ"));
this.dimension = tag.getInteger("Dim");
this.dimensionName = tag.getString("DimName");
this.blockName = tag.getString("BlockName");
this.blockMeta = tag.getByte("BlockMeta");
this.itemMeta = tag.getByte("ItemMeta");
this.blockFace = tag.getByte("BlockFace");
this.facing = EnumFacing.byIndex(this.blockFace);
this.dPosX = tag.hasKey("dPosX", Constants.NBT.TAG_DOUBLE) ? tag.getDouble("dPosX") : this.pos.getX() + 0.5d;
this.dPosY = tag.hasKey("dPosY", Constants.NBT.TAG_DOUBLE) ? tag.getDouble("dPosY") : this.pos.getY();
this.dPosZ = tag.hasKey("dPosZ", Constants.NBT.TAG_DOUBLE) ? tag.getDouble("dPosZ") : this.pos.getZ() + 0.5d;
if (tag.hasKey("Yaw", Constants.NBT.TAG_FLOAT) && tag.hasKey("Pitch", Constants.NBT.TAG_FLOAT))
{
this.hasRotation = true;
this.yaw = tag.getFloat("Yaw");
this.pitch = tag.getFloat("Pitch");
}
return tag;
}
public void read(NBTTagCompound nbt)
{
NBTTagList tagList = nbt.getTagList("endPosRelative", 3);
this.endPosRelative = new BlockPos(tagList.getIntAt(0), tagList.getIntAt(1), tagList.getIntAt(2));
this.facing = EnumFacing.byIndex(nbt.getByte("facing"));
this.templateName = nbt.getString("name");
this.author = nbt.getString("author");
}
public void readNBT(NBTTagCompound compound, boolean isClient) {
_age = (!isClient ? compound.getInteger(TAG_AGE) : 0);
facing = EnumFacing.byIndex(NbtUtils.get(compound, (byte)0, TAG_FACING) + 2);
_stack = NbtUtils.readItem(compound.getCompoundTag(TAG_STACK));
if (_stack.isEmpty() || isClient) { _data = null; return; }
_data = BackpackHelper.getBackpackType(_stack).createBackpackData(_stack);
NBTBase dataTag = compound.getTag(TAG_DATA);
if (dataTag != null) _data.deserializeNBT(dataTag);
_despawnTimer = (compound.hasKey(TAG_DESPAWN_TIMER)
? compound.getInteger(TAG_DESPAWN_TIMER) : -1);
}
private static Set<BlockPos> allLiquidInPool(World world, BlockPos pos, int needed, Fluid fluid) {
if (needed <= 0) return Sets.newHashSet();
Block block = fluid.getBlock();
if (block == null) return Sets.newHashSet();
IBlockState sourceBlock = block.getDefaultState();
BlockPos.MutableBlockPos topPos = new BlockPos.MutableBlockPos(pos);
IBlockState stateAt = world.getBlockState(topPos);
boolean lastWasFluid = false;
while (stateAt.getBlock() == block) {
lastWasFluid = stateAt == sourceBlock;
stateAt = world.getBlockState(topPos.setPos(topPos.getX(), topPos.getY() + 1, topPos.getZ()));
}
topPos.setPos(topPos.getX(), topPos.getY() - 1, topPos.getZ());
BlockPos.MutableBlockPos tool = new BlockPos.MutableBlockPos();
Set<BlockPos> positions = Sets.newHashSet(topPos.toImmutable());
Set<BlockPos> visited = Sets.newHashSet(positions);
Set<BlockPos> resultants = Sets.newHashSet();
if (lastWasFluid)
resultants.addAll(positions);
while (resultants.size() < needed && !positions.isEmpty() && visited.size() < 1000) {
BlockPos point = positions.iterator().next();
positions.remove(point);
for (int index = EnumFacing.VALUES.length - 1; index >= 0; index--) {
EnumFacing facing = EnumFacing.byIndex(index);
tool.setPos(point.getX() + facing.getXOffset(),
point.getY() + facing.getYOffset(),
point.getZ() + facing.getZOffset());
if (!visited.contains(tool)) {
BlockPos immutable = tool.toImmutable();
visited.add(immutable);
stateAt = world.getBlockState(tool);
if (stateAt.getBlock() == block) {
positions.add(immutable);
if (stateAt == sourceBlock) {
resultants.add(immutable);
if (resultants.size() >= needed)
return resultants;
}
}
}
}
}
return resultants;
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
EnumFacing facing = EnumFacing.byIndex(meta);
return new TileEntityGearbox(facing);
}
private boolean tryPlaceDownBlock(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side)
{
pos = pos.offset(side);
if (this.isCarryingBlock(stack) == false || world.isBlockModifiable(player, pos) == false)
{
return false;
}
NBTTagCompound tagCarrying = NBTUtils.getCompoundTag(stack, "Carrying", false);
String name = tagCarrying.getString("Block");
int meta = tagCarrying.getByte("Meta");
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name));
try
{
if (block != null && block != Blocks.AIR && world.mayPlace(block, pos, false, side, player))
{
@SuppressWarnings("deprecation")
IBlockState state = block.getStateFromMeta(meta);
EnumFacing pickupFacing = EnumFacing.byIndex(tagCarrying.getByte("PickupFacing"));
EnumFacing currentFacing = EntityUtils.getHorizontalLookingDirection(player);
Rotation rotation = PositionUtils.getRotation(pickupFacing, currentFacing);
state = state.withRotation(rotation);
if (world.setBlockState(pos, state))
{
TileEntity te = world.getTileEntity(pos);
if (te != null && tagCarrying.hasKey("te", Constants.NBT.TAG_COMPOUND))
{
NBTTagCompound nbt = tagCarrying.getCompoundTag("te");
TileUtils.createAndAddTileEntity(world, pos, nbt, rotation, Mirror.NONE);
}
NBTUtils.removeCompoundTag(stack, null, "Carrying");
return true;
}
}
}
catch (Exception e)
{
EnderUtilities.logger.warn("Failed to place down a block from the Dolly", e);
}
return false;
}
public EnumFacing getTemplateFacing(ItemStack stack)
{
NBTTagCompound tag = this.getSelectedTemplateTag(stack, Mode.PASTE, true);
return EnumFacing.byIndex(tag.getByte("TemplateFacing"));
}
public BlockPosEU(BlockPos pos, int dim, int facing)
{
this(pos.getX(), pos.getY(), pos.getZ(), dim, EnumFacing.byIndex(facing));
}