下面列出了怎么用net.minecraftforge.common.util.ForgeDirection的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote) {
ticksExisted++;
if(getPressure(ForgeDirection.UNKNOWN) >= PneumaticValues.MIN_PRESSURE_UV_LIGHTBOX && inventory[0] != null && inventory[0].getItem() == Itemss.emptyPCB && inventory[0].getItemDamage() > 0) {
addAir((int)(-PneumaticValues.USAGE_UV_LIGHTBOX * getSpeedUsageMultiplierFromUpgrades(getUpgradeSlots())), ForgeDirection.UNKNOWN);
if(ticksExisted % Math.max(1, (int)(TileEntityConstants.LIGHT_BOX_0_100_TIME / (5 * getSpeedMultiplierFromUpgrades(getUpgradeSlots())))) == 0) {
if(!areLightsOn) {
areLightsOn = true;
updateNeighbours();
}
inventory[0].setItemDamage(Math.max(0, inventory[0].getItemDamage() - 1));
}
} else if(areLightsOn) {
areLightsOn = false;
updateNeighbours();
}
if(oldRedstoneStatus != shouldEmitRedstone()) {
oldRedstoneStatus = !oldRedstoneStatus;
updateNeighbours();
}
}
}
public IHeatExchangerLogic getLogic(World world, int x, int y, int z, ForgeDirection side){
if(!world.blockExists(x, y, z)) return null;
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof IHeatExchanger) {
return ((IHeatExchanger)te).getHeatExchangerLogic(side);
} else {
if(world.isAirBlock(x, y, z)) {
return AIR_EXCHANGER;
} else {
Block block = world.getBlock(x, y, z);
if(block instanceof IHeatExchanger) {
return ((IHeatExchanger)block).getHeatExchangerLogic(side);
} else {
IHeatExchanger exchanger = specialBlockExchangers.get(block);
return exchanger == null ? null : exchanger.getHeatExchangerLogic(side);
}
}
}
}
public int calcConnectionFlags (IBlockAccess world, int x, int y, int z) {
Block blockYNeg = world.getBlock(x, y - 1, z);
Block blockYPos = world.getBlock(x, y + 1, z);
Block blockZNeg = world.getBlock(x, y, z - 1);
Block blockZPos = world.getBlock(x, y, z + 1);
Block blockXNeg = world.getBlock(x - 1, y, z);
Block blockXPos = world.getBlock(x + 1, y, z);
boolean hardYNeg = isNeighborHardConnection(world, x, y - 1, z, blockYNeg, ForgeDirection.DOWN);
boolean hardYPos = isNeighborHardConnection(world, x, y + 1, z, blockYPos, ForgeDirection.UP);
boolean hardZNeg = isNeighborHardConnection(world, x, y, z - 1, blockZNeg, ForgeDirection.NORTH);
boolean hardZPos = isNeighborHardConnection(world, x, y, z + 1, blockZPos, ForgeDirection.SOUTH);
boolean hardXNeg = isNeighborHardConnection(world, x - 1, y, z, blockXNeg, ForgeDirection.WEST);
boolean hardXPos = isNeighborHardConnection(world, x + 1, y, z, blockXPos, ForgeDirection.EAST);
boolean extYNeg = isNeighborExtConnection(world, x, y - 1, z, blockYNeg, ForgeDirection.DOWN);
boolean extYPos = isNeighborExtConnection(world, x, y + 1, z, blockYPos, ForgeDirection.UP);
boolean extZNeg = isNeighborExtConnection(world, x, y, z - 1, blockZNeg, ForgeDirection.NORTH);
boolean extZPos = isNeighborExtConnection(world, x, y, z + 1, blockZPos, ForgeDirection.SOUTH);
boolean extXNeg = isNeighborExtConnection(world, x - 1, y, z, blockXNeg, ForgeDirection.WEST);
boolean extXPos = isNeighborExtConnection(world, x + 1, y, z, blockXPos, ForgeDirection.EAST);
return (hardYNeg ? 1 : 0) | (hardYPos ? 2 : 0) | (hardZNeg ? 4 : 0) | (hardZPos ? 8 : 0) | (hardXNeg ? 16 : 0) | (hardXPos ? 32 : 0)
| (extYNeg ? 64 : 0) | (extYPos ? 128 : 0) | (extZNeg ? 256 : 0) | (extZPos ? 512 : 0) | (extXNeg ? 1024 : 0) | (extXPos ? 2048 : 0);
}
@Override
public void readFromNBT(NBTTagCompound tag){
super.readFromNBT(tag);
progress = tag.getFloat("extension");
opening = tag.getBoolean("opening");
redstoneMode = tag.getInteger("redstoneMode");
orientation = ForgeDirection.getOrientation(tag.getInteger("orientation"));
rightGoing = tag.getBoolean("rightGoing");
// Read in the ItemStacks in the inventory from NBT
NBTTagList tagList = tag.getTagList("Items", 10);
inventory = new ItemStack[getSizeInventory()];
for(int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
byte slot = tagCompound.getByte("Slot");
if(slot >= 0 && slot < inventory.length) {
inventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
}
@Override
public void updateEntity(){
if(!worldObj.isRemote && updateNeighbours) {
updateNeighbours = false;
updateNeighbours();
}
if(!worldObj.isRemote) {
if(getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MIN_PRESSURE_AERIAL_INTERFACE && isConnectedToPlayer) {
if(energyRF != null) tickRF();
addAir(-PneumaticValues.USAGE_AERIAL_INTERFACE, ForgeDirection.UNKNOWN);
if(worldObj.getTotalWorldTime() % 40 == 0) dispenserUpgradeInserted = getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0;
if(worldObj.getTotalWorldTime() % 20 == 0) {
EntityPlayer player = getPlayer();
if(player != null && player.getAir() <= 280) {
player.setAir(player.getAir() + 20);
addAir(-4000, null);
}
}
}
if(worldObj.getTotalWorldTime() % 20 == 0) getPlayerInventory();
}
if(oldRedstoneStatus != shouldEmitRedstone()) {
oldRedstoneStatus = shouldEmitRedstone();
updateNeighbours = true;
}
super.updateEntity();
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack par6ItemStack){
super.onBlockPlacedBy(world, x, y, z, par5EntityLiving, par6ItemStack);
TileEntityVortexTube te = (TileEntityVortexTube)world.getTileEntity(x, y, z);
for(int i = 0; i < 4; i++) {
te.rotateRoll(1);
ForgeDirection d = te.getTubeDirection();
IPneumaticMachine pneumaticMachine = ModInteractionUtils.getInstance().getMachine(world.getTileEntity(x + d.offsetX, y + d.offsetY, z + d.offsetZ));
if(pneumaticMachine != null && pneumaticMachine.isConnectedTo(d.getOpposite())) break;
}
}
@Override
public int addEssentia(Aspect aspect, int i, ForgeDirection direction) {
if(canInputFrom(direction) && canAccept(aspect)) {
TileEssentiaCompressor master = tryFindMasterTile();
if(master == null) return 0;
master.al.add(aspect, i);
worldObj.markBlockForUpdate(master.xCoord, master.yCoord, master.zCoord);
markDirty();
return i;
}
return 0;
}
@Override
public IGridNode getGridNode(ForgeDirection dir) {
// if (getWorld() != null && !getWorld().isRemote) {
// if (node == null)
// node = AEApi.instance().createGridNode(this);
// node.updateState();
// }
return node;
}
/**
* A randomly called display update to be able to add particles or other items for display
*/
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random par5Random)
{
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntityReactorRedstonePort)
{
TileEntityReactorRedstonePort port = (TileEntityReactorRedstonePort)te;
if(port.isRedstoneActive()) {
ForgeDirection out = port.getOutwardsDir();
if(out != ForgeDirection.UNKNOWN) {
double particleX, particleY, particleZ;
particleY = y + 0.45D + par5Random.nextFloat() * 0.1D;
if(out.offsetX > 0)
particleX = x + par5Random.nextFloat() * 0.1D + 1.1D;
else
particleX = x + 0.45D + par5Random.nextFloat() * 0.1D;
if(out.offsetZ > 0)
particleZ = z + par5Random.nextFloat() * 0.1D + 1.1D;
else
particleZ = z + 0.45D + par5Random.nextFloat() * 0.1D;
world.spawnParticle("reddust", particleX, particleY, particleZ, 0.0D, par5Random.nextFloat() * 0.1D, 0.0D);
}
}
}
}
@Override
public IHeatExchangerLogic getHeatExchangerLogic(ForgeDirection side){
if(side == ForgeDirection.UNKNOWN || side == getRotation().getOpposite()) {
return hotHeatExchanger;
} else if(side == getRotation()) {
return coldHeatExchanger;
} else {
return null;
}
}
public static void renderBlade(RenderBlocks renderer, int x, int y, int z, Block block, int metadata, ForgeDirection rotorDir) {
if(rotorDir == ForgeDirection.UNKNOWN) {
rotorDir = ForgeDirection.UP;
}
double xMin, yMin, zMin, xMax, yMax, zMax;
xMin = yMin = zMin = 0D;
xMax = yMax = zMax = 1D;
if(rotorDir.offsetX != 0) {
xMin = 0.45D;
xMax = 0.55D;
}
else if(rotorDir.offsetY != 0) {
yMin = 0.45D;
yMax = 0.55D;
}
else if(rotorDir.offsetZ != 0) {
zMin = 0.45D;
zMax = 0.55D;
}
Tessellator.instance.setColorRGBA(255, 255, 255, 255);
renderer.setRenderBoundsFromBlock(block);
renderer.setOverrideBlockTexture(null);
renderer.setRenderBounds(xMin, yMin, zMin, xMax, yMax, zMax);
renderer.renderFaceYNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 0, metadata));
renderer.setRenderBounds(xMin, yMin, zMin, xMax, yMax, zMax);
renderer.renderFaceYPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 1, metadata));
renderer.setRenderBounds(xMin, yMin, zMin, xMax, yMax, zMax);
renderer.renderFaceZNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 2, metadata));
renderer.setRenderBounds(xMin, yMin, zMin, xMax, yMax, zMax);
renderer.renderFaceZPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 3, metadata));
renderer.setRenderBounds(xMin, yMin, zMin, xMax, yMax, zMax);
renderer.renderFaceXNeg(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 4, metadata));
renderer.setRenderBounds(xMin, yMin, zMin, xMax, yMax, zMax);
renderer.renderFaceXPos(block, x, y, z, renderer.getBlockIconFromSideAndMetadata(block, 5, metadata));
renderer.setRenderBounds(0D, 0D, 0D, 1D, 1D, 1D);
}
@Override
public Aspect getEssentiaType(ForgeDirection paramForgeDirection) {
if(isValid()) {
syncToParent();
Aspect result = parent.getEssentiaType(changeDirection(paramForgeDirection));
syncFromParent();
return result;
}
return null;
}
@Override
public void drawEnergy(double amount){
int efficiency = Config.pneumaticGeneratorEfficiency;
if(efficiency < 1) efficiency = 1;
int airUsage = (int)(amount / 0.25F * 100F / efficiency);
addAir(-airUsage, ForgeDirection.UNKNOWN);
heatExchanger.addHeat(airUsage / 40);
outputting = true;
curEnergyProduction = (int)amount;
}
@Override
public boolean cultivate(int x, int y, int z, ForgeDirection d, int extent){
for(int i = 0; i < extent; i++) {
if(tryPlaceSoil(x + d.offsetX * i, y + d.offsetY * i - 2, z + d.offsetZ * i)) return true;
}
for(int i = 0; i < extent; i++) {
if(manageCrops(x + d.offsetX * i, y + d.offsetY * i - 3, z + d.offsetZ * i)) return true;
}
return false;
}
@Override
public void setEmittingRedstone(ForgeDirection side, int value){
if(emittingRedstoneValues[side.ordinal()] != value) {
emittingRedstoneValues[side.ordinal()] = value;
worldObj.notifyBlocksOfNeighborChange((int)Math.floor(posX + width / 2), (int)Math.floor(posY), (int)Math.floor(posZ + width / 2), Blockss.droneRedstoneEmitter);
}
}
public TileEntityBeefBase() {
super();
facing = ForgeDirection.NORTH.ordinal();
exposures = new int[6];
for(int i = 0; i < exposures.length; i++) {
exposures[i] = SIDE_UNEXPOSED;
}
ticksSinceLastUpdate = 0;
updatePlayers = new HashSet<EntityPlayer>();
}
private boolean isNeighborHardConnectionY (IBlockAccess world, int x, int y, int z, Block block, ForgeDirection side) {
if (isNeighborHardConnection(world, x, y, z, block, side))
return true;
return block instanceof BlockLeavesBase
|| block == ModBlocks.thinLogFence;
}
public static TileEntityCache[] getDefaultCache(World world, int x, int y, int z){
TileEntityCache[] cache = new TileEntityCache[6];
for(int i = 0; i < 6; i++) {
ForgeDirection d = ForgeDirection.getOrientation(i);
cache[i] = new TileEntityCache(world, x + d.offsetX, y + d.offsetY, z + d.offsetZ);
}
return cache;
}
public Position(double ci, double cj, double ck, ForgeDirection corientation) {
x = ci;
y = cj;
z = ck;
orientation = corientation;
if (orientation == null) {
orientation = ForgeDirection.UNKNOWN;
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
TileEntityPneumaticDoorBase doorBase = getDoorBase(world, x, y, z);
if(!world.isRemote && doorBase != null && doorBase.redstoneMode == 2 && doorBase.getPressure(ForgeDirection.UNKNOWN) >= PneumaticValues.MIN_PRESSURE_PNEUMATIC_DOOR) {
doorBase.setOpening(!doorBase.isOpening());
doorBase.setNeighborOpening(doorBase.isOpening());
return true;
}
return false;
}
public static void addModuleInfo(List<String> currenttip, TileEntityPressureTube tube, NBTTagCompound tubeTag, ForgeDirection dir){
if(dir != ForgeDirection.UNKNOWN) {
NBTTagList moduleList = tubeTag.getTagList("modules", 10);
for(int i = 0; i < moduleList.tagCount(); i++) {
NBTTagCompound moduleTag = moduleList.getCompoundTagAt(i);
if(dir == ForgeDirection.getOrientation(moduleTag.getInteger("side"))) {
if(tube != null && tube.modules[dir.ordinal()] != null) {
TubeModule module = tube.modules[dir.ordinal()];
module.readFromNBT(moduleTag);
module.addInfo(currenttip);
}
}
}
}
}
public ForgeDirection changeDirection(ForgeDirection face) {
if(placedOn == ForgeDirection.UP) {
if(face == ForgeDirection.UP || face == ForgeDirection.DOWN) {
return face.getOpposite();
}
return face;
}
if(placedOn == ForgeDirection.DOWN) {
return face;
}
if(face == ForgeDirection.UP) {
return ForgeDirection.NORTH;
}
if(face == ForgeDirection.DOWN) {
return ForgeDirection.SOUTH;
}
if(face == placedOn) {
return ForgeDirection.DOWN;
}
if(face == placedOn.getOpposite()) {
return ForgeDirection.UP;
}
switch (placedOn) {
case EAST: return face == ForgeDirection.NORTH ? ForgeDirection.WEST : ForgeDirection.EAST;
case SOUTH: return face.getOpposite();
case WEST: return face == ForgeDirection.SOUTH ? ForgeDirection.WEST : ForgeDirection.EAST;
}
return face;
}
@Override
public boolean canOutputTo(ForgeDirection direction) {
if(isMultiblockFormed() && multiblockYIndex == 1) { //The middle one
return direction == ForgeDirection.SOUTH ||
direction == ForgeDirection.NORTH ||
direction == ForgeDirection.EAST ||
direction == ForgeDirection.WEST;
}
return false;
}
@Override
public void updateEntity(){
for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if(Blockss.droneRedstoneEmitter.isProvidingWeakPower(worldObj, xCoord, yCoord, zCoord, d.ordinal()) > 0) {
return;
}
}
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
private void updateDoorSide(TileEntityPneumaticDoorBase doorBase){
TileEntity teDoor = doorBase.getWorldObj().getTileEntity(doorBase.xCoord + doorBase.orientation.offsetX, doorBase.yCoord, doorBase.zCoord + doorBase.orientation.offsetZ);
if(teDoor instanceof TileEntityPneumaticDoor) {
TileEntityPneumaticDoor door = (TileEntityPneumaticDoor)teDoor;
if(doorBase.orientation.getRotation(ForgeDirection.UP) == ForgeDirection.getOrientation(door.getBlockMetadata() % 6) && door.rightGoing || doorBase.orientation.getRotation(ForgeDirection.DOWN) == ForgeDirection.getOrientation(door.getBlockMetadata() % 6) && !door.rightGoing) {
door.rightGoing = !door.rightGoing;
door.setRotation(0);
}
}
}
@Override
public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int meta)
{
ForgeDirection dir = ForgeDirection.getOrientation(meta);
return (dir == NORTH && world.getBlock(x, y, z + 1).isSideSolid(world, x, y, z + 1, NORTH)) ||
(dir == SOUTH && world.getBlock(x, y, z - 1).isSideSolid(world, x, y, z - 1, SOUTH)) ||
(dir == WEST && world.getBlock(x + 1, y, z).isSideSolid(world, x + 1, y, z, WEST )) ||
(dir == EAST && world.getBlock(x - 1, y, z).isSideSolid(world, x - 1, y, z, EAST ));
}
@Override
public boolean shouldTrackWithThisEntry(IBlockAccess world, int x, int y, int z, Block block, TileEntity te){
if(te instanceof IEnergyConnection) {
IEnergyConnection connection = (IEnergyConnection)te;
for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if(connection.canConnectEnergy(d)) return true;
}
}
return false;
}
/** This will be called by the Reactor Controller when this tap should be providing power.
* @return Power units remaining after consumption.
*/
public int onProvidePower(int units) {
if(rfNetwork == null) {
return units;
}
ForgeDirection approachDirection = getOutwardsDir().getOpposite();
int energyConsumed = rfNetwork.receiveEnergy(approachDirection, (int)units, false);
units -= energyConsumed;
return units;
}
@Override
public boolean rotateBlock(World world, EntityPlayer player, int x, int y, int z, ForgeDirection side){
if(player.isSneaking()) {
return super.rotateBlock(world, player, x, y, z, side);
} else {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityPneumaticDoorBase) {
TileEntityPneumaticDoorBase teDb = (TileEntityPneumaticDoorBase)te;
teDb.orientation = teDb.orientation.getRotation(ForgeDirection.UP);
return true;
}
return false;
}
}
/** Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
*
* This method is not Fluid-sensitive.
* @param from Orientation the fluid is drained to.
* @param maxDrain Maximum amount of fluid to drain.
* @param doDrain If false draining will only be simulated.
* @return FluidStack representing the fluid and amount actually drained from the ITankContainer
*/
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
int tankToDrain = 0;
if(from != ForgeDirection.UNKNOWN) {
tankToDrain = getExposedTankFromSide(from.ordinal());
}
if(tankToDrain <= FLUIDTANK_NONE) {
return null;
} else {
return drain(tankToDrain, maxDrain, doDrain);
}
}