Comments (4)
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.
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 positionNotes: 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.
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.
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)
- Error when loading LightAPI on 1.15.2 Paper HOT 1
- Lights disappear on block update HOT 1
- Lighting only updates after a server restart HOT 2
- Performance HOT 6
- 1.17 HOT 3
- Error stopped chunks from loading HOT 10
- Tunity Starlight Support. HOT 21
- java.lang.ClassCastException: ca.spottedleaf.starlight.light.StarLightInterface$2 incompatible with net.minecraft.world.level.lighting.LightEngineBlock
- Can someone give plugin? HOT 2
- 1.17.1 Pupur Issue HOT 2
- don't see light HOT 13
- [WARN] LightAPIFork on paper 1.17.1-233 HOT 4
- No LightAPI implementations was found for Paper v1_17_R1 HOT 8
- [BUG] starlight.light.StarLightInterface HOT 1
- Error on StartUp
- Добавить поддержку starlight(в виде светлых блоков) для 1.17
- Update to support java 17 and mc 1.18
- Warn flood to console PufferFish core
- Classnotfoundexception on 1.18.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightapi.