players = new HashSet<>();
players.add(Minecraft.getMinecraft().thePlayer.getName());
GlStateManager.color(1, 1, 1, 1);
Runnable runnable = this.closedCallback;
this.closedCallback = null;
Minecraft.getMinecraft().displayGuiScreen(new GuiPositionEditorButForTheDungeonMap(
NotEnoughUpdates.INSTANCE.config.dungeonMap.dmPosition,
size, size, () -> {
ScaledResolution scaledResolution = Utils.pushGuiScale(2);
demoMap.renderMap(
NotEnoughUpdates.INSTANCE.config.dungeonMap.dmPosition.getAbsX(scaledResolution, size) + size / 2,
NotEnoughUpdates.INSTANCE.config.dungeonMap.dmPosition.getAbsY(scaledResolution, size) + size / 2,
NotEnoughUpdates.INSTANCE.colourMap,
decorations,
0,
players,
false,
0
);
Utils.pushGuiScale(-1);
}, () -> {}, () -> NotEnoughUpdates.INSTANCE.openGui = new GuiDungeonMapEditor(runnable)
).withScale(2));
return;
}
}
blurField.otherComponentClick();
}
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
if (activeColourEditor != null) {
ScaledResolution realRes = new ScaledResolution(Minecraft.getMinecraft());
int mouseX = Mouse.getEventX() * realRes.getScaledWidth() / this.mc.displayWidth;
int mouseY =
realRes.getScaledHeight() - Mouse.getEventY() * realRes.getScaledHeight() / this.mc.displayHeight - 1;
activeColourEditor.mouseInput(mouseX, mouseY);
}
}
@Override
public void handleKeyboardInput() throws IOException {
super.handleKeyboardInput();
if (activeColourEditor != null) {
activeColourEditor.keyboardInput();
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
super.keyTyped(typedChar, keyCode);
if (blurField.getFocus()) {
blurField.keyTyped(typedChar, keyCode);
try {
blurField.setCustomBorderColour(-1);
NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBackgroundBlur = Float.parseFloat(blurField.getText());
} catch (Exception e) {
blurField.setCustomBorderColour(Color.RED.getRGB());
}
}
}
private void buttonClicked(int mouseX, int mouseY, int id) {
DungeonMapConfig options = NotEnoughUpdates.INSTANCE.config.dungeonMap;
switch (id) {
case 0:
options.dmBorderSize = 0;
break;
case 1:
options.dmBorderSize = 1;
break;
case 2:
options.dmBorderSize = 2;
break;
case 30:
options.dmBorderSize = 3;
break;
case 3:
options.dmRoomSize = 0;
break;
case 4:
options.dmRoomSize = 1;
break;
case 5:
options.dmRoomSize = 2;
break;
case 29:
options.dmRoomSize = 3;
break;
case 18:
options.dmEnable = !options.dmEnable;
break;
case 19:
options.dmCenterPlayer = !options.dmCenterPlayer;
break;
case 20:
options.dmRotatePlayer = !options.dmRotatePlayer;
break;
case 21:
options.dmPlayerHeads++;
if (options.dmPlayerHeads > 2) options.dmPlayerHeads = 0;
break;
case 22:
options.dmOrientCheck = !options.dmOrientCheck;
break;
case 23:
options.dmCenterCheck = !options.dmCenterCheck;
break;
case 24:
options.dmPlayerInterp = !options.dmPlayerInterp;
break;
case 25:
options.dmCompat++;
if (options.dmCompat > 2) options.dmCompat = 0;
break;
case 26: {
ScaledResolution realRes = new ScaledResolution(Minecraft.getMinecraft());
mouseX = Mouse.getEventX() * realRes.getScaledWidth() / this.mc.displayWidth;
mouseY = realRes.getScaledHeight() - Mouse.getEventY() * realRes.getScaledHeight() / this.mc.displayHeight - 1;
activeColourEditor = new GuiElementColour(mouseX, mouseY, () -> options.dmBackgroundColour,
(col) -> options.dmBackgroundColour = col, () -> activeColourEditor = null
);
}
break;
case 27: {
ScaledResolution realRes = new ScaledResolution(Minecraft.getMinecraft());
mouseX = Mouse.getEventX() * realRes.getScaledWidth() / this.mc.displayWidth;
mouseY = realRes.getScaledHeight() - Mouse.getEventY() * realRes.getScaledHeight() / this.mc.displayHeight - 1;
activeColourEditor = new GuiElementColour(mouseX, mouseY, () -> options.dmBorderColour,
(col) -> options.dmBorderColour = col, () -> activeColourEditor = null
);
}
break;
case 28:
options.dmChromaBorder = !options.dmChromaBorder;
break;
default:
if (id >= 6 && id <= 17) {
options.dmBorderStyle = id - 6;
break;
}
}
}
private boolean isButtonPressed(int id) {
DungeonMapConfig options = NotEnoughUpdates.INSTANCE.config.dungeonMap;
if (id >= 0 && id <= 2) {
return options.dmBorderSize == id;
} else if (id >= 3 && id <= 5) {
return options.dmRoomSize == id - 3;
} else if (id >= 6 && id <= 17) {
return options.dmBorderStyle == id - 6;
} else if (id == 29) {
return options.dmRoomSize == 3;
} else if (id == 30) {
return options.dmBorderSize == 3;
}
return false;
}
Shader blurShaderHorz = null;
Framebuffer blurOutputHorz = null;
Shader blurShaderVert = null;
Framebuffer blurOutputVert = null;
/**
* Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate
* space [-1 -> 1; 1 -> -1] (Note: flipped y-axis).
*
* This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to
* apply scales and translations manually.
*/
private Matrix4f createProjectionMatrix(int width, int height) {
Matrix4f projMatrix = new Matrix4f();
projMatrix.setIdentity();
projMatrix.m00 = 2.0F / (float) width;
projMatrix.m11 = 2.0F / (float) (-height);
projMatrix.m22 = -0.0020001999F;
projMatrix.m33 = 1.0F;
projMatrix.m03 = -1.0F;
projMatrix.m13 = 1.0F;
projMatrix.m23 = -1.0001999F;
return projMatrix;
}
private double lastBgBlurFactor = -1;
private void blurBackground() {
if (!OpenGlHelper.isFramebufferEnabled()) return;
int width = Minecraft.getMinecraft().displayWidth;
int height = Minecraft.getMinecraft().displayHeight;
if (blurOutputHorz == null) {
blurOutputHorz = new Framebuffer(width, height, false);
blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST);
}
if (blurOutputVert == null) {
blurOutputVert = new Framebuffer(width, height, false);
blurOutputVert.setFramebufferFilter(GL11.GL_NEAREST);
}
if (blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) {
blurOutputHorz.createBindFramebuffer(width, height);
blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height));
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false);
}
if (blurOutputVert.framebufferWidth != width || blurOutputVert.framebufferHeight != height) {
blurOutputVert.createBindFramebuffer(width, height);
blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height));
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false);
}
if (blurShaderHorz == null) {
try {
blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur",
Minecraft.getMinecraft().getFramebuffer(), blurOutputHorz
);
blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0);
blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height));
} catch (Exception ignored) {
}
}
if (blurShaderVert == null) {
try {
blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur",
blurOutputHorz, blurOutputVert
);
blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1);
blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height));
} catch (Exception ignored) {
}
}
if (blurShaderHorz != null && blurShaderVert != null) {
if (15 != lastBgBlurFactor) {
blurShaderHorz.getShaderManager().getShaderUniform("Radius").set((float) 15);
blurShaderVert.getShaderManager().getShaderUniform("Radius").set((float) 15);
lastBgBlurFactor = 15;
}
GL11.glPushMatrix();
blurShaderHorz.loadShader(0);
blurShaderVert.loadShader(0);
GlStateManager.enableDepth();
GL11.glPopMatrix();
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false);
}
}
/**
* Renders a subsection of the blurred framebuffer on to the corresponding section of the screen.
* Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight]
*/
public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) {
if (!OpenGlHelper.isFramebufferEnabled()) return;
float uMin = x / (float) width;
float uMax = (x + blurWidth) / (float) width;
float vMin = (height - y) / (float) height;
float vMax = (height - y - blurHeight) / (float) height;
blurOutputVert.bindFramebufferTexture();
GlStateManager.color(1f, 1f, 1f, 1f);
Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax);
blurOutputVert.unbindFramebufferTexture();
}
@Override
public void onGuiClosed() {
if (this.closedCallback != null) {
this.closedCallback.run();
}
}
}