@Optional.Method(modid = ModIds.IGWMOD) private void onIGWAction() { int x = lastMouseX; int y = lastMouseY; IProgWidget hoveredWidget = programmerUnit.getHoveredWidget(x, y); if(hoveredWidget != null) { WikiRegistry.getWikiHooks().showWikiGui("pneumaticcraft:progwidget/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, hoveredWidget.getWidgetString())); } for(IProgWidget widget : visibleSpawnWidgets) { if(widget != draggingWidget && x - guiLeft >= widget.getX() && y - guiTop >= widget.getY() && x - guiLeft <= widget.getX() + widget.getWidth() / 2 && y - guiTop <= widget.getY() + widget.getHeight() / 2) { WikiRegistry.getWikiHooks().showWikiGui("pneumaticcraft:progwidget/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, widget.getWidgetString())); } } }
@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.getWorld().equals(getWorld()) && tother.getPos().equals(getPos()); } return false; }
@Override @Optional.Method(modid = "theoneprobe") public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) { TileEntity te = world.getTileEntity(data.getPos()); if(te instanceof IInfoForwarder){ te = ((IInfoForwarder)te).getInfoTileEntity(); } if (te instanceof IPneumaticMachine) { TOPCallback.handlePneumatic(mode, probeInfo, (IPneumaticMachine)te); } if (te instanceof IHeatExchanger) { TOPCallback.handleHeat(mode, probeInfo, (IHeatExchanger) te); } if (ConfigHandler.client.topShowsFluids && te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, data.getSideHit())) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, data.getSideHit()); TOPCallback.handleFluidTanks(mode, probeInfo, handler); } if (te instanceof TileEntityBase) { TOPCallback.handleRedstoneMode(mode, probeInfo, (TileEntityBase) te); } if (te instanceof TileEntityPressureTube) { TOPCallback.handlePressureTube(mode, probeInfo, (TileEntityPressureTube) te, data.getSideHit()); } }
@Optional.Method(modid = "redstoneflux") private int attemptFERFTransfer(EnumFacing face, int maxTransferLeft) { BlockPos at = this.getPos().offset(face); EnumFacing accessingSide = face.getOpposite(); int receivedEnergy = 0; TileEntity te = world.getTileEntity(at); if(te != null && !(te instanceof TileEnergyHatch)) { if(te instanceof cofh.redstoneflux.api.IEnergyReceiver && ((IEnergyReceiver) te).canConnectEnergy(accessingSide)) { receivedEnergy = ((IEnergyReceiver) te).receiveEnergy(accessingSide, maxTransferLeft, false); } if(receivedEnergy <= 0 && te instanceof IEnergyStorage) { receivedEnergy = ((IEnergyStorage) te).receiveEnergy(maxTransferLeft, false); } if(receivedEnergy <= 0 && te.hasCapability(CapabilityEnergy.ENERGY, accessingSide)) { net.minecraftforge.energy.IEnergyStorage ce = te.getCapability(CapabilityEnergy.ENERGY, accessingSide); if(ce != null && ce.canReceive()) { receivedEnergy = ce.receiveEnergy(maxTransferLeft, false); } } } return receivedEnergy; }
@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().grid().createGridConnection(((IGridHost)te).getGridNode(null), getGridNode(null)); } catch(FailedConnectionException e) { Log.error("Couldn't connect to an ME Interface!"); e.printStackTrace(); } } } return false; }
@Override @Optional.Method(modid = ModIds.AE2) public void onRequestChange(ICraftingGrid grid, IAEItemStack aeStack){ craftingGrid = grid; int freeSlot = -1; for(int i = 0; i < getFilters().getSlots(); i++) { ItemStack s = getFilters().getStackInSlot(i); if(!s.isEmpty()) { if(aeStack.isSameType(s)) { s.setCount( (int) aeStack.getStackSize() ); return; } } else if(freeSlot == -1) { freeSlot = i; } } if(freeSlot >= 0) { getFilters().setStackInSlot(freeSlot, aeStack.createItemStack()); } }
@Override @Optional.Method(modid = ModIds.AE2) public void onStackChange(IItemList arg0, IAEStack arg1, IAEStack arg2, IActionSource arg3, IStorageChannel arg4){ if(craftingGrid != null) { ICraftingGrid grid = (ICraftingGrid)craftingGrid; for(int i = 0; i < getFilters().getSlots(); i++) { ItemStack s = getFilters().getStackInSlot(i); if(!s.isEmpty()) { if(!grid.isRequesting(AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack(s))) { getFilters().setStackInSlot(i, ItemStack.EMPTY); notifyNetworkOfCraftingChange(); } } } } }
@Optional.Method(modid = Compats.IC2) @Override public void onArmorTick(World world, EntityPlayer player, ItemStack stack) { boolean shouldUpdate = false; // If we wear some air mask on head. if (this.isAirMask && this.armorType == EntityEquipmentSlot.HEAD) { // Default max value is 300 if ((player.getAir() <= minAirToStartRefil) && (player.inventory.hasItemStack(ItemsCG.ic2AirCell))) { consumeItemFromInventory(player, ItemsCG.ic2AirCell); player.inventory.addItemStackToInventory(new ItemStack(ItemsCG.ic2EmptyCell.getItem())); player.setAir(300); shouldUpdate = true; } } // If we have changed inventory contents then we should sync it on client. if (shouldUpdate) { player.inventoryContainer.detectAndSendChanges(); } }
@Override @Optional.Method(modid = ModIds.OPEN_COMPUTERS) public Object[] invoke(String method, Context context, Arguments args) throws Exception { if ("greet".equals(method)) return new Object[]{String.format("Hello, %s!", args.checkString(0))}; for (ILuaMethod m : luaMethods) { if (m.getMethodName().equals(method)) { return m.call(args.toArray()); } } throw new IllegalArgumentException("Can't invoke method with name \"" + method + "\". not registered"); }
@Override @Optional.Method(modid = ModIds.COMPUTERCRAFT) public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException { try { return luaMethods.get(method).call(arguments); } catch (Exception e) { throw new LuaException(e.getMessage()); } }
/** * Produce an peripheral implementation from a block location. * * @return a peripheral, or null if there is not a peripheral here you'd like to handle. * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) */ @Override @Optional.Method(modid = ModIds.COMPUTERCRAFT) public IPeripheral getPeripheral(World world, BlockPos pos, EnumFacing side) { TileEntity te = world.getTileEntity(pos); return te instanceof IPeripheral ? (IPeripheral) te : null; }
@Override @Optional.Method(modid = "theoneprobe") public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) { super.addProbeInfo(mode, probeInfo, player, world, blockState, data); IBlockState camo = getCamoState(world, data.getPos()); if (camo != null) { TOPCallback.handleCamo(mode, probeInfo, camo); } }
@Override @Optional.Method(modid = ModIds.COMPUTERCRAFT) public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException { try { return luaMethods.get(method).call(arguments); } catch (Exception e) { throw new LuaException(e.getMessage()); } }
/** * Called on a event sensor * * @param arguments */ @Optional.Method(modid = ModIds.COMPUTERCRAFT) private void notifyComputers(Object... arguments) { for(IComputerAccess computer : attachedComputers) { computer.queueEvent(getType(), arguments); } }
@Override @Optional.Method(modid = ModIds.AE2) public void handleGUIButtonPress(int guiID, EntityPlayer player){ if(guiID == 1) { aeMode = !aeMode; needToCheckForInterface = aeMode; if(!aeMode && gridNode != null) { disconnectFromInterface(); } } super.handleGUIButtonPress(guiID, player); }
@Override @Optional.Method(modid = ModIds.AE2) public void invalidate(){ super.invalidate(); if(gridNode != null) { disconnectFromInterface(); } }
@Override @Optional.Method(modid = "ic2") public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) { double addable = Math.min((getMaxEnergy() - getCurrentEnergy()) / 4, amount); amount -= addable; this.energy = MathHelper.clamp(this.energy + MathHelper.floor(addable * 4), 0, this.size.maxEnergy); markForUpdate(); return amount; }
@Override @Optional.Method(modid = "ic2") public void invalidate() { super.invalidate(); if(!world.isRemote) { MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); } }
@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)); } }
@Optional.Method(modid = ModIds.AE2) public List<IAEItemStack> getProvidingItems(){ List<IAEItemStack> stacks = new ArrayList<IAEItemStack>(); for(TileEntity te : providingInventories.keySet()) { IItemHandler inv = IOHelper.getInventoryForTE(te); if(inv != null) { for(int i = 0; i < inv.getSlots(); i++) { ItemStack stack = inv.getStackInSlot(i); if(!stack.isEmpty()) stacks.add(AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack(stack)); } } } return stacks; }
@Override @Optional.Method(modid = ModIds.AE2) public List<IMEInventoryHandler> getCellArray(IStorageChannel channel){ if(channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class )) { return Arrays.asList((IMEInventoryHandler)this); } else { return new ArrayList<IMEInventoryHandler>(); } }
@Override @Optional.Method(modid = ModIds.AE2) public TickRateModulation tickingRequest(IGridNode arg0, int arg1){ notifyNetworkOfCraftingChange(); if(gridNode != null) { getGridNode(null).getGrid().postEvent(new MENetworkCellArrayUpdate());//Doing it on interval, as doing it right after AEApi.instance().createGridConnection doesn't seem to work.. } return TickRateModulation.SAME; }
@Optional.Method(modid = "mekanism") private boolean checkMekanismGasCapabilitiesPresence(Capability<?> capability, @Nullable EnumFacing facing) { if(super.hasCapability(capability, facing)) { return checkMekanismGasCapabilities(capability, facing); } return false; }
@Override @Optional.Method(modid = ModIds.AE2) public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> arg0){ for(IAEItemStack stack : getProvidingItems()) { stack.setCountRequestable(stack.getStackSize()); arg0.addRequestable(stack); } return arg0; }
@Optional.Method(modid = "mekanism") private ComponentRequirement deserializeMekanismGasRequirement(MachineComponent.IOType machineIoType, JsonObject requirement) throws JsonParseException { if(!requirement.has("gas") || !requirement.get("gas").isJsonPrimitive() || !requirement.get("gas").getAsJsonPrimitive().isString()) { throw new JsonParseException("The ComponentType 'gas' expects an 'gas'-entry that defines the type of gas!"); } if(!requirement.has("amount") || !requirement.get("amount").isJsonPrimitive() || !requirement.get("amount").getAsJsonPrimitive().isNumber()) { throw new JsonParseException("The ComponentType 'gas' expects an 'amount'-entry that defines the type of gas!"); } String gasName = requirement.getAsJsonPrimitive("gas").getAsString(); int mbAmount = requirement.getAsJsonPrimitive("amount").getAsInt(); Gas gas = GasRegistry.getGas(gasName); if(gas == null) { throw new JsonParseException("The gas specified in the 'gas'-entry (" + gasName + ") doesn't exist!"); } mbAmount = Math.max(0, mbAmount); GasStack gasStack = new GasStack(gas, mbAmount); ComponentRequirement.RequirementFluid req = ComponentRequirement.RequirementFluid.createMekanismGasRequirement(machineIoType, gasStack); if(requirement.has("chance")) { if(!requirement.get("chance").isJsonPrimitive() || !requirement.getAsJsonPrimitive("chance").isNumber()) { throw new JsonParseException("'chance', if defined, needs to be a chance-number between 0 and 1!"); } float chance = requirement.getAsJsonPrimitive("chance").getAsFloat(); if(chance >= 0 && chance <= 1) { req.setChance(chance); } } return req; }
@Override @Optional.Method(modid = "mekanism") public int receiveGas(EnumFacing side, GasStack stack, boolean doTransfer) { if(this.tank instanceof HybridGasTank) { return ((HybridGasTank) this.tank).receiveGas(side, stack, doTransfer); } return 0; }
@Optional.Method(modid = "tconstruct") public static void init() { TinkerRegistry.registerMelting(new MeltingRecipe(RecipeMatch.of(ModBlocks.butter, 1000), ModFluids.liquid_butter, 300)); TinkerRegistry.registerBasinCasting(new CastingRecipe(new ItemStack(ModBlocks.butter), ModFluids.liquid_butter, 1000, 60)); if (Loader.isModLoaded("xlfoodmod")) { TinkerRegistry.registerMelting(new MeltingRecipe(RecipeMatch.of(ItemListxlfoodmod.butter, 250), ModFluids.liquid_butter, 200)); TinkerRegistry.registerTableCasting(new CastingRecipe(new ItemStack(ItemListxlfoodmod.butter), RecipeMatch.of(TinkerSmeltery.castIngot), ModFluids.liquid_butter, 250, 15)); } }
@Optional.Method(modid = "immersiveengineering") public static void init() { if (Loader.isModLoaded("mysticalagriculture")) { BelljarHandler.registerBasicItemFertilizer(new ItemStack(ModItems.itemMysticalFertilizer), 2.25f); } }
@Optional.Method(modid = "thermalexpansion") public static void init() { CompressionManager.addFuel("liquid_butter", 64000); CrucibleManager.addRecipe(10000, new ItemStack(ModItems.butter), new FluidStack(ModFluids.liquid_butter, 1000)); if (Loader.isModLoaded("xlfoodmod")) { CrucibleManager.addRecipe(2500, new ItemStack(ItemListxlfoodmod.butter), new FluidStack(ModFluids.liquid_butter, 250)); } }
@Override @Optional.Method(modid = "baubles") public void onWornTick(ItemStack stack, EntityLivingBase player) { if (player.world.isRemote) return; if (stack.getItemDamage()==1) { if (player.getBrightness() < 0.4375f) { player.addPotionEffect(new PotionEffect(POTION_INVIS, 5)); } } }
@Optional.Method(modid = "dynamiclights") public static void removeSource(){ Iterator<MuzzleFlashLightSource> iterator = muzzleFlashes.iterator(); while (iterator.hasNext()) { MuzzleFlashLightSource light = iterator.next(); light.update(); if (light.over) { DynamicLights.removeLightSource(light); iterator.remove(); } } }
@Optional.Method(modid = "mekanism") private void drawMekTooltip(int x, int z) { List<String> text = Lists.newArrayList(); FluidStack content = tank.getTank().getFluid(); int amt; if(content == null || content.amount <= 0) { if(tank.getTank() instanceof HybridGasTank) { GasStack gasContent = ((HybridGasTank) tank.getTank()).getGas(); if(gasContent == null || gasContent.amount <= 0) { text.add(I18n.format("tooltip.fluidhatch.empty")); amt = 0; text.add(I18n.format("tooltip.fluidhatch.tank", String.valueOf(amt), String.valueOf(tank.getTank().getCapacity()))); } else { if(ModularMachinery.isMekanismLoaded) { text.add(I18n.format("tooltip.fluidhatch.gas")); } text.add(gasContent.getGas().getLocalizedName()); amt = gasContent.amount; text.add(I18n.format("tooltip.fluidhatch.tank.gas", String.valueOf(amt), String.valueOf(tank.getTank().getCapacity()))); } } else { text.add(I18n.format("tooltip.fluidhatch.empty")); amt = 0; text.add(I18n.format("tooltip.fluidhatch.tank", String.valueOf(amt), String.valueOf(tank.getTank().getCapacity()))); } } else { if(ModularMachinery.isMekanismLoaded) { text.add(I18n.format("tooltip.fluidhatch.fluid")); } text.add(content.getLocalizedName()); amt = content.amount; text.add(I18n.format("tooltip.fluidhatch.tank", String.valueOf(amt), String.valueOf(tank.getTank().getCapacity()))); } FontRenderer font = Minecraft.getMinecraft().fontRenderer; drawHoveringText(text, x, z, (font == null ? fontRenderer : font)); }
@Override @Optional.Method(modid = "mekanism") public GasStack drawGas(EnumFacing side, int amount, boolean doTransfer) { if(this.tank instanceof HybridGasTank) { return ((HybridGasTank) this.tank).drawGas(side, amount, doTransfer); } return null; }
@Optional.Method(modid = "mekanism") private String getGasDisplayName(T ingredient) { if(ingredient instanceof HybridFluidGas) { IIngredientHelper<GasStack> gasHelper = ModIntegrationJEI.ingredientRegistry.getIngredientHelper(GasStack.class); return gasHelper.getDisplayName(((HybridFluidGas) ingredient).asGasStack()); } return null; }
@Optional.Method(modid = "mekanism") private String gasGasUniqueId(T ingredient) { if(ingredient instanceof HybridFluidGas) { IIngredientHelper<GasStack> gasHelper = ModIntegrationJEI.ingredientRegistry.getIngredientHelper(GasStack.class); return gasHelper.getUniqueId(((HybridFluidGas) ingredient).asGasStack()); } return null; }
@Optional.Method(modid = "mekanism") private String getGasWildcardId(T ingredient) { if(ingredient instanceof HybridFluidGas) { IIngredientHelper<GasStack> gasHelper = ModIntegrationJEI.ingredientRegistry.getIngredientHelper(GasStack.class); return gasHelper.getWildcardId(((HybridFluidGas) ingredient).asGasStack()); } return null; }
@Optional.Method(modid = "mekanism") private String getGasModId(T ingredient) { if(ingredient instanceof HybridFluidGas) { IIngredientHelper<GasStack> gasHelper = ModIntegrationJEI.ingredientRegistry.getIngredientHelper(GasStack.class); return gasHelper.getModId(((HybridFluidGas) ingredient).asGasStack()); } return null; }
@Optional.Method(modid = "mekanism") private Iterable<Color> getGasColors(T ingredient) { if(ingredient instanceof HybridFluidGas) { IIngredientHelper<GasStack> gasHelper = ModIntegrationJEI.ingredientRegistry.getIngredientHelper(GasStack.class); return gasHelper.getColors(((HybridFluidGas) ingredient).asGasStack()); } return null; }
@Optional.Method(modid = "mekanism") private String getGasResourceId(T ingredient) { if(ingredient instanceof HybridFluidGas) { IIngredientHelper<GasStack> gasHelper = ModIntegrationJEI.ingredientRegistry.getIngredientHelper(GasStack.class); return gasHelper.getResourceId(((HybridFluidGas) ingredient).asGasStack()); } return null; }