From a98957ba0d0f3019dec5e7b1a5298bd1bf842aa4 Mon Sep 17 00:00:00 2001 From: TexTrue <3140846162@qq.com> Date: Fri, 5 Jul 2024 13:10:08 +0800 Subject: [PATCH] clean --- .../api/item/ItemLightSource.java | 22 ++++-------- .../AbstractDecorationEntityMixin.java | 36 +++++++++---------- .../lightsource/BlockAttachedEntityMixin.java | 36 ------------------- .../ryoamiclights.common.mixins.json | 2 +- 4 files changed, 24 insertions(+), 72 deletions(-) delete mode 100644 common/src/main/java/org/thinkingstudio/ryoamiclights/mixin/lightsource/BlockAttachedEntityMixin.java diff --git a/common/src/main/java/org/thinkingstudio/ryoamiclights/api/item/ItemLightSource.java b/common/src/main/java/org/thinkingstudio/ryoamiclights/api/item/ItemLightSource.java index 61675e2a..cc805d1c 100644 --- a/common/src/main/java/org/thinkingstudio/ryoamiclights/api/item/ItemLightSource.java +++ b/common/src/main/java/org/thinkingstudio/ryoamiclights/api/item/ItemLightSource.java @@ -12,6 +12,7 @@ import com.google.gson.JsonObject; import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.BlockStateComponent; import org.thinkingstudio.ryoamiclights.RyoamicLights; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -97,7 +98,7 @@ public String toString() { return Optional.empty(); } - var affectId = Identifier.of(json.get("item").getAsString()); + var affectId = Identifier.tryParse(json.get("item").getAsString()); var item = Registries.ITEM.get(affectId); if (item == Items.AIR) @@ -164,21 +165,10 @@ public int getLuminance(ItemStack stack) { } static int getLuminance(ItemStack stack, BlockState state) { - var nbt = stack.getComponents(); - - if (nbt != null) { - var blockStateTag = nbt.get(DataComponentTypes.BLOCK_STATE); - var stateManager = state.getBlock().getStateManager(); - - if (blockStateTag != null) { - for (var key : blockStateTag.properties().keySet()) { - var property = stateManager.getProperty(key); - if (property != null) { - var value = blockStateTag.properties().get(key); - state = with(state, property, value); - } - } - } + var nbt = stack.getComponents().getOrDefault(DataComponentTypes.BLOCK_STATE, BlockStateComponent.DEFAULT); + + if (!nbt.isEmpty()) { + state = nbt.applyToState(state); } return state.getLuminance(); diff --git a/common/src/main/java/org/thinkingstudio/ryoamiclights/mixin/lightsource/AbstractDecorationEntityMixin.java b/common/src/main/java/org/thinkingstudio/ryoamiclights/mixin/lightsource/AbstractDecorationEntityMixin.java index 08724557..1635d279 100644 --- a/common/src/main/java/org/thinkingstudio/ryoamiclights/mixin/lightsource/AbstractDecorationEntityMixin.java +++ b/common/src/main/java/org/thinkingstudio/ryoamiclights/mixin/lightsource/AbstractDecorationEntityMixin.java @@ -10,7 +10,6 @@ package org.thinkingstudio.ryoamiclights.mixin.lightsource; -import net.minecraft.entity.decoration.BlockAttachedEntity; import org.thinkingstudio.ryoamiclights.DynamicLightSource; import org.thinkingstudio.ryoamiclights.RyoamicLights; import org.thinkingstudio.ryoamiclights.api.DynamicLightHandlers; @@ -19,9 +18,6 @@ import net.minecraft.entity.decoration.AbstractDecorationEntity; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(AbstractDecorationEntity.class) public abstract class AbstractDecorationEntityMixin extends Entity implements DynamicLightSource { @@ -29,19 +25,21 @@ public AbstractDecorationEntityMixin(EntityType type, World world) { super(type, world); } -// @Inject(method = "tick", at = @At("TAIL")) -// private void onTick(CallbackInfo ci) { -// // We do not want to update the entity on the server. -// if (this.getWorld().isClient()) { -// if (this.isRemoved()) { -// this.ryoamicLights$setDynamicLightEnabled(false); -// } else { -// if (!RyoamicLights.get().config.getEntitiesLightSource().get() || !DynamicLightHandlers.canLightUp(this)) -// this.ryoamicLights$resetDynamicLight(); -// else -// this.ryoamicLights$dynamicLightTick(); -// RyoamicLights.updateTracking(this); -// } -// } -// } + @Override + public void tick() { + super.tick(); + + // We do not want to update the entity on the server. + if (this.getWorld().isClient()) { + if (this.isRemoved()) { + this.ryoamicLights$setDynamicLightEnabled(false); + } else { + if (!RyoamicLights.get().config.getEntitiesLightSource().get() || !DynamicLightHandlers.canLightUp(this)) + this.ryoamicLights$resetDynamicLight(); + else + this.ryoamicLights$dynamicLightTick(); + RyoamicLights.updateTracking(this); + } + } + } } diff --git a/common/src/main/java/org/thinkingstudio/ryoamiclights/mixin/lightsource/BlockAttachedEntityMixin.java b/common/src/main/java/org/thinkingstudio/ryoamiclights/mixin/lightsource/BlockAttachedEntityMixin.java deleted file mode 100644 index 03490e16..00000000 --- a/common/src/main/java/org/thinkingstudio/ryoamiclights/mixin/lightsource/BlockAttachedEntityMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.thinkingstudio.ryoamiclights.mixin.lightsource; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.decoration.BlockAttachedEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.thinkingstudio.ryoamiclights.DynamicLightSource; -import org.thinkingstudio.ryoamiclights.RyoamicLights; -import org.thinkingstudio.ryoamiclights.api.DynamicLightHandlers; - -@Mixin(BlockAttachedEntity.class) -public abstract class BlockAttachedEntityMixin extends Entity implements DynamicLightSource { - public BlockAttachedEntityMixin(EntityType type, World world) { - super(type, world); - } - - @Inject(method = "tick", at = @At("TAIL")) - private void onTick(CallbackInfo ci) { - // We do not want to update the entity on the server. - if (this.getWorld().isClient()) { - if (this.isRemoved()) { - this.ryoamicLights$setDynamicLightEnabled(false); - } else { - if (!RyoamicLights.get().config.getEntitiesLightSource().get() || !DynamicLightHandlers.canLightUp(this)) - this.ryoamicLights$resetDynamicLight(); - else - this.ryoamicLights$dynamicLightTick(); - RyoamicLights.updateTracking(this); - } - } - } -} diff --git a/common/src/main/resources/ryoamiclights.common.mixins.json b/common/src/main/resources/ryoamiclights.common.mixins.json index cd99368c..784b0761 100644 --- a/common/src/main/resources/ryoamiclights.common.mixins.json +++ b/common/src/main/resources/ryoamiclights.common.mixins.json @@ -11,8 +11,8 @@ "EntityTypeMixin", "MinecraftClientMixin", "WorldMixin", + "lightsource.AbstractDecorationEntityMixin", "lightsource.AbstractMinecartEntityMixin", - "lightsource.BlockAttachedEntityMixin", "lightsource.BlockEntityMixin", "lightsource.EntityMixin", "lightsource.ExplosiveProjectileEntityMixin",