-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LambDynamicLights v1.2.1: Add some tweaks, TNT lighting and fixes.
- Loading branch information
1 parent
57abd1e
commit 87c3ce4
Showing
18 changed files
with
438 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# LambDynamicLights API | ||
|
||
You added a new entity that could emit light? You want that it dynamically emits light? | ||
|
||
Then try the API of this mod! | ||
|
||
## Quick note | ||
|
||
Every time entity is referenced it means either an entity or a block entity. | ||
|
||
Block entity dynamic lighting is non-recommended if avoidable with block states. | ||
|
||
If your entity re-implements tick without calling the super method the dynamic light handler will not work. | ||
|
||
## Dynamic light handlers | ||
|
||
### `DynamicLightHandler` | ||
|
||
A dynamic light handler is an interface with one method: `int getLuminance(T lightSource)`. | ||
|
||
The returned value is between 0 and 15 which are luminance values, `lightSource` is of the type of the entity and is the targeted entity. | ||
The method is called for every entity matching the type at each tick. | ||
|
||
### `DynamicLightHandlers` | ||
|
||
That's where you register your handler! | ||
|
||
Just call `DynamicLightHandlers#registerDynamicLightHandler(EntityType<T>, DynamicLightHandler<T>)` | ||
or `DynamicLightHandlers#registerDynamicLightHandler(BlockEntityType<T>, DynamicLightHandler<T>)` | ||
to register your handler! | ||
|
||
If a handler is already registered for this entity, then it will merge the two handlers with a `Math#max` handler. | ||
|
||
And that's all! The mod will light up your entities following your handler. | ||
|
||
### Examples | ||
|
||
#### Blaze | ||
|
||
```java | ||
registerDynamicLightHandler(EntityType.BLAZE, entity -> 10); | ||
``` | ||
|
||
#### Enderman | ||
|
||
```java | ||
registerDynamicLightHandler(EntityType.ENDERMAN, entity -> { | ||
int luminance = 0; | ||
if (entity.getCarriedBlock() != null) | ||
luminance = entity.getCarriedBlock().getLuminance(); | ||
return luminance; | ||
}); | ||
``` | ||
|
||
#### Item frame | ||
|
||
```java | ||
registerDynamicLightHandler(EntityType.ITEM_FRAME, entity -> { | ||
World world = entity.getEntityWorld(); | ||
return LambDynLights.getLuminanceFromItemStack(entity.getHeldItemStack(), !world.getFluidState(entity.getBlockPos()).isEmpty()); | ||
}); | ||
``` | ||
|
||
## Utility methods | ||
|
||
- `DynamicLightHandler#makeLivingEntityHandler` will merge the given handler with a basic handler for living entity which detects item light sources. | ||
- `DynamicLightHandler#makeCreeperEntityHandler` will optionally merge the given handler with a basic handler for creepers. May be useful for Creepers mod. | ||
- `LambDynLights#getLuminanceFromItemStack` will return the luminance value of the given item stack. | ||
|
||
## `#lambdynlights:water_sensitive` tag | ||
|
||
This is an item tag which lists water-sensitive light-emitting items. | ||
|
||
Every items listed in this tag will not emit light in water. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/me/lambdaurora/lambdynlights/ExplosiveLightingMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright © 2020 LambdAurora <[email protected]> | ||
* | ||
* This file is part of LambDynamicLights. | ||
* | ||
* Licensed under the MIT license. For more information, | ||
* see the LICENSE file. | ||
*/ | ||
|
||
package me.lambdaurora.lambdynlights; | ||
|
||
import me.lambdaurora.spruceui.SpruceTexts; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.aperlambda.lambdacommon.utils.Nameable; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents the explosives dynamic lighting mode. | ||
* | ||
* @author LambdAurora | ||
* @version 1.2.1 | ||
* @since 1.2.1 | ||
*/ | ||
public enum ExplosiveLightingMode implements Nameable | ||
{ | ||
OFF(Formatting.RED, SpruceTexts.OPTIONS_OFF), | ||
SIMPLE(Formatting.YELLOW, SpruceTexts.OPTIONS_GENERIC_SIMPLE), | ||
FANCY(Formatting.GREEN, SpruceTexts.OPTIONS_GENERIC_FANCY); | ||
|
||
private final Text translatedText; | ||
|
||
ExplosiveLightingMode(@NotNull Formatting formatting, @NotNull Text translatedText) | ||
{ | ||
this.translatedText = translatedText.copy().formatted(formatting); | ||
} | ||
|
||
/** | ||
* Returns whether this mode enables explosives dynamic lighting. | ||
* | ||
* @return True if the mode enables explosives dynamic lighting, else false. | ||
*/ | ||
public boolean isEnabled() | ||
{ | ||
return this != OFF; | ||
} | ||
|
||
/** | ||
* Returns the next explosives dynamic lighting mode available. | ||
* | ||
* @return The next available explosives dynamic lighting mode. | ||
*/ | ||
public ExplosiveLightingMode next() | ||
{ | ||
ExplosiveLightingMode[] v = values(); | ||
if (v.length == this.ordinal() + 1) | ||
return v[0]; | ||
return v[this.ordinal() + 1]; | ||
} | ||
|
||
/** | ||
* Returns the translated text of the explosives dynamic lighting mode. | ||
* | ||
* @return The translated text of the explosives dynamic lighting mode. | ||
*/ | ||
public @NotNull Text getTranslatedText() | ||
{ | ||
return this.translatedText; | ||
} | ||
|
||
@Override | ||
public @NotNull String getName() | ||
{ | ||
return this.name().toLowerCase(); | ||
} | ||
|
||
/** | ||
* Gets the explosives dynamic lighting mode from its identifier. | ||
* | ||
* @param id The identifier of the explosives dynamic lighting mode. | ||
* @return The explosives dynamic lighting mode if found, else empty. | ||
*/ | ||
public static @NotNull Optional<ExplosiveLightingMode> byId(@NotNull String id) | ||
{ | ||
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); | ||
} | ||
} |
Oops, something went wrong.