Search in sources :

Example 1 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class ElevatorSounds method stopSound.

public static void stopSound(World worldObj, BlockPos pos) {
    GlobalCoordinate g = new GlobalCoordinate(pos, worldObj.provider.getDimension());
    if (sounds.containsKey(g)) {
        MovingSound movingSound = sounds.get(g);
        Minecraft.getMinecraft().getSoundHandler().stopSound(movingSound);
        sounds.remove(g);
    }
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) MovingSound(net.minecraft.client.audio.MovingSound)

Example 2 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class ElevatorSounds method isStopPlaying.

public static boolean isStopPlaying(World worldObj, BlockPos pos) {
    GlobalCoordinate g = new GlobalCoordinate(pos, worldObj.provider.getDimension());
    MovingSound movingSound = sounds.get(g);
    return movingSound instanceof ElevatorStopSound;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) MovingSound(net.minecraft.client.audio.MovingSound)

Example 3 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class NoTeleportAreaManager method isTeleportPrevented.

public static boolean isTeleportPrevented(Entity entity, GlobalCoordinate coordinate) {
    if (areas.isEmpty()) {
        return false;
    }
    List<GlobalCoordinate> toRemove = new ArrayList<>();
    boolean noTeleport = false;
    long curtime = System.currentTimeMillis() - 10000;
    for (Map.Entry<GlobalCoordinate, NoTeleportArea> entry : areas.entrySet()) {
        NoTeleportArea area = entry.getValue();
        GlobalCoordinate entryCoordinate = entry.getKey();
        if (area.in(coordinate, entryCoordinate)) {
            World world = mcjty.lib.varia.TeleportationTools.getWorldForDimension(entryCoordinate.getDimension());
            TileEntity te = world.getTileEntity(entryCoordinate.getCoordinate());
            if (te instanceof EnvironmentalControllerTileEntity) {
                EnvironmentalControllerTileEntity controllerTileEntity = (EnvironmentalControllerTileEntity) te;
                noTeleport = controllerTileEntity.isEntityAffected(entity);
            }
        }
        if (area.getLastTouched() < curtime) {
            // Hasn't been touched for at least 10 seconds. Probably no longer valid.
            // To be sure we will first check this by testing if the environmental controller is still active and running.
            WorldServer world = DimensionManager.getWorld(entryCoordinate.getDimension());
            if (world != null) {
                BlockPos c = entryCoordinate.getCoordinate();
                // If the world is not loaded we don't do anything and we also don't remove the area since we have no information about it.
                if (RFToolsTools.chunkLoaded(world, c)) {
                    boolean removeArea = true;
                    TileEntity te = world.getTileEntity(c);
                    if (te instanceof EnvironmentalControllerTileEntity) {
                        EnvironmentalControllerTileEntity controllerTileEntity = (EnvironmentalControllerTileEntity) te;
                        for (EnvironmentModule module : controllerTileEntity.getEnvironmentModules()) {
                            if (module instanceof NoTeleportEModule) {
                                if (((NoTeleportEModule) module).isActive()) {
                                    removeArea = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (removeArea) {
                        toRemove.add(entryCoordinate);
                    }
                }
            }
        }
    }
    for (GlobalCoordinate globalCoordinate : toRemove) {
        areas.remove(globalCoordinate);
    }
    return noTeleport;
}
Also used : EnvironmentModule(mcjty.rftools.blocks.environmental.modules.EnvironmentModule) NoTeleportEModule(mcjty.rftools.blocks.environmental.modules.NoTeleportEModule) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.world.WorldServer) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class PeacefulAreaManager method isPeaceful.

public static boolean isPeaceful(GlobalCoordinate coordinate) {
    if (areas.isEmpty()) {
        return false;
    }
    List<GlobalCoordinate> toRemove = new ArrayList<>();
    boolean peaceful = false;
    long curtime = System.currentTimeMillis() - 10000;
    for (Map.Entry<GlobalCoordinate, PeacefulArea> entry : areas.entrySet()) {
        PeacefulArea area = entry.getValue();
        GlobalCoordinate entryCoordinate = entry.getKey();
        if (area.in(coordinate, entryCoordinate)) {
            peaceful = true;
        }
        if (area.getLastTouched() < curtime) {
            // Hasn't been touched for at least 10 seconds. Probably no longer valid.
            // To be sure we will first check this by testing if the environmental controller is still active and running.
            WorldServer world = DimensionManager.getWorld(entryCoordinate.getDimension());
            if (world != null) {
                BlockPos c = entryCoordinate.getCoordinate();
                // If the world is not loaded we don't do anything and we also don't remove the area since we have no information about it.
                if (RFToolsTools.chunkLoaded(world, c)) {
                    boolean removeArea = true;
                    TileEntity te = world.getTileEntity(c);
                    if (te instanceof EnvironmentalControllerTileEntity) {
                        EnvironmentalControllerTileEntity controllerTileEntity = (EnvironmentalControllerTileEntity) te;
                        for (EnvironmentModule module : controllerTileEntity.getEnvironmentModules()) {
                            if (module instanceof PeacefulEModule) {
                                if (((PeacefulEModule) module).isActive()) {
                                    removeArea = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (removeArea) {
                        toRemove.add(entryCoordinate);
                    }
                }
            }
        }
    }
    for (GlobalCoordinate globalCoordinate : toRemove) {
        areas.remove(globalCoordinate);
    }
    return peaceful;
}
Also used : EnvironmentModule(mcjty.rftools.blocks.environmental.modules.EnvironmentModule) ArrayList(java.util.ArrayList) PeacefulEModule(mcjty.rftools.blocks.environmental.modules.PeacefulEModule) WorldServer(net.minecraft.world.WorldServer) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class EndergenicTileEntity method queueWork.

// Postpone the actual tick to after all other TE's have ticked (in a WorldTickEvent)
private void queueWork() {
    GlobalCoordinate gc = new GlobalCoordinate(getPos(), getWorld().provider.getDimension());
    if (endergenicsAdded.contains(gc)) {
        // We're already there. Nothing to do
        return;
    }
    // Find an endergenic with an injector.
    EndergenicTileEntity withInjector = findEndergenicWithPredicate(new HashSet<>(), EndergenicTileEntity::hasInjector);
    if (withInjector != null) {
        // From this injector locate if possible an injector that has a pearl and use
        // that one instead as the head of the endergenic list for post-tick processing.
        EndergenicTileEntity loop = withInjector.findEndergenicWithPredicate(new HashSet<>(), p -> !p.pearls.isEmpty());
        if (loop == null)
            loop = withInjector;
        Set<BlockPos> done = new HashSet<>();
        while (loop != null) {
            done.add(loop.getPos());
            addToQueue(loop, new GlobalCoordinate(loop.getPos(), getWorld().provider.getDimension()));
            loop = loop.getDestinationTE();
            if (loop == null || done.contains(loop.getPos())) {
                loop = null;
            }
        }
    }
    // In all cases we add this endergenic. This will not do anything
    // if it was already added before
    addToQueue(this, gc);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Aggregations

GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)53 BlockPos (net.minecraft.util.math.BlockPos)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 TileEntity (net.minecraft.tileentity.TileEntity)9 World (net.minecraft.world.World)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 ItemStack (net.minecraft.item.ItemStack)5 IBlockState (net.minecraft.block.state.IBlockState)4 MovingSound (net.minecraft.client.audio.MovingSound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 ArrayList (java.util.ArrayList)3 Block (net.minecraft.block.Block)3 WorldServer (net.minecraft.world.WorldServer)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SmartWrenchMode (mcjty.lib.api.smartwrench.SmartWrenchMode)2 IModuleData (mcjty.rftools.api.screens.data.IModuleData)2 EndergenicTileEntity (mcjty.rftools.blocks.endergen.EndergenicTileEntity)2 EnvironmentModule (mcjty.rftools.blocks.environmental.modules.EnvironmentModule)2 TeleportDestination (mcjty.rftools.blocks.teleporter.TeleportDestination)2