Начинающий
- Статус
- Оффлайн
- Регистрация
- 14 Янв 2025
- Сообщения
- 284
- Реакции
- 0
- Выберите загрузчик игры
- Прочие моды
Пожалуйста, авторизуйтесь для просмотра ссылки.
ShulkerVisible:
package xd.harm.modules.impl.player;
import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.Block;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.DyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector2f;
import org.lwjgl.opengl.GL11;
import xd.harm.events.EventDisplay;
import xd.harm.modules.api.Category;
import xd.harm.modules.api.Module;
import xd.harm.modules.api.ModuleRegister;
import xd.harm.utils.math.MathUtil;
import xd.harm.utils.render.color.ColorUtils;
@ModuleRegister(name = "ShulkerVisible", category = Category.Player, desc = "Показывает содержимое шалкера")
public class ShulkerVisible extends Module {
private final BufferBuilder BUILDER = Tessellator.getInstance().getBuffer();
private final Tessellator TESSELLATOR = Tessellator.getInstance();
ResourceLocation SHULKER_TOOLTIP = new ResourceLocation("harmony/images/shulker_box_tooltip.png");
@Subscribe
public void onRender(EventDisplay event) {
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
for (Entity entity : mc.world.getAllEntities()) {
double x = 0, y = 0, z = 0;
ItemStack stack = null;
if (entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity;
if (player.getUniqueID().equals(mc.player.getUniqueID())) continue;
double dx = player.getPosX() - mc.player.getPosX();
double dy = player.getPosY() - mc.player.getPosY();
double dz = player.getPosZ() - mc.player.getPosZ();
double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (distance > 15) continue;
stack = player.inventory.getCurrentItem();
x = player.getPosX();
y = player.getPosY() + player.getHeight() + 1.5f;
z = player.getPosZ();
}
if (entity instanceof ItemEntity) {
double dx = entity.getPosX() - mc.player.getPosX();
double dy = entity.getPosY() - mc.player.getPosY();
double dz = entity.getPosZ() - mc.player.getPosZ();
double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (distance > 15) continue;
ItemStack s = ((ItemEntity) entity).getItem();
if (Block.getBlockFromItem(s.getItem()) instanceof ShulkerBoxBlock) {
stack = s;
x = entity.getPosX();
y = entity.getPosY() + 0.75f;
z = entity.getPosZ();
}
}
if (stack == null || !(Block.getBlockFromItem(stack.getItem()) instanceof ShulkerBoxBlock)) continue;
CompoundNBT tag = stack.getTag();
if (tag == null || !tag.contains("BlockEntityTag", 10)) continue;
CompoundNBT blocksTag = tag.getCompound("BlockEntityTag");
if (!blocksTag.contains("Items", 9)) continue;
NonNullList<ItemStack> items = NonNullList.withSize(27, ItemStack.EMPTY);
ItemStackHelper.loadAllItems(blocksTag, items);
if (items.isEmpty()) continue;
Vector2f vec = xd.harm.utils.projections.ProjectionUtil.project((float) x, (float) y, (float) z);
if (vec == null) continue;
double dx = mc.player.getPosX() - x;
double dy = mc.player.getPosY() - y;
double dz = mc.player.getPosZ() - z;
double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
double scale = MathUtil.lerp(0.5, 1.75, 2.5 / distance);
GlStateManager.pushMatrix();
GlStateManager.translatef(vec.x, vec.y, 0);
GlStateManager.scalef((float) scale, (float) scale, 1.0f);
float slotSize = 18.0f;
float slotSpacing = 0.3f;
float bgScale = 1.5f;
float bgWidth = 174 * bgScale;
float bgHeight = 166 * bgScale;
float bgOffsetX = - 0.1f;
float bgOffsetY = 11.5f;
ShulkerBoxBlock shulkerBlock = (ShulkerBoxBlock) Block.getBlockFromItem(stack.getItem());
DyeColor color = shulkerBlock.getColor();
int shulkerColor;
if (color != null) {
float[] colorComponents = color.getColorComponentValues();
shulkerColor = ColorUtils.rgba(
(int)(colorComponents[0] * 255),
(int)(colorComponents[1] * 255),
(int)(colorComponents[2] * 255),
255
);
} else {
shulkerColor = ColorUtils.rgba(138, 93, 150, 255);
}
mc.getTextureManager().bindTexture(SHULKER_TOOLTIP);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Matrix4f matrix = event.getMatrixStack().getLast().getMatrix();
BUILDER.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX);
int r = ColorUtils.getRed(shulkerColor);
int g = ColorUtils.getGreen(shulkerColor);
int b = ColorUtils.getBlue(shulkerColor);
int a = ColorUtils.getAlpha(shulkerColor);
float x1 = bgOffsetX;
float y1 = bgOffsetY;
float x2 = bgWidth + bgOffsetX;
float y2 = bgHeight + bgOffsetY;
float u1 = 0.0f;
float v1 = 0.0f;
float u2 = 1.0f;
float v2 = 1.0f;
BUILDER.pos(matrix, x1, y2, 0).color(r, g, b, a).tex(u1, v2).endVertex();
BUILDER.pos(matrix, x2, y2, 0).color(r, g, b, a).tex(u2, v2).endVertex();
BUILDER.pos(matrix, x2, y1, 0).color(r, g, b, a).tex(u2, v1).endVertex();
BUILDER.pos(matrix, x1, y1, 0).color(r, g, b, a).tex(u1, v1).endVertex();
TESSELLATOR.draw();
float startX = 8;
float startY = 18;
float posX = startX;
float posY = startY;
for (int i = 0; i < items.size(); i++) {
ItemStack item = items.get(i);
if (!item.isEmpty()) {
mc.getItemRenderer().renderItemAndEffectIntoGUI(item, (int) posX, (int) posY);
mc.getItemRenderer().renderItemOverlayIntoGUI(mc.fontRenderer, item, (int) posX, (int) posY, null);
}
posX += slotSize + slotSpacing;
if ((i + 1) % 9 == 0) {
posX = startX;
posY += slotSize + slotSpacing;
}
}
GlStateManager.popMatrix();
}
RenderSystem.disableBlend();
}
}
Последнее редактирование: