Search in sources :

Example 1 with IICProxy

use of blusunrize.immersiveengineering.api.energy.wires.IICProxy in project ImmersiveEngineering by BluSunrize.

the class EventHandler method onWorldTick.

//	@SubscribeEvent
//	public void onEntityInteract(EntityInteractEvent event)
//	{
//		if(event.target instanceof EntityLivingBase && OreDictionary.itemMatches(new ItemStack(IEContent.itemRevolver,1,OreDictionary.WILDCARD_VALUE), event.entityPlayer.getCurrentEquippedItem(), false))
//			event.setCanceled(true);
//	}
@SubscribeEvent
public void onWorldTick(WorldTickEvent event) {
    if (event.phase == TickEvent.Phase.START && validateConnsNextTick && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
        boolean validateConnections = IEConfig.validateConnections;
        int invalidConnectionsDropped = 0;
        for (int dim : ImmersiveNetHandler.INSTANCE.getRelevantDimensions()) {
            if (!validateConnections) {
                continue;
            }
            World world = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dim);
            if (world == null) {
                ImmersiveNetHandler.INSTANCE.directConnections.remove(dim);
                continue;
            }
            for (Connection con : ImmersiveNetHandler.INSTANCE.getAllConnections(world)) {
                if (!(world.getTileEntity(con.start) instanceof IImmersiveConnectable && world.getTileEntity(con.end) instanceof IImmersiveConnectable)) {
                    ImmersiveNetHandler.INSTANCE.removeConnection(world, con);
                    invalidConnectionsDropped++;
                }
            }
            IELogger.info("removed " + invalidConnectionsDropped + " invalid connections from world");
        }
        int invalidProxies = 0;
        Set<DimensionBlockPos> toRemove = new HashSet<>();
        for (Entry<DimensionBlockPos, IICProxy> e : ImmersiveNetHandler.INSTANCE.proxies.entrySet()) {
            if (!validateConnections) {
                continue;
            }
            DimensionBlockPos p = e.getKey();
            World w = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(p.dimension);
            if (w != null && w.isBlockLoaded(p))
                toRemove.add(p);
            if (validateConnections && w == null) {
                invalidProxies++;
                toRemove.add(p);
                continue;
            }
            if (validateConnections && !(w.getTileEntity(p) instanceof IImmersiveConnectable)) {
                invalidProxies++;
                toRemove.add(p);
            }
        }
        if (invalidProxies > 0)
            IELogger.info("Removed " + invalidProxies + " invalid connector proxies (used to transfer power through unloaded chunks)");
        validateConnsNextTick = false;
    }
    if (event.phase == TickEvent.Phase.END && ArcRecyclingThreadHandler.recipesToAdd != null) {
        ArcFurnaceRecipe.recipeList.addAll(ArcRecyclingThreadHandler.recipesToAdd);
        ArcRecyclingThreadHandler.recipesToAdd = null;
    }
    if (event.phase == TickEvent.Phase.END && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
        for (Entry<Connection, Integer> e : ImmersiveNetHandler.INSTANCE.getTransferedRates(event.world.provider.getDimension()).entrySet()) if (e.getValue() > e.getKey().cableType.getTransferRate()) {
            if (event.world instanceof WorldServer)
                for (Vec3d vec : e.getKey().getSubVertices(event.world)) ((WorldServer) event.world).spawnParticle(EnumParticleTypes.FLAME, false, vec.xCoord, vec.yCoord, vec.zCoord, 0, 0, .02, 0, 1, new int[0]);
            ImmersiveNetHandler.INSTANCE.removeConnection(event.world, e.getKey());
        }
        ImmersiveNetHandler.INSTANCE.getTransferedRates(event.world.provider.getDimension()).clear();
    }
    if (event.phase == TickEvent.Phase.START) {
        if (!currentExplosions.isEmpty()) {
            Iterator<IEExplosion> itExplosion = currentExplosions.iterator();
            while (itExplosion.hasNext()) {
                IEExplosion ex = itExplosion.next();
                ex.doExplosionTick();
                if (ex.isExplosionFinished)
                    itExplosion.remove();
            }
        }
        synchronized (requestedBlockUpdates) {
            while (!requestedBlockUpdates.isEmpty()) {
                Pair<Integer, BlockPos> curr = requestedBlockUpdates.poll();
                if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
                    World w = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(curr.getLeft());
                    if (w != null) {
                        IBlockState state = w.getBlockState(curr.getRight());
                        w.notifyBlockUpdate(curr.getRight(), state, state, 3);
                    }
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IICProxy(blusunrize.immersiveengineering.api.energy.wires.IICProxy) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) DimensionBlockPos(blusunrize.immersiveengineering.api.DimensionBlockPos) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d) DimensionBlockPos(blusunrize.immersiveengineering.api.DimensionBlockPos) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IICProxy

use of blusunrize.immersiveengineering.api.energy.wires.IICProxy in project ImmersiveEngineering by BluSunrize.

the class IESaveData method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    Integer[] relDim = ImmersiveNetHandler.INSTANCE.getRelevantDimensions().toArray(new Integer[0]);
    int[] savedDimensions = new int[relDim.length];
    for (int ii = 0; ii < relDim.length; ii++) savedDimensions[ii] = relDim[ii];
    nbt.setIntArray("savedDimensions", savedDimensions);
    for (int dim : savedDimensions) {
        NBTTagList connectionList = new NBTTagList();
        for (Connection con : ImmersiveNetHandler.INSTANCE.getAllConnections(dim)) {
            connectionList.appendTag(con.writeToNBT());
        }
        nbt.setTag("connectionList" + dim, connectionList);
    }
    NBTTagList proxies = new NBTTagList();
    for (IICProxy iic : ImmersiveNetHandler.INSTANCE.proxies.values()) proxies.appendTag(iic.writeToNBT());
    nbt.setTag("iicProxies", proxies);
    NBTTagList mineralList = new NBTTagList();
    for (Map.Entry<DimensionChunkCoords, MineralWorldInfo> e : ExcavatorHandler.mineralCache.entrySet()) if (e.getKey() != null && e.getValue() != null) {
        NBTTagCompound tag = e.getKey().writeToNBT();
        tag.setTag("info", e.getValue().writeToNBT());
        mineralList.appendTag(tag);
    }
    nbt.setTag("mineralDepletion", mineralList);
    NBTTagList receivedShaderList = new NBTTagList();
    for (String player : ShaderRegistry.receivedShaders.keySet()) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setString("player", player);
        NBTTagList playerReceived = new NBTTagList();
        for (String shader : ShaderRegistry.receivedShaders.get(player)) if (shader != null && !shader.isEmpty())
            playerReceived.appendTag(new NBTTagString(shader));
        tag.setTag("received", playerReceived);
        receivedShaderList.appendTag(tag);
    }
    nbt.setTag("receivedShaderList", receivedShaderList);
    return nbt;
}
Also used : MineralWorldInfo(blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo) IICProxy(blusunrize.immersiveengineering.api.energy.wires.IICProxy) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagList(net.minecraft.nbt.NBTTagList) DimensionChunkCoords(blusunrize.immersiveengineering.api.DimensionChunkCoords) NBTTagString(net.minecraft.nbt.NBTTagString) Map(java.util.Map)

Aggregations

IICProxy (blusunrize.immersiveengineering.api.energy.wires.IICProxy)2 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)2 DimensionBlockPos (blusunrize.immersiveengineering.api.DimensionBlockPos)1 DimensionChunkCoords (blusunrize.immersiveengineering.api.DimensionChunkCoords)1 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1 MineralWorldInfo (blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo)1 Map (java.util.Map)1 IBlockState (net.minecraft.block.state.IBlockState)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 NBTTagString (net.minecraft.nbt.NBTTagString)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1 WorldServer (net.minecraft.world.WorldServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1