Skip to content

Commit

Permalink
Fix #142
Browse files Browse the repository at this point in the history
  • Loading branch information
ssblur committed Aug 15, 2024
1 parent e1a1df4 commit 4ed088c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public class CoordinateCasterWorldRenderer {
static final int BOX_COLOR = 0xffff5064;


public static void render(PoseStack matrix) {
public static void render(@Nullable PoseStack matrix) {
var player = Minecraft.getInstance().player;
ItemStack item;
if (player != null) {

if (player != null && matrix != null) {
if (player.getItemInHand(InteractionHand.MAIN_HAND).getItem() == ScriptorItems.COORDINATE_CASTING_CRYSTAL.get())
render(matrix, player.getItemInHand(InteractionHand.MAIN_HAND));
if (player.getItemInHand(InteractionHand.OFF_HAND).getItem() == ScriptorItems.COORDINATE_CASTING_CRYSTAL.get())
Expand All @@ -27,9 +28,9 @@ public static void render(PoseStack matrix) {
}

public static void render(PoseStack matrix, ItemStack item) {
if(matrix == null) return;
var tesselator = Tesselator.getInstance();
BufferBuilder builder;
MeshData mesh;
var camera = Minecraft.getInstance().gameRenderer.getMainCamera();
var last = matrix.last();
var pose = last.pose();
Expand All @@ -39,7 +40,6 @@ public static void render(PoseStack matrix, ItemStack item) {
RenderSystem.enableBlend();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.disableCull();

for(var pair: CoordinateCasterCrystal.getCoordinates(item)) {
BlockPos pos = pair.getLeft();
Direction direction = pair.getRight();
Expand All @@ -58,6 +58,7 @@ public static void render(PoseStack matrix, ItemStack item) {
case WEST -> x += 1;
case EAST -> xo -= 1;
}

if(direction.getAxis() == Direction.Axis.Z) {
builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);

Expand Down Expand Up @@ -86,7 +87,7 @@ public static void render(PoseStack matrix, ItemStack item) {
z
).setColor(BOX_COLOR);

builder.build();
mesh = builder.build();
} else {
builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);

Expand Down Expand Up @@ -115,7 +116,11 @@ public static void render(PoseStack matrix, ItemStack item) {
z
).setColor(BOX_COLOR);

builder.build();
mesh = builder.build();
}

if(mesh != null) {
BufferUploader.drawWithShader(mesh);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.ssblur.scriptor.helpers.ComponentHelper;
import com.ssblur.scriptor.helpers.targetable.Targetable;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -65,8 +64,6 @@ public List<Targetable> getTargetables(ItemStack itemStack, Level level) {
@Override
public void appendHoverText(ItemStack itemStack, TooltipContext level, List<Component> list, TooltipFlag tooltipFlag) {
super.appendHoverText(itemStack, level, list, tooltipFlag);
var font = Minecraft.getInstance().font;

var coordinates = getCoordinates(itemStack);
for(var pair: coordinates) {
var coordinate = pair.getLeft();
Expand Down Expand Up @@ -98,8 +95,11 @@ public static void addCoordinate(ItemStack itemStack, BlockPos pos, Direction di
var list = itemStack.get(ScriptorDataComponents.COORDINATES);
if(list == null)
list = new ArrayList<>();
if(list.size() < 4)
if(list.size() < 4) {
list = new ArrayList<>(list);
list.add(List.of(pos.getX(), pos.getY(), pos.getZ(), direction.ordinal()));
}
itemStack.set(ScriptorDataComponents.COORDINATES, list);
}

public static List<BlockPosDirection> getCoordinates(ItemStack itemStack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public class ScriptorEventsExpectPlatformImpl extends ScriptorExpectPlatform {
public static void registerClientEvents() {
WorldRenderEvents.BEFORE_ENTITIES.register(context -> {
Thread.yield();
WorldRenderEvents.AFTER_ENTITIES.register(context -> {
CoordinateCasterWorldRenderer.render(context.matrixStack());
Thread.yield();
});
}
}

0 comments on commit 4ed088c

Please sign in to comment.