-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e691f2
commit 049c7dd
Showing
5 changed files
with
68 additions
and
4 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
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
19 changes: 19 additions & 0 deletions
19
common/src/main/java/net/gigabit101/shrink/api/ShrinkAPI.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 |
---|---|---|
@@ -1,9 +1,28 @@ | ||
package net.gigabit101.shrink.api; | ||
|
||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.ai.attributes.Attribute; | ||
import net.minecraft.world.entity.ai.attributes.RangedAttribute; | ||
|
||
public class ShrinkAPI | ||
{ | ||
public static final Attribute SCALE_ATTRIBUTE = new RangedAttribute("shrink_scale", 1.0D, 0.25D, 10).setSyncable(true); | ||
|
||
public static boolean canEntityShrink(LivingEntity livingEntity) | ||
{ | ||
if(livingEntity == null) return false; | ||
if(livingEntity.getAttributes() == null) return false; | ||
if(livingEntity.getAttribute(SCALE_ATTRIBUTE) == null) return false; | ||
|
||
return livingEntity.getAttribute(ShrinkAPI.SCALE_ATTRIBUTE).getValue() != 1.0D; | ||
} | ||
|
||
public static boolean isEntityShrunk(LivingEntity livingEntity) | ||
{ | ||
if(livingEntity == null) return false; | ||
if(livingEntity.getAttributes() == null) return false; | ||
if(livingEntity.getAttribute(SCALE_ATTRIBUTE) == null) return false; | ||
|
||
return !livingEntity.getAttribute(ShrinkAPI.SCALE_ATTRIBUTE).getModifiers().isEmpty(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
common/src/main/java/net/gigabit101/shrink/mixins/EntityRenderDispatcherMixin.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,43 @@ | ||
package net.gigabit101.shrink.mixins; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import net.gigabit101.shrink.api.ShrinkAPI; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.entity.EntityRenderDispatcher; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.level.LevelReader; | ||
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.ModifyVariable; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(EntityRenderDispatcher.class) | ||
public class EntityRenderDispatcherMixin | ||
{ | ||
@Unique | ||
private static float shrink$value = 0; | ||
@Inject(method = "renderShadow", at = @At("HEAD")) | ||
private static void renderShadow(PoseStack poseStack, MultiBufferSource multiBufferSource, Entity entity, float f, float g, LevelReader levelReader, float h, CallbackInfo ci) | ||
{ | ||
if(entity instanceof LivingEntity livingEntity) | ||
{ | ||
if(ShrinkAPI.isEntityShrunk(livingEntity)) | ||
{ | ||
shrink$value = (float) (h * livingEntity.getAttribute(ShrinkAPI.SCALE_ATTRIBUTE).getValue()); | ||
} | ||
else | ||
{ | ||
shrink$value = h; | ||
} | ||
} | ||
} | ||
|
||
@ModifyVariable(method = "renderShadow", at = @At("HEAD"), ordinal = 2) | ||
private static float injected(float h) | ||
{ | ||
return shrink$value; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"defaultRequire": 1 | ||
}, | ||
"client": [ | ||
"EntityRenderDispatcherMixin", | ||
"LivingEntityRendererMixin" | ||
] | ||
} |