Начинающий
- Статус
- Оффлайн
- Регистрация
- 23 Июн 2025
- Сообщения
- 43
- Реакции
- 0
- Выберите загрузчик игры
- Vanilla
JavaScript:
package im.expensive.functions.impl.render;
import com.google.common.eventbus.Subscribe;
import com.jhlabs.image.ImageMath;
import java.awt.Color;
import im.expensive.Expensive;
import im.expensive.events.WorldEvent;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.render.ColorUtils;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.RayTraceResult.Type;
import net.optifine.render.RenderUtils;
@FunctionRegister(name = "BlockOverlay", type = Category.Movement)
public class BlockOverlay extends Function {
private final Minecraft mc = Minecraft.getInstance();
public float animationStep;
@Subscribe
public void onWorld(WorldEvent e) {
assert this.mc.objectMouseOver != null;
if (this.mc.objectMouseOver.getType() != Type.ENTITY) {
RayTraceResult rayTraceResult = this.mc.getRenderViewEntity().pick((double)6.0F, 0.0F, false);
if (rayTraceResult.getType() == Type.BLOCK) {
BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult)rayTraceResult;
BlockPos blockPos = blockRayTraceResult.getPos();
BlockState blockState = this.mc.world.getBlockState(blockPos);
Item blockItem = Item.getItemFromBlock(blockState.getBlock());
if (blockItem instanceof BlockItem) {
float destroyProgress = this.mc.playerController.curBlockDamageMP;
this.animationStep = MathUtil.fast(this.animationStep, destroyProgress, 15.0F);
float value = 1.0F - Math.abs((float)(System.currentTimeMillis() % 1800L) / 900.0F - 1.0F);
RenderUtils.drawBlockBoxWithProgress(blockPos, ColorUtils.rgba(ColorUtils.interpolate(Expensive.getInstance().getStyleManager().getCurrentStyle().getFirstColor().getRed(), Expensive.getInstance().getStyleManager().getCurrentStyle().getSecondColor().getRed(), value), ColorUtils.interpolate(Expensive.getInstance().getStyleManager().getCurrentStyle().getFirstColor().getGreen(), Expensive.getInstance().getStyleManager().getCurrentStyle().getSecondColor().getGreen(), value), ColorUtils.interpolate(Expensive.getInstance().getStyleManager().getCurrentStyle().getFirstColor().getBlue(), Expensive.getInstance().getStyleManager().getCurrentStyle().getSecondColor().getBlue(), value), destroyProgress != 0.0F ? ImageMath.clamp((int)(this.animationStep * 255.0F), 100, 255) : 128), 0.0F);
int alpha = (int)(this.animationStep * 100.0F);
RenderUtils.drawFilledBlockBox(blockPos, (new Color(ColorUtils.interpolate(Expensive.getInstance().getStyleManager().getCurrentStyle().getFirstColor().getRed(), Expensive.getInstance().getStyleManager().getCurrentStyle().getSecondColor().getRed(), value), ColorUtils.interpolate(Expensive.getInstance().getStyleManager().getCurrentStyle().getFirstColor().getGreen(), Expensive.getInstance().getStyleManager().getCurrentStyle().getSecondColor().getGreen(), value), ColorUtils.interpolate(Expensive.getInstance().getStyleManager().getCurrentStyle().getFirstColor().getBlue(), Expensive.getInstance().getStyleManager().getCurrentStyle().getSecondColor().getBlue(), value), alpha)).getRGB(), alpha);
}
}
}
}
}
drawFilledBlockBox:
public static void drawFilledBlockBox(BlockPos blockPos, int color, int alpha) {
BlockState blockState = mc.world.getBlockState(blockPos);
VoxelShape shape = blockState.getShape(mc.world, blockPos);
shape.forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> {
AxisAlignedBB box = (new AxisAlignedBB((double)blockPos.getX() + minX, (double)blockPos.getY() + minY, (double)blockPos.getZ() + minZ, (double)blockPos.getX() + maxX, (double)blockPos.getY() + maxY, (double)blockPos.getZ() + maxZ)).offset(-mc.getRenderManager().info.getProjectedView().x, -mc.getRenderManager().info.getProjectedView().y, -mc.getRenderManager().info.getProjectedView().z);
drawBoxFilled(box, color, alpha);
});
}
}
drawBlockBoxWithProgress:
public static void drawBlockBoxWithProgress(BlockPos blockPos, int color, float progress) {
BlockState blockState = mc.world.getBlockState(blockPos);
VoxelShape shape = blockState.getShape(mc.world, blockPos);
double camX = mc.getRenderManager().info.getProjectedView().x;
double camY = mc.getRenderManager().info.getProjectedView().y;
double camZ = mc.getRenderManager().info.getProjectedView().z;
shape.forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> {
AxisAlignedBB fullBox = (new AxisAlignedBB(blockPos.getX() + minX, blockPos.getY() + minY, blockPos.getZ() + minZ,
blockPos.getX() + maxX, blockPos.getY() + maxY, blockPos.getZ() + maxZ))
.offset(-camX, -camY, -camZ);
drawBox(fullBox, color);
double height = maxY - minY;
float fillHeight = (float) (Math.min(progress, 1.0F) * height);
AxisAlignedBB filledBox = (new AxisAlignedBB(blockPos.getX() + minX, blockPos.getY() + minY, blockPos.getZ() + minZ,
blockPos.getX() + maxX, blockPos.getY() + minY + fillHeight, blockPos.getZ() + maxZ))
.offset(-camX, -camY, -camZ);
int alpha = (int) ((1.0F - progress) * 255.0F);
int filledColor = ColorUtils.setAlpha(color, alpha);
drawBoxz(filledBox, filledColor);
});
}
Вложения
Последнее редактирование: