Search in sources :

Example 1 with LuaFunction

use of dan200.computercraft.api.lua.LuaFunction in project AdvancedPeripherals by Seniorendi.

the class ColonyPeripheral method getBuildings.

@LuaFunction(mainThread = true)
public final Object getBuildings() throws LuaException {
    IColony colony = getColony();
    IBuildingManager manager = colony.getBuildingManager();
    List<Object> buildingData = new ArrayList<>();
    for (Map.Entry<BlockPos, IBuilding> building : manager.getBuildings().entrySet()) {
        buildingData.add(MineColonies.buildingToObject(manager, building.getValue(), building.getKey()));
    }
    return buildingData;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) IBuildingManager(com.minecolonies.api.colony.managers.interfaces.IBuildingManager) LuaFunction(dan200.computercraft.api.lua.LuaFunction)

Example 2 with LuaFunction

use of dan200.computercraft.api.lua.LuaFunction in project AdvancedPeripherals by Seniorendi.

the class ColonyPeripheral method getWorkOrderResources.

@LuaFunction(mainThread = true)
public final Object getWorkOrderResources(int id) throws LuaException {
    IColony colony = getColony();
    IWorkOrder workOrder = colony.getWorkManager().getWorkOrder(id);
    if (workOrder == null)
        return null;
    return MineColonies.builderResourcesToObject(colony, workOrder.getClaimedBy());
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) IColony(com.minecolonies.api.colony.IColony) LuaFunction(dan200.computercraft.api.lua.LuaFunction)

Example 3 with LuaFunction

use of dan200.computercraft.api.lua.LuaFunction in project AdvancedPeripherals by Seniorendi.

the class ColonyPeripheral method getCitizens.

@LuaFunction(mainThread = true)
public final Object getCitizens() throws LuaException {
    IColony colony = getColony();
    List<Object> list = new ArrayList<>();
    colony.getCitizenManager().getCitizens().forEach(citizen -> {
        list.add(MineColonies.citizenToObject(citizen));
    });
    return list;
}
Also used : IColony(com.minecolonies.api.colony.IColony) LuaFunction(dan200.computercraft.api.lua.LuaFunction)

Example 4 with LuaFunction

use of dan200.computercraft.api.lua.LuaFunction in project AdvancedPeripherals by Seniorendi.

the class ColonyPeripheral method getWorkOrders.

@LuaFunction(mainThread = true)
public final Object getWorkOrders() throws LuaException {
    IColony colony = getColony();
    List<Object> worksData = new ArrayList<>();
    for (IWorkOrder workOrder : colony.getWorkManager().getWorkOrders().values()) worksData.add(MineColonies.workOrderToObject(workOrder));
    return worksData;
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) IColony(com.minecolonies.api.colony.IColony) LuaFunction(dan200.computercraft.api.lua.LuaFunction)

Example 5 with LuaFunction

use of dan200.computercraft.api.lua.LuaFunction in project AdvancedPeripherals by Seniorendi.

the class EnvironmentDetectorPeripheral method scanEntities.

@LuaFunction(mainThread = true)
public final MethodResult scanEntities(@Nonnull IComputerAccess access, @Nonnull IArguments arguments) throws LuaException {
    int radius = arguments.getInt(0);
    return withOperation(SCAN_ENTITIES, new SphereOperationContext(radius), context -> {
        if (radius > SCAN_ENTITIES.getMaxCostRadius()) {
            return MethodResult.of(null, "Radius is exceed max value");
        }
        return null;
    }, context -> {
        BlockPos pos = owner.getPos();
        AxisAlignedBB box = new AxisAlignedBB(pos);
        List<Map<String, Object>> entities = new ArrayList<>();
        getWorld().getEntities((Entity) null, box.inflate(radius), entity -> entity instanceof LivingEntity).forEach(entity -> entities.add(LuaConverter.completeEntityWithPositionToLua(entity, ItemStack.EMPTY, pos)));
        return MethodResult.of(entities);
    }, null);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ITurtleAccess(dan200.computercraft.api.turtle.ITurtleAccess) SphereOperationContext(de.srendi.advancedperipherals.common.addons.computercraft.operations.SphereOperationContext) MethodResult(dan200.computercraft.api.lua.MethodResult) java.util(java.util) LuaException(dan200.computercraft.api.lua.LuaException) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PeripheralTileEntity(de.srendi.advancedperipherals.common.blocks.base.PeripheralTileEntity) SharedSeedRandom(net.minecraft.util.SharedSeedRandom) Function(java.util.function.Function) ItemStack(net.minecraft.item.ItemStack) ServerLifecycleHooks(net.minecraftforge.fml.server.ServerLifecycleHooks) PocketPeripheralOwner(de.srendi.advancedperipherals.lib.peripherals.owner.PocketPeripheralOwner) IArguments(dan200.computercraft.api.lua.IArguments) APConfig(de.srendi.advancedperipherals.common.configuration.APConfig) SCAN_ENTITIES(de.srendi.advancedperipherals.common.addons.computercraft.operations.SphereOperation.SCAN_ENTITIES) BasePeripheral(de.srendi.advancedperipherals.lib.peripherals.BasePeripheral) TurtlePeripheralOwner(de.srendi.advancedperipherals.lib.peripherals.owner.TurtlePeripheralOwner) Nonnull(javax.annotation.Nonnull) ISeedReader(net.minecraft.world.ISeedReader) LightType(net.minecraft.world.LightType) LuaFunction(dan200.computercraft.api.lua.LuaFunction) Entity(net.minecraft.entity.Entity) IPeripheralPlugin(de.srendi.advancedperipherals.lib.peripherals.IPeripheralPlugin) TileEntityPeripheralOwner(de.srendi.advancedperipherals.lib.peripherals.owner.TileEntityPeripheralOwner) IPocketAccess(dan200.computercraft.api.pocket.IPocketAccess) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) TurtleSide(dan200.computercraft.api.turtle.TurtleSide) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) IPeripheralOwner(de.srendi.advancedperipherals.lib.peripherals.owner.IPeripheralOwner) IComputerAccess(dan200.computercraft.api.peripheral.IComputerAccess) MathHelper(net.minecraft.util.math.MathHelper) LuaConverter(de.srendi.advancedperipherals.common.util.LuaConverter) LivingEntity(net.minecraft.entity.LivingEntity) PeripheralTileEntity(de.srendi.advancedperipherals.common.blocks.base.PeripheralTileEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) SphereOperationContext(de.srendi.advancedperipherals.common.addons.computercraft.operations.SphereOperationContext) BlockPos(net.minecraft.util.math.BlockPos) LuaFunction(dan200.computercraft.api.lua.LuaFunction)

Aggregations

LuaFunction (dan200.computercraft.api.lua.LuaFunction)71 ItemStack (net.minecraft.item.ItemStack)19 LuaException (dan200.computercraft.api.lua.LuaException)15 BlockPos (net.minecraft.util.math.BlockPos)13 HashMap (java.util.HashMap)12 TurtlePeripheralOwner (de.srendi.advancedperipherals.lib.peripherals.owner.TurtlePeripheralOwner)11 IColony (com.minecolonies.api.colony.IColony)9 CompoundNBT (net.minecraft.nbt.CompoundNBT)9 MethodResult (dan200.computercraft.api.lua.MethodResult)8 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)8 ResourceLocation (net.minecraft.util.ResourceLocation)8 TileEntity (net.minecraft.tileentity.TileEntity)6 Direction (net.minecraft.util.Direction)6 IItemHandler (net.minecraftforge.items.IItemHandler)6 IFormattableTextComponent (net.minecraft.util.text.IFormattableTextComponent)4 World (net.minecraft.world.World)4 IStorageGrid (appeng.api.networking.storage.IStorageGrid)3 IItemStorageChannel (appeng.api.storage.channels.IItemStorageChannel)3 IAEItemStack (appeng.api.storage.data.IAEItemStack)3 IDrawer (com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer)3