aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java26
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java1
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java5
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java50
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java8
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java10
7 files changed, 42 insertions, 62 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java
index 2cb1de6..3c4d8ad 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java
@@ -115,17 +115,17 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
}
@Override
- public ItemStack onSlotClick(int slotNumber, int button, SlotActionType action, PlayerEntity player) {
+ public void onSlotClick(int slotNumber, int button, SlotActionType action, PlayerEntity player) {
if (action==SlotActionType.QUICK_MOVE) {
if (slotNumber < 0) {
- return ItemStack.EMPTY;
+ return;
}
- if (slotNumber>=this.slots.size()) return ItemStack.EMPTY;
+ if (slotNumber>=this.slots.size()) return;
Slot slot = this.slots.get(slotNumber);
if (slot == null || !slot.canTakeItems(player)) {
- return ItemStack.EMPTY;
+ return;
}
ItemStack remaining = ItemStack.EMPTY;
@@ -137,15 +137,15 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
if (slot.inventory==blockInventory) {
//Try to transfer the item from the block into the player's inventory
if (!this.insertItem(toTransfer, this.playerInventory, true, player)) {
- return ItemStack.EMPTY;
+ return;
}
} else if (!this.insertItem(toTransfer, this.blockInventory, false, player)) { //Try to transfer the item from the player to the block
- return ItemStack.EMPTY;
+ return;
}
} else {
//There's no block, just swap between the player's storage and their hotbar
if (!swapHotbar(toTransfer, slotNumber, this.playerInventory, player)) {
- return ItemStack.EMPTY;
+ return;
}
}
@@ -156,16 +156,14 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
}
}
- return remaining;
- } else {
- return super.onSlotClick(slotNumber, button, action, player);
+ super.onSlotClick(slotNumber, button, action, player);
}
}
/** WILL MODIFY toInsert! Returns true if anything was inserted. */
private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) {
ItemStack curSlotStack = slot.getStack();
- if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack) && slot.canInsert(toInsert)) {
+ if (!curSlotStack.isEmpty() && ItemStack.canCombine(toInsert, curSlotStack) && slot.canInsert(toInsert)) {
int combinedAmount = curSlotStack.getCount() + toInsert.getCount();
int maxAmount = Math.min(toInsert.getMaxCount(), slot.getMaxItemCount(toInsert));
if (combinedAmount <= maxAmount) {
@@ -384,7 +382,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
}
private static Inventory getBlockInventory(ScreenHandlerContext ctx, Supplier<Inventory> fallback) {
- return ctx.run((world, pos) -> {
+ return ctx.get((world, pos) -> {
BlockState state = world.getBlockState(pos);
Block b = state.getBlock();
@@ -422,7 +420,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
* @return the found property delegate
*/
public static PropertyDelegate getBlockPropertyDelegate(ScreenHandlerContext ctx) {
- return ctx.run((world, pos) -> {
+ return ctx.get((world, pos) -> {
BlockEntity be = world.getBlockEntity(pos);
if (be!=null && be instanceof PropertyDelegateHolder) {
return ((PropertyDelegateHolder)be).getPropertyDelegate();
@@ -446,7 +444,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio
* @since 2.0.0
*/
public static PropertyDelegate getBlockPropertyDelegate(ScreenHandlerContext ctx, int size) {
- return ctx.run((world, pos) -> {
+ return ctx.get((world, pos) -> {
BlockEntity be = world.getBlockEntity(pos);
if (be!=null && be instanceof PropertyDelegateHolder) {
return ((PropertyDelegateHolder)be).getPropertyDelegate();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
index fa27766..2acc371 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
@@ -127,7 +127,6 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl {
}
}
- @SuppressWarnings("deprecation")
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
paint(matrices, mouseX, mouseY);
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
index 2ddf84a..68f28fe 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
@@ -44,7 +44,7 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl
* @param title the screen title
*/
public CottonInventoryScreen(T description, PlayerEntity player, Text title) {
- super(description, player.inventory, title);
+ super(description, player.getInventory(), title);
this.description = description;
width = 18*9;
height = 18*9;
@@ -251,13 +251,12 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl
}
}
- @SuppressWarnings("deprecation")
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
paint(matrices, mouseX, mouseY);
super.render(matrices, mouseX, mouseY, partialTicks);
- DiffuseLighting.disable(); //Needed because super.render leaves dirty state
+ DiffuseLighting.disableGuiDepthLighting(); //Needed because super.render leaves dirty state
if (description!=null) {
WPanel root = description.getRootPanel();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
index d9d5da8..7fae1bf 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
@@ -1,10 +1,13 @@
package io.github.cottonmc.cotton.gui.client;
-import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.render.BufferBuilder;
+import net.minecraft.client.render.BufferRenderer;
+import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
+import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;
@@ -18,7 +21,6 @@ import io.github.cottonmc.cotton.gui.widget.data.Texture;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
-import org.lwjgl.opengl.GL11;
/**
* {@code ScreenDrawing} contains utility methods for drawing contents on a screen.
@@ -130,10 +132,6 @@ public class ScreenDrawing {
* @since 2.0.0
*/
public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color, float opacity) {
- MinecraftClient.getInstance().getTextureManager().bindTexture(texture);
-
- //float scale = 0.00390625F;
-
if (width <= 0) width = 1;
if (height <= 0) height = 1;
@@ -143,17 +141,16 @@ public class ScreenDrawing {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
Matrix4f model = matrices.peek().getModel();
- RenderSystem.enableBlend();
- //GlStateManager.disableTexture2D();
- RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
- buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE); //I thought GL_QUADS was deprecated but okay, sure.
- buffer.vertex(model, x, y + height, 0).color(r, g, b, opacity).texture(u1, v2).next();
- buffer.vertex(model, x + width, y + height, 0).color(r, g, b, opacity).texture(u2, v2).next();
- buffer.vertex(model, x + width, y, 0).color(r, g, b, opacity).texture(u2, v1).next();
- buffer.vertex(model, x, y, 0).color(r, g, b, opacity).texture(u1, v1).next();
- tessellator.draw();
- //GlStateManager.enableTexture2D();
- RenderSystem.disableBlend();
+ RenderSystem.setShaderTexture(0, texture);
+ RenderSystem.setShaderColor(r, g, b, opacity);
+ RenderSystem.setShader(GameRenderer::method_34542);
+ buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
+ buffer.vertex(model, x, y + height, 0).texture(u1, v2).next();
+ buffer.vertex(model, x + width, y + height, 0).texture(u2, v2).next();
+ buffer.vertex(model, x + width, y, 0).texture(u2, v1).next();
+ buffer.vertex(model, x, y, 0).texture(u1, v1).next();
+ buffer.end();
+ BufferRenderer.draw(buffer);
}
/**
@@ -200,24 +197,7 @@ public class ScreenDrawing {
if (width <= 0) width = 1;
if (height <= 0) height = 1;
- float a = (color >> 24 & 255) / 255.0F;
- float r = (color >> 16 & 255) / 255.0F;
- float g = (color >> 8 & 255) / 255.0F;
- float b = (color & 255) / 255.0F;
- Tessellator tessellator = Tessellator.getInstance();
- BufferBuilder buffer = tessellator.getBuffer();
- Matrix4f model = matrices.peek().getModel();
- RenderSystem.enableBlend();
- RenderSystem.disableTexture();
- RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
- buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR); //I thought GL_QUADS was deprecated but okay, sure.
- buffer.vertex(model, left, top + height, 0).color(r, g, b, a).next();
- buffer.vertex(model, left + width, top + height, 0).color(r, g, b, a).next();
- buffer.vertex(model, left + width, top, 0).color(r, g, b, a).next();
- buffer.vertex(model, left, top, 0).color(r, g, b, a).next();
- tessellator.draw();
- RenderSystem.enableTexture();
- RenderSystem.disableBlend();
+ DrawableHelper.fill(matrices, left, top, left + width, top + height, color);
}
/**
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
index 5403bff..911d547 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
@@ -3,9 +3,9 @@ package io.github.cottonmc.cotton.gui.widget;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.client.util.math.Vector3f;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
+import net.minecraft.util.math.Vec3f;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.data.Axis;
@@ -169,7 +169,7 @@ public class WLabeledSlider extends WAbstractSlider {
matrices.translate(x, y, 0);
if (axis == Axis.VERTICAL) {
matrices.translate(0, height, 0);
- matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(270));
+ matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(270));
}
drawButton(matrices, 0, 0, 0, aWidth);
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
index c9fd92e..ac3c8bf 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
@@ -8,7 +8,9 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.render.BufferBuilder;
+import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
+import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
@@ -20,7 +22,6 @@ import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.data.InputResult;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
-import org.lwjgl.opengl.GL11;
import java.util.function.Consumer;
import java.util.function.Predicate;
@@ -404,11 +405,12 @@ public class WTextField extends WWidget {
private void invertedRect(int x, int y, int width, int height) {
Tessellator tessellator_1 = Tessellator.getInstance();
BufferBuilder bufferBuilder_1 = tessellator_1.getBuffer();
- RenderSystem.color4f(0.0F, 0.0F, 255.0F, 255.0F);
+ RenderSystem.setShaderColor(0.0F, 0.0F, 1.0F, 1.0F);
+ RenderSystem.setShader(GameRenderer::method_34542);
RenderSystem.disableTexture();
RenderSystem.enableColorLogicOp();
RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE);
- bufferBuilder_1.begin(GL11.GL_QUADS, VertexFormats.POSITION);
+ bufferBuilder_1.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
bufferBuilder_1.vertex(x, y+height, 0.0D).next();
bufferBuilder_1.vertex(x+width, y+height, 0.0D).next();
bufferBuilder_1.vertex(x+width, y, 0.0D).next();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
index b5fb85e..2575d36 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
@@ -43,15 +43,17 @@ public class ItemIcon implements Icon {
@Environment(EnvType.CLIENT)
@Override
public void paint(MatrixStack matrices, int x, int y, int size) {
+ // TODO: Make this not ignore the actual matrices
MinecraftClient client = MinecraftClient.getInstance();
ItemRenderer renderer = client.getItemRenderer();
+ MatrixStack modelViewMatrices = RenderSystem.getModelViewStack();
float scale = size != 16 ? ((float) size / 16f) : 1f;
- RenderSystem.pushMatrix();
- RenderSystem.translatef(x, y, 0);
- RenderSystem.scalef(scale, scale, 1);
+ modelViewMatrices.push();
+ modelViewMatrices.translate(x, y, 0);
+ modelViewMatrices.scale(scale, scale, 1);
renderer.renderInGui(stack, 0, 0);
- RenderSystem.popMatrix();
+ modelViewMatrices.pop();
}
}