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);
}
}
}
}
}
}
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;
}
Aggregations