Skip to content

Commit

Permalink
Only render the background translucently if the player is in world
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixaurora committed Jan 24, 2025
1 parent e0d0411 commit c5764d8
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.pixaurora.kitten_cube.impl.ui.screen.align.Alignment;
import net.pixaurora.kitten_cube.impl.ui.texture.GuiTexture;
import net.pixaurora.kitten_cube.impl.ui.widget.event.WindowUpdateEvent;
import net.pixaurora.kitten_heart.impl.KitTunes;

public class TiledBackground implements IncorporealWidget {
private final GuiTexture texture;
Expand All @@ -23,7 +24,7 @@ public TiledBackground(GuiTexture texture) {
@Override
public void draw(GuiDisplay gui, Point mousePos) {
for (Point pos : posToDrawAt) {
gui.drawGui(this.texture, pos, 0.5);
gui.drawGui(this.texture, pos, KitTunes.UI_LAYER.isInWorld() ? 0.5 : 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public interface UICompat extends SoundPlayer, TextProcessor {

public FileAccess accessResource(ResourcePath path) throws IOException;

public default TextField newTextField(TextFieldBackground<GuiTexture> background, Component defaultText, int maxLength) {
public boolean isInWorld();

public default TextField newTextField(TextFieldBackground<GuiTexture> background, Component defaultText,
int maxLength) {
throw new RuntimeException("No implementation for `newTextField` defined!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,9 @@ public FileAccess accessResource(ResourcePath path) throws IOException {
throw new RuntimeException("Can't access regular files yet!");
}
}

@Override
public boolean isInWorld() {
return Minecraft.INSTANCE.world != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,9 @@ public FileAccess accessResource(ResourcePath path) throws IOException {

return FileAccess.create(resource.getInputStream());
}

@Override
public boolean isInWorld() {
return this.client.level != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ public FileAccess accessResource(ResourcePath path) throws IOException {

return FileAccess.create(resource.open());
}

@Override
public boolean isInWorld() {
return this.client.level != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ public FileAccess accessResource(ResourcePath path) throws IOException {

return FileAccess.create(resource.open());
}

@Override
public boolean isInWorld() {
return this.client.level != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ public FileAccess accessResource(ResourcePath path) throws IOException {

return FileAccess.create(resource.open());
}

@Override
public boolean isInWorld() {
return this.client.level != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ public FileAccess accessResource(ResourcePath path) throws IOException {

return FileAccess.create(resource.open());
}

@Override
public boolean isInWorld() {
return this.client.level != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ public FileAccess accessResource(ResourcePath path) throws IOException {

return FileAccess.create(resource.open());
}

@Override
public boolean isInWorld() {
return this.client.level != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ public FileAccess accessResource(ResourcePath path) throws IOException {

return FileAccess.create(resource.open());
}

@Override
public boolean isInWorld() {
return this.client.level != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public FileAccess accessResource(ResourcePath path) throws IOException {
return FileAccess.create(resource.open());
}

@Override
public boolean isInWorld() {
return this.client.level != null;
}

@Override
public TextField newTextField(TextFieldBackground<GuiTexture> background, Component defaultText, int maxLength) {
return new TextFieldImpl(this.client.font, background, defaultText, maxLength);
Expand All @@ -138,7 +143,8 @@ public TextField newTextField(TextFieldBackground<GuiTexture> background, Compon
@Override
public void addTextField(Screen screen, TextField field) {
if (!(field instanceof TextFieldImpl)) {
throw new RuntimeException("Internal text field is of an unconvertable type `" + field.getClass().getName() + "`!");
throw new RuntimeException(
"Internal text field is of an unconvertable type `" + field.getClass().getName() + "`!");
}

internalToMinecraftType(screen, false).addRenderableWidget((TextFieldImpl) field);
Expand Down

0 comments on commit c5764d8

Please sign in to comment.