Search in sources :

Example 1 with Connection

use of blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection 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 Connection

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

the class TileRenderImmersiveConnectable method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) {
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    //		tes.draw();
    if (te instanceof IImmersiveConnectable && te.getWorld() != null) {
        Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(te.getWorld(), Utils.toCC(te));
        if (outputs != null) {
            VertexBuffer worldrenderer = ClientUtils.tes().getBuffer();
            worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
            //		GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0F);
            //		GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0F);
            GlStateManager.disableLighting();
            GlStateManager.disableCull();
            GlStateManager.enableBlend();
            GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            Iterator<Connection> itCon = outputs.iterator();
            while (itCon.hasNext()) {
                Connection con = itCon.next();
                TileEntity tileEnd = te.getWorld().getTileEntity(con.end);
                if (tileEnd instanceof IImmersiveConnectable) {
                    ClientUtils.tessellateConnection(con, (IImmersiveConnectable) te, ApiUtils.toIIC(tileEnd, te.getWorld()), con.cableType.getIcon(con));
                }
            }
            GlStateManager.enableLighting();
            GlStateManager.enableTexture2D();
            ClientUtils.tes().draw();
        }
    }
    GlStateManager.popMatrix();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)

Example 3 with Connection

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

the class ClientEventHandler method onPlayerTick.

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
    if (event.side.isClient() && event.phase == Phase.START && event.player != null && event.player == ClientUtils.mc().getRenderViewEntity()) {
        skyhookGrabableConnections.clear();
        EntityPlayer player = event.player;
        ItemStack stack = player.getActiveItemStack();
        if (stack != null && stack.getItem() instanceof ItemSkyhook) {
            TileEntity connector = null;
            double lastDist = 0;
            Connection line = null;
            double py = player.posY + player.getEyeHeight();
            BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ);
            for (int xx = -2; xx <= 2; xx++) for (int zz = -2; zz <= 2; zz++) for (int yy = 0; yy <= 3; yy++) {
                TileEntity tile = player.worldObj.getTileEntity(pos.add(xx, yy, zz));
                if (tile != null) {
                    Connection con = SkylineHelper.getTargetConnection(player.worldObj, pos.add(xx, yy, zz), player, null);
                    if (con != null) {
                        double d = tile.getDistanceSq(player.posX, py, player.posZ);
                        if (connector == null || d < lastDist) {
                            connector = tile;
                            lastDist = d;
                            line = con;
                        }
                    }
                }
            }
            if (line != null && connector != null)
                skyhookGrabableConnections.add(line);
        }
    }
//		if(event.side.isClient() && event.phase == Phase.END && event.player!=null)
//		{
//			EntityPlayer player = event.player;
//			ItemStack stack = player.getActiveItemStack();
//			boolean twohanded = stack!=null && (stack.getItem() instanceof ItemDrill);
//			if(twohanded && (player!=ClientUtils.mc().getRenderViewEntity()||ClientUtils.mc().gameSettings.thirdPersonView!=0))
//			{
//				if(player.getItemInUseCount() <= 0)
//				{
//					player.stopActiveHand();
//					player.setActiveHand(EnumHand.MAIN_HAND);
//				}
//			}
//
//		}
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with Connection

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

the class ConnModelReal method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    if (side == null && state instanceof IExtendedBlockState) {
        IExtendedBlockState iExtendedBlockState = (IExtendedBlockState) state;
        ExtBlockstateAdapter ad = new ExtBlockstateAdapter(iExtendedBlockState, null, ExtBlockstateAdapter.ONLY_OBJ_CALLBACK);
        int x = 0, z = 0;
        if (iExtendedBlockState.getUnlistedProperties().containsKey(IEProperties.CONNECTIONS)) {
            Set<Connection> conns = iExtendedBlockState.getValue(IEProperties.CONNECTIONS);
            if (conns != null && conns.size() > 0) {
                BlockPos tmp = conns.iterator().next().start;
                x = (tmp.getX() % 16 + 16) % 16;
                z = (tmp.getZ() % 16 + 16) % 16;
            }
        }
        Pair<Byte, ExtBlockstateAdapter> key = new ImmutablePair<>((byte) ((x << 4) | z), ad);
        IBakedModel ret = cache.get(key);
        if (ret == null) {
            ret = new AssembledBakedModel(iExtendedBlockState, textureAtlasSprite, base, rand);
            cache.put(key, ret);
        }
        return ret.getQuads(state, side, rand);
    }
    return base.getQuads(state, side, rand);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 5 with Connection

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

the class ItemWireCoil method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (!world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
            TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
            WireType wire = getWireType(stack);
            BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
            tileEntity = world.getTileEntity(masterPos);
            if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect())
                return EnumActionResult.PASS;
            if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target)) {
                player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
                return EnumActionResult.FAIL;
            }
            if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
                ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ() });
                NBTTagCompound targetNbt = new NBTTagCompound();
                target.writeToNBT(targetNbt);
                ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
            } else {
                WireType type = getWireType(stack);
                int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
                BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
                TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
                int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
                if (array[0] != world.provider.getDimension())
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
                else if (linkPos.equals(masterPos))
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
                else if (distanceSq > (type.getMaxLength() * type.getMaxLength()))
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
                else {
                    TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
                    if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink))
                        player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
                    else {
                        IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
                        IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
                        boolean connectionExists = false;
                        Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
                        if (outputs != null)
                            for (Connection con : outputs) {
                                if (con.end.equals(Utils.toCC(nodeLink)))
                                    connectionExists = true;
                            }
                        if (connectionExists)
                            player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
                        else {
                            Vec3d rtOff0 = nodeHere.getRaytraceOffset(nodeLink).addVector(masterPos.getX(), masterPos.getY(), masterPos.getZ());
                            Vec3d rtOff1 = nodeLink.getRaytraceOffset(nodeHere).addVector(linkPos.getX(), linkPos.getY(), linkPos.getZ());
                            Set<BlockPos> ignore = new HashSet<>();
                            ignore.addAll(nodeHere.getIgnored(nodeLink));
                            ignore.addAll(nodeLink.getIgnored(nodeHere));
                            boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
                            if (canSee) {
                                ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), (int) Math.sqrt(distanceSq), type);
                                nodeHere.connectCable(type, target, nodeLink);
                                nodeLink.connectCable(type, targetLink, nodeHere);
                                IESaveData.setDirty(world.provider.getDimension());
                                player.addStat(IEAchievements.connectWire);
                                if (!player.capabilities.isCreativeMode)
                                    stack.stackSize--;
                                ((TileEntity) nodeHere).markDirty();
                                world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
                                IBlockState state = world.getBlockState(masterPos);
                                world.notifyBlockUpdate(masterPos, state, state, 3);
                                ((TileEntity) nodeLink).markDirty();
                                world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
                                state = world.getBlockState(linkPos);
                                world.notifyBlockUpdate(linkPos, state, state, 3);
                            } else
                                player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
                        }
                    }
                }
                ItemNBTHelper.remove(stack, "linkingPos");
                ItemNBTHelper.remove(stack, "targettingInfo");
            }
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType) Vec3d(net.minecraft.util.math.Vec3d) TileEntity(net.minecraft.tileentity.TileEntity) TargetingInfo(blusunrize.immersiveengineering.api.TargetingInfo) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Aggregations

Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)20 BlockPos (net.minecraft.util.math.BlockPos)6 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)5 TileEntity (net.minecraft.tileentity.TileEntity)5 Vec3d (net.minecraft.util.math.Vec3d)5 HashSet (java.util.HashSet)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 IBlockState (net.minecraft.block.state.IBlockState)3 DimensionChunkCoords (blusunrize.immersiveengineering.api.DimensionChunkCoords)2 IICProxy (blusunrize.immersiveengineering.api.energy.wires.IICProxy)2 AbstractConnection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection)2 MineralWorldInfo (blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo)2 Set (java.util.Set)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 DimensionBlockPos (blusunrize.immersiveengineering.api.DimensionBlockPos)1 TargetingInfo (blusunrize.immersiveengineering.api.TargetingInfo)1