Skip to content

Commit

Permalink
_fixed a small thing (and mod menu integration)_
Browse files Browse the repository at this point in the history
  • Loading branch information
I-No-oNe committed Feb 4, 2024
1 parent be26b8e commit 58a8831
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -38,8 +38,8 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Uncomment the following line to enable the deprecated Fabric API modules.

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void onInitializeClient() {
.executes(context -> {
int value = IntegerArgumentType.getInteger(context, "glowing");
IEntityDataSaver playerData = (IEntityDataSaver) context.getSource().getPlayer();
playerData.getPersistentData().putInt("glow",value);
playerData.glowing_entities$getPersistentData().putInt("glow",value);
if (value > 15)
value = 15;
String glow = value < 0 ? "Normal" : String.valueOf(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import net.minecraft.nbt.NbtCompound;

public interface IEntityDataSaver {
NbtCompound getPersistentData();
NbtCompound glowing_entities$getPersistentData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@
public abstract class EntityRendererMixin {

@Inject(method = "getBlockLight", at = @At("RETURN"), cancellable = true)
public <T extends Entity> void getLight(T entity, BlockPos pos, CallbackInfoReturnable<Integer> cir){
public <T extends Entity> void getLight(T entity, BlockPos pos, CallbackInfoReturnable<Integer> cir) {
int glow = 0;
if (entity.getWorld().isClient() && MinecraftClient.getInstance().player != null) {
PlayerEntity player = entity.getWorld().getPlayerByUuid(MinecraftClient.getInstance().player.getUuid());
PlayerEntity player = entity.getWorld().getPlayerByUuid(MinecraftClient.getInstance().player.getUuid());
IEntityDataSaver playerData = (IEntityDataSaver) player;
if(playerData != null && playerData.getPersistentData().contains("glow"))
glow = playerData.getPersistentData().getInt("glow");
}
if (playerData != null && playerData.glowing_entities$getPersistentData().contains("glow"))
glow = playerData.glowing_entities$getPersistentData().getInt("glow");
}
if (glow == 0) {
cir.setReturnValue(0); // Return light level 0 if glow is explicitly set to 0
return;
}
if (glow > 15)
glow = 15;
if (glow < 0)
cir.setReturnValue(entity.isOnFire() ? 15 : entity.getWorld().getLightLevel(LightType.BLOCK, pos));
else cir.setReturnValue(glow);
else
cir.setReturnValue(glow);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
import net.minecraft.nbt.NbtCompound;
import net.i_no_am.glowing_entities.IEntityDataSaver;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Entity.class)
public abstract class ModEntityDataSaverMixin implements IEntityDataSaver {
@Unique
private NbtCompound persistentData;

@Override
public NbtCompound getPersistentData() {
public NbtCompound glowing_entities$getPersistentData() {
if(this.persistentData == null) {
this.persistentData = new NbtCompound();
}
return persistentData;
}

@Inject(method = "writeNbt", at = @At("HEAD"))
protected void injectWriteMethod(NbtCompound nbt, CallbackInfoReturnable info) {
protected void injectWriteMethod(NbtCompound nbt, CallbackInfoReturnable<NbtCompound> info) {
if(persistentData != null) {
nbt.put("glowingentity.uhb_data", persistentData);
}
Expand Down

0 comments on commit 58a8831

Please sign in to comment.