Java Code Examples for net.minecraft.util.EnumFacing#getIndex()

The following examples show how to use net.minecraft.util.EnumFacing#getIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockFluidPipe.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int getActiveNodeConnections(IBlockAccess world, BlockPos nodePos, IPipeTile<FluidPipeType, FluidPipeProperties> selfTileEntity) {
    int activeNodeConnections = 0;
    for (EnumFacing side : EnumFacing.VALUES) {
        BlockPos offsetPos = nodePos.offset(side);
        TileEntity tileEntity = world.getTileEntity(offsetPos);
        if(tileEntity != null) {
            EnumFacing opposite = side.getOpposite();
            IFluidHandler sourceHandler = selfTileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
            IFluidHandler receivedHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opposite);
            if (sourceHandler != null && receivedHandler != null && canPushIntoFluidHandler(selfTileEntity, tileEntity, sourceHandler, receivedHandler)) {
                activeNodeConnections |= 1 << side.getIndex();
            }
        }
    }
    return activeNodeConnections;
}
 
Example 2
Source File: FluidPipeRenderer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void handleRenderBlockDamage(IBlockAccess world, BlockPos pos, IBlockState state, TextureAtlasSprite sprite, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setPipeline(new Vector3(new Vec3d(pos)).translation(), new IconTransformation(sprite));
    BlockFluidPipe blockFluidPipe = (BlockFluidPipe) state.getBlock();
    IPipeTile<FluidPipeType, FluidPipeProperties> tileEntityPipe = blockFluidPipe.getPipeTileEntity(world, pos);
    if (tileEntityPipe == null) {
        return;
    }
    FluidPipeType fluidPipeType = tileEntityPipe.getPipeType();
    if (fluidPipeType == null) {
        return;
    }
    float thickness = fluidPipeType.getThickness();
    int connectedSidesMask = blockFluidPipe.getActualConnections(tileEntityPipe, world);
    Cuboid6 baseBox = BlockFluidPipe.getSideBox(null, thickness);
    BlockRenderer.renderCuboid(renderState, baseBox, 0);
    for (EnumFacing renderSide : EnumFacing.VALUES) {
        if ((connectedSidesMask & (1 << renderSide.getIndex())) > 0) {
            Cuboid6 sideBox = BlockFluidPipe.getSideBox(renderSide, thickness);
            BlockRenderer.renderCuboid(renderState, sideBox, 0);
        }
    }
}
 
Example 3
Source File: TileEntityFluidPipeTickable.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void pushFluidsFromTank(IPipeTile<FluidPipeType, FluidPipeProperties> pipeTile) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    int blockedConnections = pipeTile.getBlockedConnections();
    BlockFluidPipe blockFluidPipe = (BlockFluidPipe) pipeTile.getPipeBlock();
    for (EnumFacing side : EnumFacing.VALUES) {
        if ((blockedConnections & 1 << side.getIndex()) > 0) {
            continue; //do not dispatch energy to blocked sides
        }
        blockPos.setPos(pipeTile.getPipePos()).move(side);
        if (!pipeTile.getPipeWorld().isBlockLoaded(blockPos)) {
            continue; //do not allow cables to load chunks
        }
        TileEntity tileEntity = pipeTile.getPipeWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            continue; //do not emit into multiparts or other fluid pipes
        }
        IFluidHandler sourceHandler = pipeTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        IFluidHandler receiverHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite());
        if (sourceHandler != null && receiverHandler != null && blockFluidPipe.canPushIntoFluidHandler(pipeTile, tileEntity, sourceHandler, receiverHandler)) {
            CoverPump.moveHandlerFluids(sourceHandler, receiverHandler, Integer.MAX_VALUE, FLUID_FILTER_ALWAYS_TRUE);
        }
    }
    blockPos.release();
}
 
Example 4
Source File: BlockFluidPipe.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected int getActiveVisualConnections(IPipeTile<FluidPipeType, FluidPipeProperties> selfTile) {
    int activeNodeConnections = 0;
    for (EnumFacing side : EnumFacing.VALUES) {
        BlockPos offsetPos = selfTile.getPipePos().offset(side);
        TileEntity tileEntity = selfTile.getPipeWorld().getTileEntity(offsetPos);
        if(tileEntity != null) {
            EnumFacing opposite = side.getOpposite();
            IFluidHandler sourceHandler = selfTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
            IFluidHandler receivedHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opposite);
            if (sourceHandler != null && receivedHandler != null) {
                activeNodeConnections |= 1 << side.getIndex();
            }
        }
    }
    return activeNodeConnections;
}
 
Example 5
Source File: TileEntityPipeBase.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public final <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
    boolean isCoverable = capability == GregtechTileCapabilities.CAPABILITY_COVERABLE;
    CoverBehavior coverBehavior = facing == null ? null : coverableImplementation.getCoverAtSide(facing);
    T defaultValue = getCapabilityInternal(capability, facing);
    if(isCoverable) {
        return defaultValue;
    }
    if(coverBehavior == null && facing != null) {
        boolean isBlocked = (getBlockedConnections() & 1 << facing.getIndex()) > 0;
        return isBlocked ? null : defaultValue;
    }
    if (coverBehavior != null) {
        return coverBehavior.getCapability(capability, defaultValue);
    }
    return defaultValue;
}
 
Example 6
Source File: CableRenderer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void renderCableCube(int connections, CCRenderState renderState, IVertexOperation[] pipeline, IVertexOperation[] wire, IVertexOperation[] overlays, EnumFacing side, float thickness) {
    if ((connections & 1 << side.getIndex()) > 0) {
        boolean renderFrontSide = (connections & 1 << (6 + side.getIndex())) > 0;
        Cuboid6 cuboid6 = BlockCable.getSideBox(side, thickness);
        for (EnumFacing renderedSide : EnumFacing.VALUES) {
            if (renderedSide == side) {
                if (renderFrontSide) {
                    renderCableSide(renderState, wire, renderedSide, cuboid6);
                    renderCableSide(renderState, overlays, renderedSide, cuboid6);
                }
            } else if (renderedSide != side.getOpposite()) {
                renderCableSide(renderState, pipeline, renderedSide, cuboid6);
            }
        }
    }
}
 
Example 7
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final boolean placeCoverOnSide(EnumFacing side, ItemStack itemStack, CoverDefinition coverDefinition) {
    Preconditions.checkNotNull(side, "side");
    Preconditions.checkNotNull(coverDefinition, "coverDefinition");
    CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, side);
    if (!canPlaceCoverOnSide(side) || !coverBehavior.canAttach()) {
        return false;
    }
    //if cover requires ticking and we're not tickable, update ourselves and redirect call to new tickable tile entity
    boolean requiresTicking = coverBehavior instanceof ITickable;
    if (requiresTicking && !holder.supportsTicking()) {
        IPipeTile<?, ?> newHolderTile = holder.setSupportsTicking();
        return newHolderTile.getCoverableImplementation().placeCoverOnSide(side, itemStack, coverDefinition);
    }
    if (coverBehaviors[side.getIndex()] != null) {
        removeCover(side);
    }
    this.coverBehaviors[side.getIndex()] = coverBehavior;
    coverBehavior.onAttached(itemStack);
    writeCustomData(1, buffer -> {
        buffer.writeByte(side.getIndex());
        buffer.writeVarInt(CoverDefinition.getNetworkIdForCover(coverDefinition));
        coverBehavior.writeInitialSyncData(buffer);
    });
    if (!coverBehavior.canPipePassThrough()) {
        holder.setConnectionBlocked(AttachmentType.COVER, side, true);
    }
    holder.notifyBlockUpdate();
    holder.markAsDirty();
    return true;
}
 
Example 8
Source File: BakedCompositeModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public void add(IBakedModel model, IBlockState state, EnumFacing side, long rand) {
	int index;
	if(side == null) {
		index = 6;
	}
	else {
		index = side.getIndex();
	}

	builders[index].addAll(model.getQuads(state, side, rand));
}
 
Example 9
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final void dropAllCovers() {
    for (EnumFacing coverSide : EnumFacing.VALUES) {
        CoverBehavior coverBehavior = coverBehaviors[coverSide.getIndex()];
        if (coverBehavior == null) continue;
        List<ItemStack> drops = coverBehavior.getDrops();
        coverBehavior.onRemoved();
        for (ItemStack dropStack : drops) {
            Block.spawnAsEntity(getWorld(), getPos(), dropStack);
        }
    }
}
 
Example 10
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void recheckBlockedSides() {
    this.blockedSides = 0;
    for (EnumFacing side : EnumFacing.VALUES) {
        CoverBehavior coverBehavior = getCoverAtSide(side);
        if (coverBehavior == null) continue;
        if (coverBehavior.canPipePassThrough()) continue;
        this.blockedSides |= 1 << side.getIndex();
    }
}
 
Example 11
Source File: GTModelBlock.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected BlockPartFace createBlockFace(EnumFacing side, int layer, boolean color) {
	if (layer == 1) {
		return new BlockPartFace((EnumFacing) null, -1, "", new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F,
				16.0F }, 0));
	}
	return new BlockPartFace((EnumFacing) null, color ? side.getIndex() + layer * 6
			: -1, "", new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F }, 0));
}
 
Example 12
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void readFromNBT(NBTTagCompound data) {
    NBTTagList coversList = data.getTagList("Covers", NBT.TAG_COMPOUND);
    for (int index = 0; index < coversList.tagCount(); index++) {
        NBTTagCompound tagCompound = coversList.getCompoundTagAt(index);
        if (tagCompound.hasKey("CoverId", NBT.TAG_STRING)) {
            EnumFacing coverSide = EnumFacing.VALUES[tagCompound.getByte("Side")];
            ResourceLocation coverId = new ResourceLocation(tagCompound.getString("CoverId"));
            CoverDefinition coverDefinition = CoverDefinition.getCoverById(coverId);
            CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, coverSide);
            coverBehavior.readFromNBT(tagCompound);
            this.coverBehaviors[coverSide.getIndex()] = coverBehavior;
        }
    }
}
 
Example 13
Source File: TileEntityPipeBase.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private int withSideConnectionBlocked(int blockedConnections, EnumFacing side, boolean blocked) {
    int index = 1 << side.getIndex();
    if(blocked) {
        return blockedConnections | index;
    } else {
        return blockedConnections & ~index;
    }
}
 
Example 14
Source File: PositionUtils.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
public static EnumFacing getCWRotationAxis(EnumFacing from, EnumFacing to)
{
    return FROM_TO_CW_ROTATION_AXES[from.getIndex()][to.getIndex()];
}
 
Example 15
Source File: GTModelBlock.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
	return this.quads[side == null ? 6 : side.getIndex()];
}
 
Example 16
Source File: PipeNet.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void updateBlockedConnections(BlockPos nodePos, EnumFacing facing, boolean isBlocked) {
    if (!containsNode(nodePos)) {
        return;
    }
    Node<NodeDataType> selfNode = getNodeAt(nodePos);
    boolean wasBlocked = (selfNode.blockedConnections & 1 << facing.getIndex()) > 0;
    if (wasBlocked == isBlocked) {
        return;
    }
    setBlocked(selfNode, facing, isBlocked);
    BlockPos offsetPos = nodePos.offset(facing);
    PipeNet<NodeDataType> pipeNetAtOffset = worldData.getNetFromPos(offsetPos);
    if (pipeNetAtOffset == null) {
        //if there is no any pipe net at this side,
        //updating blocked status of it won't change anything in any net
        return;
    }
    //if we are on that side of node too
    //and it is blocked now
    if (pipeNetAtOffset == this) {
        //if side was unblocked, well, there is really nothing changed in this e-net
        //if it is blocked now, but was able to connect with neighbour node before, try split networks
        if (isBlocked) {
            //need to unblock node before doing canNodesConnectCheck
            setBlocked(selfNode, facing, false);
            if(canNodesConnect(selfNode, facing, getNodeAt(offsetPos), this)) {
                //now block again to call findAllConnectedBlocks
                setBlocked(selfNode, facing, true);
                HashMap<BlockPos, Node<NodeDataType>> thisENet = findAllConnectedBlocks(nodePos);
                if (!getAllNodes().equals(thisENet)) {
                    //node visibility has changed, split network into 2
                    //node that code below is similar to removeNodeInternal, but only for 2 networks, and without node removal
                    PipeNet<NodeDataType> newPipeNet = worldData.createNetInstance();
                    thisENet.keySet().forEach(this::removeNodeWithoutRebuilding);
                    newPipeNet.transferNodeData(thisENet, this);
                    worldData.addPipeNet(newPipeNet);
                }
            }
        }
        //there is another network on that side
        //if this is an unblock, and we can connect with their node, merge them

    } else if (!isBlocked) {
        Node<NodeDataType> neighbourNode = pipeNetAtOffset.getNodeAt(offsetPos);
        //check connection availability from both networks
        if (canNodesConnect(selfNode, facing, neighbourNode, pipeNetAtOffset) &&
            pipeNetAtOffset.canNodesConnect(neighbourNode, facing.getOpposite(), selfNode, this)) {
            //so, side is unblocked now, and nodes can connect, merge two networks
            //our network consumes other one
            uniteNetworks(pipeNetAtOffset);
        }
    }
    onConnectionsUpdate();
    worldData.markDirty();
}
 
Example 17
Source File: GTModelOre.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
	return this.quads[side == null ? 6 : side.getIndex()];
}
 
Example 18
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public CoverBehavior getCoverAtSide(EnumFacing side) {
    return coverBehaviors[side.getIndex()];
}
 
Example 19
Source File: GTModelMortar.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
	return this.quads[side == null ? 6 : side.getIndex()];
}
 
Example 20
Source File: CTCubeRenderer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean hasFaceBit(int mask, EnumFacing side) {
    return (mask & 1 << side.getIndex()) > 0;
}