age-series / ElectricalAge

Electrical Age (ELN) is a Minecraft Mod offering the ability to perform large-scale in-game electrical simulations.
Other
66 stars 32 forks source link

Grid Switch should produce visible electrical arc when opened #244

Closed genestrashcan closed 2 years ago

genestrashcan commented 3 years ago

Currently in the current testing release the grid switch only produces zapping sounds when opened...

make the Grid Switch produce a electrical arc when opened like in the video.

https://www.youtube.com/watch?v=VrY_k_pdlCs

genestrashcan commented 3 years ago

to generate the arcs you will have to look at the code they used to generate the arcs with the tesla coil in immersive engineering (which is open source) and write your own code to make the arcs in EA.

https://ftb.gamepedia.com/Tesla_Coil_(Immersive_Engineering)

https://github.com/BluSunrize/ImmersiveEngineering

genestrashcan commented 3 years ago

The following may point you in the right direction to figure out how to make the arcs.

https://github.com/BluSunrize/ImmersiveEngineering/blob/937660bbaffe7382de2d7ff34e38d5456a011510/src/main/java/blusunrize/immersiveengineering/common/blocks/metal/TeslaCoilTileEntity.java#L539

jrddunbr commented 3 years ago

I'm leaving this open but I'm not making it happen myself.

genestrashcan commented 3 years ago

@jrddunbr @Baughn @Grissess - perhaps the following coding can be reverse engineered and recoded to make the arcs.

they should last a bit before breaking when the grid is opened (cold) depending upon amount of power drawn and should last only a little when the grid switch is closed (hot) like in the video

I have Diddly SQUAT for Coding Skills!

https://www.youtube.com/watch?v=-cM8P6-aAf4

public static class LightningAnimation
    {
        public Vector3d startPos;
        public LivingEntity targetEntity;
        public Vector3d targetPos;
        private int lifeTimer = 20;
        private final int ANIMATION_MAX = 4;
        private int animationTimer = ANIMATION_MAX;

        public List<Vector3d> subPoints = new ArrayList<>();
        private Vector3d prevTarget;

        public LightningAnimation(Vector3d startPos, LivingEntity targetEntity)
        {
            this.startPos = startPos;
            this.targetEntity = targetEntity;
        }

        public LightningAnimation(Vector3d startPos, Vector3d targetPos)
        {
            this.startPos = startPos;
            this.targetPos = targetPos;
        }

        public boolean shoudlRecalculateLightning()
        {
            if(subPoints.isEmpty()||animationTimer==0)
                return true;
            boolean b = false;
            Vector3d end = targetEntity!=null?targetEntity.getPositionVec(): targetPos;
            if(prevTarget!=null)
                b = prevTarget.distanceTo(end) > 1;
            prevTarget = end;
            return b;
        }

        public void createLightning(Random rand)
        {
            subPoints.clear();
            Vector3d end = targetEntity!=null?targetEntity.getPositionVec(): targetPos;
            Vector3d dist = end.subtract(startPos);
            double points = 12;
            for(int i = 0; i < points; i++)
            {
                Vector3d sub = startPos.add(dist.x/points*i, dist.y/points*i, dist.z/points*i);
                //distance to the middle point and by that, distance from the start and end. -1 is start, 1 is end
                double fixPointDist = (i-points/2)/(points/2);
                //Randomization modifier, closer to start/end means smaller divergence
                double mod = 1-.75*Math.abs(fixPointDist);
                double offX = (rand.nextDouble()-.5)*mod;
                double offY = (rand.nextDouble()-.5)*mod;
                double offZ = (rand.nextDouble()-.5)*mod;
                if(fixPointDist < 0)
                {
                    offY += .75*mod*(.75+fixPointDist);//Closer to the coil should arc upwards
                    offX = (sub.x-startPos.x) < 0?-Math.abs(offX): Math.abs(offX);
                    offZ = (sub.z-startPos.z) < 0?-Math.abs(offZ): Math.abs(offZ);
                }
                else
                {
                    offY = Math.min(end.y+1*(1-fixPointDist)*-Math.signum(dist.y), offY);//final points should be higher/lower than end, depending on if lightning goes up or down
                    offX = Math.abs(offX)*(end.x-sub.x);
                    offZ = Math.abs(offZ)*(end.z-sub.z);
                }
                subPoints.add(sub.add(offX, offY, offZ));
            }
            animationTimer = ANIMATION_MAX+Utils.RAND.nextInt(5)-2;
        }

        public boolean tick()
        {
            animationTimer--;
            lifeTimer--;
            return lifeTimer <= 0;
        }
    }
jrddunbr commented 3 years ago

I can't just copy random code into the repository. It must comply with the LGPL v3 license that this project requires. You either need to provide the license for the above code from the person who wrote it or we can't use it. Also, do not ping developers. We read GitHub on a regular basis.

Grissess commented 3 years ago

Also note that the code for the rendering is handled separately, in this renderer.

genestrashcan commented 3 years ago

i didn't say a thing about needing to copy and paste exact code directly...

my idea was to more like look at the sample coding for ideas of how it works and write your own code to render the arcs.