public void rotateEngine() { for (int i = getOrientation().ordinal() + 1; i <= getOrientation().ordinal() + 6; ++i) { ForgeDirection orient = ForgeDirection.values()[i % 6]; Position pos = new Position(xCoord, yCoord, zCoord, orient); pos.moveForwards(1.0F); TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); if (BlockUtil.isPoweredTile(tile)) { setOrientation(orient); worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); break; } } }
/** * Override how this work, normally liquids never have a solid top surface... * BUT if we where called by the native fire handling mechanism then we should * pretend that we do... so that we can burn */ @Override public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) { /* We inspect the stack to see if we have been called indirectly by any of the fire handling routines. If so pretend to have a solid top surface so that the fire can stay on this block. * Note the special circumstances that forces us to do this stack based hack, it would make most software engineers cry - but works well for our purpose (not modifying any base-classes). */ if (!canBurn) return false; StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); if (stackTraceElements.length < 7) return false; StackTraceElement caller = stackTraceElements[6]; if (caller.getClassName().equals(Block.fire.getClass().getName())) { return true; } if (stackTraceElements.length < 7) return false; StackTraceElement caller8 = stackTraceElements[8]; if (caller8.getClassName().equals(Block.fire.getClass().getName())) { return true; } return false; }
public GuiPropolisPipe(EntityPlayer player, Pipe pipe) { super(Defaults.TEXTURE_PATH_GUI + "/analyzer.png", new ContainerPropolisPipe(player.inventory, pipe)); pipeLogic = (PipeLogicPropolis) pipe.logic; // Request filter set update if on client if (!Proxies.common.isSimulating(pipe.worldObj)) { pipeLogic.requestFilterSet(); } xSize = 175; ySize = 225; for (int i = 0; i < 6; i++) { slotManager.add(new TypeFilterSlot(8, 18 + i * 18, ForgeDirection.values()[i], pipeLogic)); } IApiaristTracker tracker = BeeManager.breedingManager.getApiaristTracker(player.worldObj, player.username); for (int i = 0; i < 6; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 2; k++) { slotManager.add(new SpeciesFilterSlot(tracker, 44 + j * 45 + k * 18, 18 + i * 18, ForgeDirection.values()[i], j, k, pipeLogic)); } } } }
@Override public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID) { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (world.getBlockId(x + side.offsetX, y + side.offsetY, z + side.offsetZ) == this.blockID) { if (this.passBlockChange(world, new Vector3(x, y, z), new ArrayList<Vector3>())) return; } else if (world.getBlockId(x + side.offsetX, y + side.offsetY, z + side.offsetZ) == ModBlocks.factoryController.blockID) { ModBlocks.factoryController.onNeighborBlockChange(world, x + side.offsetX, y + side.offsetY, z + side.offsetZ, world.getBlockId(x, y, z)); return; } } }
public boolean renderLeft() { if(worldObj == null) { return true; } ForgeDirection left = getLeftSide(); TileEntity en = worldObj.getBlockTileEntity(xCoord + left.offsetX, yCoord + left.offsetY, zCoord + left.offsetZ); if(en != null && en instanceof TileEntityRoast) { if(((TileEntityRoast)en).direction == direction) { return false; } } return true; }
@Override public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) { // We only accept what is already in the tank or valid ingredients if (resourceTank.quantity > 0 && resourceTank.liquidId != resource.itemID) return 0; else if (resource.itemID != ForestryItem.liquidHoney.itemID) return 0; int used = resourceTank.fill(resource, doFill); if (doFill && used > 0) { sendNetworkUpdate(); } return used; }
/** * Gets the direction the face is at(Opposite to the placer) */ public ForgeDirection getFront() { if(direction == 0)//SOUTH PLACE { return ForgeDirection.NORTH; } if(direction == 1)//WEST PLACE { return ForgeDirection.EAST; } if(direction == 2)//NORTH PLACE { return ForgeDirection.SOUTH; } if(direction == 3)//EAST PLACE { return ForgeDirection.WEST; } return ForgeDirection.UNKNOWN; }
@Override public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) { world = housing.getWorld(); Stack<ICrop> crops = new Stack<ICrop>(); for(int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y + 1, z, direction, i); for(IFarmable seed : germlings) { ICrop crop = seed.getCropAt(world, position.x, position.y, position.z); if(crop != null) crops.push(crop); } } return crops; }
@Override public void registerIcons(IconRegister registry) { Icons.top = registry.registerIcon("examplemod:top"); Icons.bottom = registry.registerIcon("examplemod:bottom"); Icons.front = registry.registerIcon("examplemod:front"); Icons.back = registry.registerIcon("examplemod:back"); Icons.left = registry.registerIcon("examplemod:left"); Icons.right = registry.registerIcon("examplemod:right"); setTexture(ForgeDirection.EAST, Icons.left); setTexture(ForgeDirection.WEST, Icons.right); setTexture(ForgeDirection.SOUTH, Icons.front); setTexture(ForgeDirection.NORTH, Icons.back); setTexture(ForgeDirection.UP, Icons.top); setTexture(ForgeDirection.DOWN, Icons.bottom); setDefaultTexture(Icons.front); }
/** * Searches for inventories adjacent to block, excludes IPowerReceptor * * @return */ public static IInventory[] getAdjacentInventories(World world, Vect blockPos, ForgeDirection from) { ArrayList<IInventory> inventories = new ArrayList<IInventory>(); for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { if(from != ForgeDirection.UNKNOWN && from != dir.getOpposite()) continue; TileEntity entity = world.getBlockTileEntity(blockPos.x + dir.offsetX, blockPos.y + dir.offsetY, blockPos.z + dir.offsetZ); if (entity != null) if (entity instanceof IInventory) if (!(entity instanceof IPowerReceptor)) { inventories.add((IInventory) entity); } } return inventories.toArray(new IInventory[inventories.size()]); }
@Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); orientation = ForgeDirection.getOrientation(tagCompound.getInteger("Orientation")); validMultiblock = tagCompound.getBoolean("ValidMultiblock"); progressing = tagCompound.getBoolean("IsProgressing"); progress = tagCompound.getInteger("Progress"); NBTTagList tagList = tagCompound.getTagList("Items"); inventory = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < tagList.tagCount(); ++i) { NBTTagCompound compound = (NBTTagCompound) tagList.tagAt(i); byte slotIndex = compound.getByte("Slot"); if (slotIndex >= 0 && slotIndex < inventory.length) { inventory[slotIndex] = ItemStack.loadItemStackFromNBT(compound); } } if (tagCompound.hasKey("EnergyPosition")) { int[] coords = tagCompound.getIntArray("EnergyPosition"); energyPos = new Vector3(coords[0], coords[1], coords[2]); } }
private void dumpToPipe(ForgeDirection[] pipes) { for (int i = SLOT_WASTE_1; i < SLOT_WASTE_1 + SLOT_WASTE_COUNT; i++) { if (inventory.getStackInSlot(i) == null) { continue; } if (inventory.getStackInSlot(i).stackSize <= 0) { continue; } ForgeDirection[] filtered; filtered = BlockUtil.filterPipeDirections(pipes, new ForgeDirection[] { getOrientation() }); while (inventory.getStackInSlot(i).stackSize > 0 && filtered.length > 0) { BlockUtil.putFromStackIntoPipe(this, filtered, inventory.getStackInSlot(i)); } if (inventory.getStackInSlot(i).stackSize <= 0) { inventory.setInventorySlotContents(i, null); } } }
public boolean matchType(ForgeDirection orientation, EnumFilterType type, IBee bee) { EnumFilterType filter = typeFilter[orientation.ordinal()]; if (filter == EnumFilterType.BEE) return type != EnumFilterType.ITEM && type != EnumFilterType.CLOSED && type != EnumFilterType.CLOSED; // Special bee filtering if (bee != null) { if (filter == EnumFilterType.PURE_BREED) return bee.isPureBred(EnumBeeChromosome.SPECIES); if (filter == EnumFilterType.NOCTURNAL) return bee.getGenome().getNocturnal(); if (filter == EnumFilterType.PURE_NOCTURNAL) return bee.getGenome().getNocturnal() && bee.isPureBred(EnumBeeChromosome.NOCTURNAL); if (filter == EnumFilterType.FLYER) return bee.getGenome().getTolerantFlyer(); if (filter == EnumFilterType.PURE_FLYER) return bee.getGenome().getTolerantFlyer() && bee.isPureBred(EnumBeeChromosome.TOLERANT_FLYER); if (filter == EnumFilterType.CAVE) return bee.getGenome().getCaveDwelling(); if (filter == EnumFilterType.PURE_CAVE) return bee.getGenome().getCaveDwelling() && bee.isPureBred(EnumBeeChromosome.CAVE_DWELLING); } // Compare the remaining return filter == type; }
@Override public int getStartInventorySide(ForgeDirection side) { switch(side) { case UP: return TileFarmPlain.SLOT_GERMLINGS_1; case DOWN: return TileFarmPlain.SLOT_PRODUCTION_1; case NORTH: case SOUTH: return TileFarmPlain.SLOT_RESOURCES_1; case WEST: case EAST: return TileFarmPlain.SLOT_FERTILIZER; default: return 0; } }
@Override public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { ItemStack product = null; for (int i = outputSlot1; i < inventory.getSizeInventory(); i++) { if (inventory.getStackInSlot(i) == null) { continue; } product = getStackInSlot(i).copy(); if (doRemove) { getStackInSlot(i).stackSize = 0; setInventorySlotContents(i, null); } break; } return new ItemStack[] { product }; }
@Override public int getStartInventorySide(ForgeDirection side) { switch (side) { case DOWN: return TradeStation.SLOT_LETTERS_1; case UP: return TradeStation.SLOT_STAMPS_1; case NORTH: case SOUTH: return TradeStation.SLOT_INPUTBUF_1; case EAST: case WEST: return TradeStation.SLOT_OUTPUTBUF_1; default: return 0; } }
@Override public void onInsertion(int slot, TileEntity tile) { if(!isCircuitable(tile)) return; FarmLogic logic = null; try { logic = logicClass.getConstructor(new Class[] { IFarmHousing.class }).newInstance(new Object[] { (IFarmHousing)tile }); } catch (Exception ex) { throw new RuntimeException("Failed to instantiate logic of class " + logicClass.getName() + ": " + ex.getMessage()); } if(logic != null) { if(isManual) logic.setManual(isManual); ((IFarmHousing)tile).setFarmLogic(ForgeDirection.values()[slot + 2], logic); } }
@Override public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { if (inventoryStacks[resourceSlot] == null) { if (doAdd) { inventoryStacks[resourceSlot] = stack.copy(); } return stack.stackSize; } if (!inventoryStacks[resourceSlot].isItemEqual(stack)) return 0; int space = inventoryStacks[resourceSlot].getMaxStackSize() - inventoryStacks[resourceSlot].stackSize; if (space <= 0) return 0; if (doAdd) if (stack.stackSize <= space) { inventoryStacks[resourceSlot].stackSize += stack.stackSize; } else { inventoryStacks[resourceSlot].stackSize += space; } return Math.min(stack.stackSize, space); }
/** * Returns true if automation can extract the given item in the given slot from the given side. Args: Slot, item, side */ @Override public boolean canExtractItem(int slot, ItemStack item, int side) { // Convert the int direction into valid forge direction. ForgeDirection dir = ForgeDirection.getOrientation( side ); // Grab a list of all container values from enumeration. ContainerTemplate[] containerSlots = this.getRegisteredMachine().getContainerTemplate(); if (containerSlots == null) { // Abort if there are no container slots. return false; } // Loop through all the gathered slots. int i = containerSlots.length; for (int j = 0; j < i; ++ j) { // Check if they match the side we decoded from parameter. ContainerTemplate currentContainer = containerSlots[j]; if (currentContainer.getExtractDirection().equals( dir ) && currentContainer.canExtract()) { // Allows the item to be extracted from the given slot. return true; } } // Default response is to return nothing! return false; }
@Override public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) { int used = resourceTank.fill(resource, doFill); if (doFill && used > 0) { // TODO: Slow down updates tile.sendNetworkUpdate(); } return used; }
@Override public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { // We only accept empty water containers LiquidContainerData container = LiquidHelper.getEmptyContainer(stack, new LiquidStack(Block.waterStill, 1)); if (container == null) return 0; if (inventoryStacks[SLOT_RESOURCE] == null) { if (doAdd) { inventoryStacks[SLOT_RESOURCE] = stack.copy(); } return stack.stackSize; } if (inventoryStacks[SLOT_RESOURCE].stackSize >= inventoryStacks[SLOT_RESOURCE].getMaxStackSize()) return 0; if (!inventoryStacks[SLOT_RESOURCE].isItemEqual(stack)) return 0; // Determine available space int space = getInventoryStackLimit() - inventoryStacks[SLOT_RESOURCE].stackSize; if (space >= stack.stackSize) { if (doAdd) { inventoryStacks[SLOT_RESOURCE].stackSize += stack.stackSize; } return stack.stackSize; } else { if (doAdd) { inventoryStacks[SLOT_RESOURCE].stackSize = getInventoryStackLimit(); stack.stackSize -= space; } return space; } }
/** * Adds humus and saplings to the appropriate free slots of the arboretum. Does not care where the stuff comes from. * * @param stack * @param doAdd * @param from * @return */ @Override public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { // Humus if (stack.isItemEqual(validSoil)) return inventory.addStack(stack, SLOT_SOIL_1, SLOT_COUNT_PART, false, doAdd); if (hasGermlingBySeed(stack)) return inventory.addStack(stack, SLOT_GERMLING_1, SLOT_COUNT_PART, false, doAdd); return 0; }
@Override public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { LiquidContainerData container = LiquidHelper.getLiquidContainer(stack); if (container == null) return 0; return inventory.addStack(stack, false, doAdd); }
@Override public void onRemoval(int slot, TileEntity tile) { if(!isCircuitable(tile)) return; ((IFarmHousing)tile).resetFarmLogic(ForgeDirection.values()[slot + 2]); }
public ArrayList<IAllele[]> getGenomeFilters(ForgeDirection orientation) { ArrayList<IAllele[]> filters = new ArrayList(); for (int i = 0; i < 3; i++) if (genomeFilter[orientation.ordinal()][i] != null && (genomeFilter[orientation.ordinal()][i][0] != null || genomeFilter[orientation.ordinal()][i][1] != null)) { filters.add(genomeFilter[orientation.ordinal()][i]); } return filters; }
public ForgeDirection getExtractDirection() { if (this.extractSide != null) { return this.extractSide; } else { return ForgeDirection.UNKNOWN; } }
/** * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return * True if something happen and false if it don't. This is for ITEMS, not BLOCKS */ public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { if (par7 != 1) { return false; } else if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)) { int i1 = par3World.getBlockId(par4, par5, par6); Block soil = Block.blocksList[i1]; if (soil != null && soil.canSustainPlant(par3World, par4, par5, par6, ForgeDirection.UP, this) && par3World.isAirBlock(par4, par5 + 1, par6)) { par3World.setBlock(par4, par5 + 1, par6, this.cropId); --par1ItemStack.stackSize; return true; } else { return false; } } else { return false; } }
public static ItemStack addToInsertion(Object theTile, int side, ItemStack stack) { if (stack == null) { return null; } if (theTile instanceof IInventory) { stack = insertItemStackIntoInventory((IInventory) theTile, stack, BlockHelper.SIDE_OPPOSITE[side]); } else { stack = ((IItemConduit) theTile).insertItem(ForgeDirection.VALID_DIRECTIONS[side ^ 1], stack); } return stack; }
public SpeciesFilterSlot(IApiaristTracker tracker, int x, int y, ForgeDirection orientation, int pattern, int allele, PipeLogicPropolis logic) { super(slotManager, x, y); this.tracker = tracker; this.orientation = orientation; this.pattern = pattern; this.allele = allele; this.logic = logic; }
public boolean isBlockValidForSide(ForgeDirection side) { if(worldObj == null) { return false; } int x = xCoord + side.offsetX; int y = yCoord + side.offsetY; int z = zCoord + side.offsetZ; return isBlockValidForSide(x, y, z); }
public WorldCoord subtract(ForgeDirection direction, int length) { x -= direction.offsetX * length; y -= direction.offsetY * length; z -= direction.offsetZ * length; return this; }
@Override public int getStartInventorySide(ForgeDirection side) { // BOTTOM if (side == ForgeDirection.DOWN) return SLOT_DRONE; // TOP else if (side == ForgeDirection.UP) return SLOT_QUEEN; // SIDES else return SLOT_PRODUCT_1; }
@Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { if (resource == null || !resource.isFluidEqual(tank.getFluid())) { return null; } return tank.drain(resource.amount, doDrain); }
/** * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata */ public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) { int j1 = par1World.getBlockMetadata(par2, par3, par4); int k1 = j1 & 8; j1 &= 7; ForgeDirection dir = ForgeDirection.getOrientation(par5); if (dir == NORTH && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH)) { j1 = 4; } else if (dir == SOUTH && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH)) { j1 = 3; } else if (dir == WEST && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST)) { j1 = 2; } else if (dir == EAST && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST)) { j1 = 1; } else { j1 = this.getOrientation(par1World, par2, par3, par4); } return j1 + k1; }
/** * Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants. */ public boolean canBlockStay(World par1World, int par2, int par3, int par4) { Block soil = blocksList[par1World.getBlockId(par2, par3 - 1, par4)]; return (par1World.getFullBlockLightValue(par2, par3, par4) >= 8 || par1World.canBlockSeeTheSky(par2, par3, par4)) && (soil != null && soil.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this)); }
@Override public void update() { if (!MiscPeripherals.proxy.isServer()) return; if (++ticker >= 20) { Vec3 pos = turtle.getPosition(); if (pos != null) { ticker = 0; World world = turtle.getWorld(); if (world != null) { int x = (int)Math.floor(pos.xCoord); int y = (int)Math.floor(pos.yCoord); int z = (int)Math.floor(pos.zCoord); if (MiscPeripherals.instance.sideSensitive) { ForgeDirection dir = Util.getDirectionFromTurtleSide(side, turtle.getFacingDir()); x += dir.offsetX; y += dir.offsetY; z += dir.offsetZ; } skyVisible = !world.provider.hasNoSky && world.canBlockSeeTheSky(x, y, z); sunVisible = world.isDaytime() && skyVisible && (world.getWorldChunkManager().getBiomeGenAt(x, z) instanceof BiomeGenDesert || (!world.isRaining() && !world.isThundering())); } } } if (canUpdate()) { euBuffer += getProduction(); while (euBuffer >= MiscPeripherals.instance.fuelEU) { euBuffer -= MiscPeripherals.instance.fuelEU * Util.addFuel(turtle, 1); } } }
private boolean hasRedstoneSignal(ForgeDirection direction) { Vect side = new Vect(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ); ForgeDirection opp = direction.getOpposite(); int dir = opp.offsetZ < 0 ? 2 : opp.offsetZ > 0 ? 3 : opp.offsetX < 0 ? 4 : opp.offsetX > 0 ? 5 : 0; return worldObj.isBlockIndirectlyProvidingPowerTo(side.x, side.y, side.z, dir) || worldObj.isBlockProvidingPowerTo(side.x, side.y, side.z, dir); }
@Override public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { ItemStack product; if (inventoryStacks[outputSlot] != null) { product = new ItemStack(inventoryStacks[outputSlot].itemID, 1, inventoryStacks[outputSlot].getItemDamage()); if (doRemove) { inventoryStacks[outputSlot].stackSize--; if (inventoryStacks[outputSlot].stackSize <= 0) { inventoryStacks[outputSlot] = null; } } return new ItemStack[] { product }; } else { if (inventoryStacks[remnantSlot] == null) return new ItemStack[0]; product = new ItemStack(inventoryStacks[remnantSlot].itemID, 1, inventoryStacks[remnantSlot].getItemDamage()); if (doRemove) { inventoryStacks[remnantSlot].stackSize--; if (inventoryStacks[remnantSlot].stackSize <= 0) { inventoryStacks[remnantSlot] = null; } } return new ItemStack[] { product }; } }