cpw.mods.fml.common.Optional Java Examples

The following examples show how to use cpw.mods.fml.common.Optional. 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: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 7 votes vote down vote up
@Optional.Method(modid = ModIds.AE2)
private boolean checkForInterface(){
    if(isPlacedOnInterface()) {
        TileEntity te = getTileEntity();
        if(te instanceof IGridHost) {
            if(((IGridHost)te).getGridNode(null) == null) return true;
            if(getGridNode(null) == null) return true;
            try {
                AEApi.instance().createGridConnection(getGridNode(null), ((IGridHost)te).getGridNode(null));
            } catch(FailedConnection e) {
                Log.error("Couldn't connect to an ME Interface!");
                e.printStackTrace();
            }
        }
    }
    return false;
}
 
Example #2
Source File: TileEntityBase.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.COMPUTERCRAFT)
public boolean equals(IPeripheral other){
    if(other == null) {
        return false;
    }
    if(this == other) {
        return true;
    }
    if(other instanceof TileEntity) {
        TileEntity tother = (TileEntity)other;
        return tother.getWorldObj().equals(worldObj) && tother.xCoord == xCoord && tother.yCoord == yCoord && tother.zCoord == zCoord;
    }

    return false;
}
 
Example #3
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.AE2)
public void update(){
    super.update();

    if(!world.isRemote) {
        if(needToCheckForInterface) {
            if(Loader.isModLoaded(ModIds.AE2) && !world.isRemote && aeMode && gridNode == null) {
                needToCheckForInterface = checkForInterface();
            } else {
                needToCheckForInterface = false;
            }
        }

        Iterator<Map.Entry<TileEntity, Integer>> iterator = providingInventories.entrySet().iterator();
        while(iterator.hasNext()) {
            Map.Entry<TileEntity, Integer> entry = iterator.next();
            if(entry.getValue() == 0 || entry.getKey().isInvalid()) {
                iterator.remove();
            } else {
                entry.setValue(entry.getValue() - 1);
            }
        }
    }
}
 
Example #4
Source File: GuiPneumaticContainerBase.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.NEI)
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility){
    for(IGuiWidget w : widgets) {
        if(w instanceof IGuiAnimatedStat) {
            IGuiAnimatedStat stat = (IGuiAnimatedStat)w;
            if(stat.isLeftSided()) {
                if(stat.getWidth() > 20) {
                    currentVisibility.showUtilityButtons = false;
                    currentVisibility.showStateButtons = false;
                }
            } else {
                if(stat.getAffectedY() < 10) {
                    currentVisibility.showWidgets = false;
                }
            }
        }
    }
    return currentVisibility;
}
 
Example #5
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.AE2)
public void onStackChange(IItemList arg0, IAEStack arg1, IAEStack arg2, BaseActionSource arg3, StorageChannel arg4){
    if(craftingGrid != null) {
        ICraftingGrid grid = (ICraftingGrid)craftingGrid;
        for(int i = 0; i < getFilters().getSizeInventory(); i++) {
            ItemStack s = getFilters().getStackInSlot(i);
            if(s != null) {
                if(!grid.isRequesting(AEApi.instance().storage().createItemStack(s))) {
                    getFilters().setInventorySlotContents(i, null);
                    notifyNetworkOfCraftingChange();
                }
            }
        }
    }
}
 
Example #6
Source File: BlockReactorPart.java    From BigReactors with MIT License 6 votes vote down vote up
@Optional.Method(modid = "MineFactoryReloaded")
@Override
public int[] getOutputValues(World world, int x, int y, int z,
		ForgeDirection side) {
	TileEntity te = world.getTileEntity(x, y, z);
	if(te instanceof TileEntityReactorRedNetPort) {
		return ((TileEntityReactorRedNetPort)te).getOutputValues();
	}
	else {
		int[] values = new int[16];
		for(int i = 0; i < 16; i++) {
			values[i] = 0;
		}
		return values;
	}
}
 
Example #7
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.AE2)
public void onRequestChange(ICraftingGrid grid, IAEItemStack aeStack){
    craftingGrid = grid;
    ItemStack stack = aeStack.getItemStack().copy();
    int freeSlot = -1;
    for(int i = 0; i < getFilters().getSizeInventory(); i++) {
        ItemStack s = getFilters().getStackInSlot(i);
        if(s != null) {
            if(stack.isItemEqual(s)) {
                s.stackSize = stack.stackSize;
                if(s.stackSize == 0) getFilters().setInventorySlotContents(i, null);
                return;
            }
        } else if(freeSlot == -1) {
            freeSlot = i;
        }
    }
    if(freeSlot >= 0) {
        getFilters().setInventorySlotContents(freeSlot, stack.copy());
    }
}
 
Example #8
Source File: TileEntityTurbineComputerPort.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(final String method, final Context context,
					   final Arguments args) throws Exception {
	final Object[] arguments = new Object[args.count()];
	for (int i = 0; i < args.count(); ++i) {
		arguments[i] = args.checkAny(i);
	}
	final Integer methodId = methodIds.get(method);
	if (methodId == null) {
		throw new NoSuchMethodError();
	}
	return callMethod(methodId, arguments);
}
 
Example #9
Source File: BlockReactorRedstonePort.java    From BigReactors with MIT License 5 votes vote down vote up
@Optional.Method(modid = "MineFactoryReloaded")
@Override
public void onInputChanged(World world, int x, int y, int z,
		ForgeDirection side, int inputValue) {
	TileEntity te = world.getTileEntity(x, y, z);
	if(te instanceof TileEntityReactorRedstonePort) {
		TileEntityReactorRedstonePort port = (TileEntityReactorRedstonePort)te;
		port.onRedNetUpdate(inputValue);
	}
}
 
Example #10
Source File: NEIbartworksConfig.java    From bartworks with MIT License 5 votes vote down vote up
@Optional.Method(modid = "NotEnoughItems")
    @Override
    public void loadConfig() {
        API.hideItem(new ItemStack(ItemRegistry.TAB));
        API.hideItem(new ItemStack(FluidLoader.bioFluidBlock));
        API.hideItem(new ItemStack(ItemRegistry.bw_fake_glasses));
        ItemStack[] prefixesToHide = {
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustTiny, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustSmall, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushed, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedPurified, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedCentrifuged, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.nugget, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemChipped, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawed, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawless, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemExquisite, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustImpure, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustPure, WerkstoffLoader.Bismutite).copy(),
        };
        for (ItemStack stack : prefixesToHide) {
            stack.setItemDamage(Short.MAX_VALUE);
            API.hideItem(stack);
        }
//        for (int i = 0; i < Short.MAX_VALUE; i++) {
//            API.addItemListEntry(new ItemStack(WerkstoffLoader.BWOres,1,i));
//        }
    }
 
Example #11
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Optional.Method(modid = ModIds.AE2)
private void updateProvidingItems(ICraftingProviderHelper cHelper){
    IStackWatcher sWatcher = (IStackWatcher)stackWatcher;
    ICraftingWatcher cWatcher = (ICraftingWatcher)craftingWatcher;
    if(sWatcher != null) sWatcher.clear();
    if(cWatcher != null) cWatcher.clear();
    for(IAEItemStack stack : getProvidingItems()) {
        if(sWatcher != null) sWatcher.add(stack);
        if(cWatcher != null) cWatcher.add(stack);
        if(cHelper != null) cHelper.setEmitable(stack);
    }
}
 
Example #12
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.AE2)
public void invalidate(){
    super.invalidate();
    if(gridNode != null) {
        disconnectFromInterface();
    }
}
 
Example #13
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Optional.Method(modid = ModIds.AE2)
private void notifyNetworkOfCraftingChange(){
    if(gridNode != null) {
        IGrid grid = ((IGridNode)gridNode).getGrid();
        if(grid != null) grid.postEvent(new MENetworkCraftingPatternChange(this, (IGridNode)gridNode));
    }
}
 
Example #14
Source File: GT_TileEntity_MegaBlastFurnace.java    From bartworks with MIT License 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Optional.Method(modid = "tectech")
private boolean areThingsProperlyTiered(Collection collection) {
    if (!collection.isEmpty())
        for (Object tecTechEnergyMulti : collection)
            if (((GT_MetaTileEntity_TieredMachineBlock) tecTechEnergyMulti).mTier > this.glasTier)
                return false;
    return true;
}
 
Example #15
Source File: GT_TileEntity_MegaBlastFurnace.java    From bartworks with MIT License 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Optional.Method(modid = "tectech")
private boolean areLazorsLowPowa() {
    Collection collection = this.getTecTechEnergyTunnels();
    if (!collection.isEmpty())
        for (Object tecTechEnergyMulti : collection)
            if (!(tecTechEnergyMulti instanceof LowPowerLaser))
                return false;
    return true;
}
 
Example #16
Source File: BlockTurbinePart.java    From BigReactors with MIT License 5 votes vote down vote up
@Optional.Method(modid = "ComputerCraft")
@Override
public IPeripheral getPeripheral(World world, int x, int y, int z, int side) {
	TileEntity te = world.getTileEntity(x, y, z);
	
	if(te instanceof TileEntityTurbineComputerPort)
		return (IPeripheral)te;
	
	return null;
}
 
Example #17
Source File: BlockReactorPart.java    From BigReactors with MIT License 5 votes vote down vote up
@Optional.Method(modid = "MineFactoryReloaded")
@Override
public int getOutputValue(World world, int x, int y, int z,
		ForgeDirection side, int subnet) {
	TileEntity te = world.getTileEntity(x, y, z);
	if(te instanceof TileEntityReactorRedNetPort) {
		return ((TileEntityReactorRedNetPort)te).getValueForChannel(subnet);
	}
	return 0;
}
 
Example #18
Source File: TileEntityUniversalSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called on a event sensor
 * @param newRedstoneStrength
 */
@Optional.Method(modid = ModIds.COMPUTERCRAFT)
private void notifyComputers(Object... arguments){
    for(IComputerAccess computer : attachedComputers) {
        computer.queueEvent(getType(), arguments);
    }
}
 
Example #19
Source File: TileEntityTurbineComputerPort.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
       try {
           return callMethod(method, arguments);
       } catch(Exception e) {
       	BRLog.info("Exception encountered when invoking computercraft method: %s", e.getMessage());
           e.printStackTrace();
       }
       return null;
   }
 
Example #20
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.AE2)
public List<IMEInventoryHandler> getCellArray(StorageChannel channel){
    if(channel == StorageChannel.ITEMS) {
        return Arrays.asList((IMEInventoryHandler)this);
    } else {
        return new ArrayList<IMEInventoryHandler>();
    }
}
 
Example #21
Source File: TileEntityBase.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Optional.Method(modid = ModIds.INDUSTRIALCRAFT)
protected int getIC2Upgrades(String ic2ItemKey, int[] upgradeSlots){
    ItemStack itemStack = IC2Items.getItem(ic2ItemKey);
    if(itemStack == null) return 0;
    int upgrades = 0;
    if(this instanceof IInventory) {// this always should be true.
        IInventory inv = (IInventory)this;
        for(int i : upgradeSlots) {
            if(inv.getStackInSlot(i) != null && inv.getStackInSlot(i).getItem() == itemStack.getItem()) {
                upgrades += inv.getStackInSlot(i).stackSize;
            }
        }
    }
    return upgrades;
}
 
Example #22
Source File: ModInteractionUtilImplementation.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.FMP)
public TileEntityPressureTube getTube(Object potentialTube){
    if(potentialTube instanceof PartPressureTube) {
        return ((PartPressureTube)potentialTube).getTube();
    } else if(potentialTube instanceof TileMultipart) {
        PartPressureTube tube = FMP.getMultiPart((TileMultipart)potentialTube, PartPressureTube.class);
        return tube != null ? tube.getTube() : null;
    } else {
        return super.getTube(potentialTube);
    }
}
 
Example #23
Source File: TileEntityReactorComputerPort.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(final String method, final Context context,
					   final Arguments args) throws Exception {
	final Object[] arguments = new Object[args.count()];
	for (int i = 0; i < args.count(); ++i) {
		arguments[i] = args.checkAny(i);
	}
	final Integer methodId = methodIds.get(method);
	if (methodId == null) {
		throw new NoSuchMethodError();
	}
	return callMethod(methodId, arguments);
}
 
Example #24
Source File: TileEntityReactorComputerPort.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
	// Convention for OC names is a) lower case, b) valid variable names,
	// so this can be used as `component.br_reactor.setActive(true)` e.g.
	return "br_reactor";
}
 
Example #25
Source File: TileEntityReactorComputerPort.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException {
       try {
           return callMethod(method, arguments);
       } catch(Exception e) {
       	// Rethrow errors as LuaExceptions for CC
       	throw new LuaException(e.getMessage());
       }
   }
 
Example #26
Source File: TubeModule.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Optional.Method(modid = ModIds.FMP)
public void writeDesc(MCDataOutput data){
    data.writeInt(dir.ordinal());
}
 
Example #27
Source File: TileEntityPressureTube.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Optional.Method(modid = ModIds.FMP)
public void updatePart(){
    ((PartPressureTube)part).onNeighborChanged();
}
 
Example #28
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.AE2)
public IGridNode getActionableNode(){
    return getGridNode(null);
}
 
Example #29
Source File: TileEntityTurbineComputerPort.java    From BigReactors with MIT License 4 votes vote down vote up
@Override
@Optional.Method(modid = "ComputerCraft")
public String[] getMethodNames() {
	return methodNames;
}
 
Example #30
Source File: TileEntityReactorComputerPort.java    From BigReactors with MIT License 4 votes vote down vote up
@Override
@Optional.Method(modid = "ComputerCraft")
public void detach(IComputerAccess computer) {
}