Skip to content

Commit

Permalink
Merge pull request TeamOpenIndustry#128 from Goldenfield192/1.12.2-forge
Browse files Browse the repository at this point in the history
[1.12.2]Add dropItem with velocity and left-aligned string renderer
  • Loading branch information
cam72cam authored Jun 27, 2024
2 parents 43860b4 + 2ac6b62 commit d384fb2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/main/java/cam72cam/mod/gui/helpers/GUIHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ public static void drawTankBlock(int x, int y, int width, int height, Fluid flui
}
}

/** Draw a left-aligned shadowed string */
public static void drawString(String text, int x, int y, int color) {
drawString(text, x, y, color, new Matrix4());
}
public static void drawString(String text, int x, int y, int color, Matrix4 matrix) {
RenderState state = new RenderState().color(1, 1, 1, 1).alpha_test(true);
state.model_view().multiply(matrix);
try (With ctx = RenderContext.apply(state)) {
GlStateManager.color(1, 1, 1, 0);
Minecraft.getMinecraft().fontRenderer.drawString(text, x, y, color);
}
}

/** Draw a shadowed string offset from the center of coords */
public static void drawCenteredString(String text, int x, int y, int color) {
drawCenteredString(text, x, y, color, new Matrix4());
Expand All @@ -122,6 +135,11 @@ public static void drawCenteredString(String text, int x, int y, int color, Matr
}
}

/** Gat a string's internal width for further use */
public static int getTextWidth(String text) {
return Minecraft.getMinecraft().fontRenderer.getStringWidth(text);
}

/** Screen Width in pixels (std coords) */
public static int getScreenWidth() {
return new ScaledResolution(Minecraft.getMinecraft()).getScaledWidth();
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/cam72cam/mod/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,19 @@ public float getTemperature(Vec3i pos) {

/** Drop a stack on the ground at pos */
public void dropItem(ItemStack stack, Vec3i pos) {
dropItem(stack, new Vec3d(pos));
dropItem(stack, new Vec3d(pos), Vec3d.ZERO);
}

/** Drop a stack on the ground at pos */
public void dropItem(ItemStack stack, Vec3d pos) {
internal.spawnEntity(new EntityItem(internal, pos.x, pos.y, pos.z, stack.internal));
dropItem(stack, pos, Vec3d.ZERO);
}

/** Drop a stack on the ground at pos with velocity */
public void dropItem(ItemStack stack, Vec3d pos, Vec3d velocity) {
EntityItem entity = new EntityItem(internal, pos.x, pos.y, pos.z, stack.internal);
entity.setVelocity(velocity.x, velocity.y, velocity.z);
internal.spawnEntity(entity);
}

/** Check if the block is currently in a loaded chunk */
Expand Down

0 comments on commit d384fb2

Please sign in to comment.