Git Product home page Git Product logo

Comments (4)

Qveshn avatar Qveshn commented on September 18, 2024

Hi

Modify your pom.xml to include LightAPI into your maven project

    <repositories>
        ...
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/groups/public/</url>
        </repository>
    </repositories>

    <dependencies>
         ...
        <dependency>
            <groupId>io.github.qveshn</groupId>
            <artifactId>LightAPI-fork</artifactId>
            <version>3.4.6-SNAPSHOT</version>
        </dependency>
    </dependencies>

(or just download jar-file and attach it to your project as external library to allow references to it)

Try next example to set light.This code is only to learn how to use api. It is not optimized for a lot of sets at one time, but it completely sets the light and updates the chunks on the client (sends notification to client to make him update chunks) for one block position.

import ru.beykerykt.lightapi.LightType;
import ru.beykerykt.lightapi.LightAPI;
...
void setLight(Location location, int lightLevel, LightType lightType) {
    Block block = location.getBlock();
    int oldLightLevel = lightType == LightType.BLOCK ? block.getLightFromBlocks() : block.getLightFromSky();
    if (oldLightLevel != lightLevel) {
        if (lightLevel > 0) {
            LightAPI.createLight(location, lightType, lightLevel, false);
        } else {
            LightAPI.deleteLight(location, lightType, false);
        }
        for (ChunkInfo chunkInfo : LightAPI.collectChunks(location, lightType, Math.max(lightLevel, oldLightLevel))) {
            LightAPI.updateChunk(chunkInfo, lightType);
        }
    }
}

Notes: Methods createLight/deleteLight creates/deletes lights only on server! Player (client) will not see changes until light-chunk-info is updated on client side. So, the next "for" cycle collects all chunk sections (16x16x16) that have changes after creating/deleting light on server and call updateChunk method to notify nearby players to reload light data for each section (chunk)

Also, I suggest you look at ShinyItems source code
https://github.com/Qveshn/ShinyItems
This plugin uses light moving while player walks with torch in hand
The main concept is: plugin every n-th tick checks the player position and light level at that block.
if it is changed then plugin deletes light at old postion and creates at new position

Notes: LightAPI is only API to set/clear light at the block position. It does not monitor it after creating. Bukkit can destroy it after updating nearby block. Therefore ShinyItems periodically checks its installed light sources, and if they accidentally disappeared, then re-creates them again.

When you will study the code, do not see at LightAPIv5.java. It was compatibility for plugin from original author. But his LightAPI still has bugs. The bridge to my fork is in LightAPIv3.java

from lightapi.

DropOfAWater avatar DropOfAWater commented on September 18, 2024

Hi

Modify your pom.xml to include LightAPI into your maven project

    <repositories>
        ...
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/groups/public/</url>
        </repository>
    </repositories>

    <dependencies>
         ...
        <dependency>
            <groupId>io.github.qveshn</groupId>
            <artifactId>LightAPI-fork</artifactId>
            <version>3.4.6-SNAPSHOT</version>
        </dependency>
    </dependencies>

(or just download jar-file and attach it to your project as external library to allow references to it)

Try next example to set light.This code is only to learn how to use api. It is not optimized for a lot of sets at one time, but it completely sets the light and updates the chunks on the client (sends notification to client to make him update chunks) for one block position.

import ru.beykerykt.lightapi.LightType;
import ru.beykerykt.lightapi.LightAPI;
...
void setLight(Location location, int lightLevel, LightType lightType) {
    Block block = location.getBlock();
    int oldLightLevel = lightType == LightType.BLOCK ? block.getLightFromBlocks() : block.getLightFromSky();
    if (oldLightLevel != lightLevel) {
        if (lightLevel > 0) {
            LightAPI.createLight(location, lightType, lightLevel, false);
        } else {
            LightAPI.deleteLight(location, lightType, false);
        }
        for (ChunkInfo chunkInfo : LightAPI.collectChunks(location, lightType, Math.max(lightLevel, oldLightLevel))) {
            LightAPI.updateChunk(chunkInfo, lightType);
        }
    }
}

Notes: Methods createLight/deleteLight creates/deletes lights only on server! Player (client) will not see changes until light-chunk-info is updated on client side. So, the next "for" cycle collects all chunk sections (16x16x16) that have changes after creating/deleting light on server and call updateChunk method to notify nearby players to reload light data for each section (chunk)

Also, I suggest you look at ShinyItems source code
https://github.com/Qveshn/ShinyItems
This plugin uses light moving while player walks with torch in hand
The main concept is: plugin every n-th tick checks the player position and light level at that block.
if it is changed then plugin deletes light at old postion and creates at new position

Notes: LightAPI is only API to set/clear light at the block position. It does not monitor it after creating. Bukkit can destroy it after updating nearby block. Therefore ShinyItems periodically checks its installed light sources, and if they accidentally disappeared, then re-creates them again.

When you will study the code, do not see at LightAPIv5.java. It was compatibility for plugin from original author. But his LightAPI still has bugs. The bridge to my fork is in LightAPIv3.java

I had some issues with editing pom.xml file, but importing external library worked, thank you very much!

from lightapi.

Qveshn avatar Qveshn commented on September 18, 2024

Hmm... Issues?
What is wrong with editing pom?
Do you use maven project?
Issues while editing pom or while compiling?
Can you show error?

from lightapi.

DropOfAWater avatar DropOfAWater commented on September 18, 2024

Hmm... Issues?
What is wrong with editing pom?
Do you use maven project?
Issues while editing pom or while compiling?
Can you show error?

It was probably my fault, I'm new to this stuff.

from lightapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.