-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump Version to 1.4.37 Took 2 hours 16 minutes
- Loading branch information
Showing
22 changed files
with
402 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/main/java/org/teacon/powertool/client/gui/TextureExtractorScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.teacon.powertool.client.gui; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.EditBox; | ||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import net.minecraft.client.renderer.texture.TextureAtlas; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.neoforged.neoforge.client.model.data.ModelData; | ||
import org.teacon.powertool.client.gui.widget.TextureAtlasSpriteList; | ||
import org.teacon.powertool.menu.TextureExtractorMenu; | ||
import org.teacon.powertool.utils.VanillaUtils; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
@MethodsReturnNonnullByDefault | ||
@ParametersAreNonnullByDefault | ||
public class TextureExtractorScreen extends AbstractContainerScreen<TextureExtractorMenu> { | ||
|
||
private static final ResourceLocation BG_LOCATION = VanillaUtils.modRL("textures/gui/texture_extractor.png"); | ||
|
||
protected TextureAtlasSpriteList textureAtlasSpriteList; | ||
private EditBox searchBar; | ||
|
||
public TextureExtractorScreen(TextureExtractorMenu menu, Inventory playerInventory, Component title) { | ||
super(menu, playerInventory, title); | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
super.init(); | ||
this.textureAtlasSpriteList = new TextureAtlasSpriteList(this, (int) (width*0.3), (int) (height*0.8),(int)(height*0.1),30); | ||
this.searchBar = new EditBox(font, (int) (10+width*0.1),(int)(height*0.9+5),(int) (width*0.2),20,Component.empty()); | ||
this.searchBar.setResponder((str) -> menu.needRefreshFilter = true); | ||
this.searchBar.setMaxLength(1000); | ||
this.addRenderableWidget(textureAtlasSpriteList); | ||
this.addRenderableWidget(searchBar); | ||
} | ||
|
||
@Override | ||
protected void containerTick() { | ||
super.containerTick(); | ||
if(menu.needRefreshFilter){ | ||
textureAtlasSpriteList.update(); | ||
menu.needRefreshFilter = false; | ||
} | ||
} | ||
|
||
public List<ResourceLocation> getFilteredTextures() { | ||
var filteredTexturesSet = new HashSet<ResourceLocation>(); | ||
var mc = Minecraft.getInstance(); | ||
var item = menu.targetContainer.getItem(0); | ||
if(item.isEmpty()){ | ||
//noinspection deprecation | ||
filteredTexturesSet.addAll(mc.getModelManager().getAtlas(TextureAtlas.LOCATION_BLOCKS).getTextures().keySet()); | ||
} | ||
else { | ||
var model = mc.getItemRenderer().getModel(item,mc.level,mc.player,943); | ||
var quads = model.getQuads(null,null, RandomSource.create(943), ModelData.EMPTY,null); | ||
filteredTexturesSet.add(model.getParticleIcon(ModelData.EMPTY).contents().name()); | ||
filteredTexturesSet.addAll(quads.stream().map(quad -> quad.getSprite().contents().name()).toList()); | ||
} | ||
return filteredTexturesSet.stream().filter(rl -> { | ||
if(searchBar == null) return true; | ||
var str = searchBar.getValue().toLowerCase(); | ||
if (str.isEmpty()) return true; | ||
return rl.toString().contains(str); | ||
}).sorted(Comparator.comparing(ResourceLocation::toString)).toList(); | ||
} | ||
|
||
@Override | ||
public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) { | ||
if(textureAtlasSpriteList.mouseDragged(mouseX,mouseY,button,dragX,dragY)) return true; | ||
return super.mouseDragged(mouseX, mouseY, button, dragX, dragY); | ||
} | ||
|
||
@Override | ||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) { | ||
if(searchBar.keyPressed(keyCode,scanCode,modifiers)) return true; | ||
if(searchBar.isFocused() && searchBar.isActive()) return true; | ||
return super.keyPressed(keyCode, scanCode, modifiers); | ||
} | ||
|
||
@Override | ||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) { | ||
if(searchBar.keyReleased(keyCode,scanCode,modifiers)) return true; | ||
return super.keyReleased(keyCode, scanCode, modifiers); | ||
} | ||
|
||
@Override | ||
public boolean charTyped(char codePoint, int modifiers) { | ||
if(searchBar.charTyped(codePoint,modifiers)) return true; | ||
return super.charTyped(codePoint, modifiers); | ||
} | ||
|
||
@Override | ||
protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) { | ||
RenderSystem.setShader(GameRenderer::getPositionTexShader); | ||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
guiGraphics.blit(BG_LOCATION, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); | ||
} | ||
|
||
@Override | ||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { | ||
super.render(guiGraphics, mouseX, mouseY, partialTick); | ||
var str = "Search: "; | ||
guiGraphics.drawString(font,str,(int) (10+width*0.1)-font.width(str)-2,(int)(height*0.9+5+2),-1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/main/java/org/teacon/powertool/client/gui/widget/TextureAtlasSpriteList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package org.teacon.powertool.client.gui.widget; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.Button; | ||
import net.minecraft.client.gui.components.Tooltip; | ||
import net.minecraft.client.gui.components.events.GuiEventListener; | ||
import net.minecraft.client.gui.narration.NarratableEntry; | ||
import net.minecraft.client.renderer.texture.TextureAtlas; | ||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.teacon.powertool.client.gui.TextureExtractorScreen; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
public class TextureAtlasSpriteList extends EntryListWidget<TextureExtractorScreen, TextureAtlasSpriteList.Entry> { | ||
|
||
public TextureAtlasSpriteList(TextureExtractorScreen screen, int width, int height, int y, int itemHeight) { | ||
super(screen, width, height, y, itemHeight); | ||
} | ||
|
||
@Override | ||
void init(TextureExtractorScreen screen) { | ||
this.setX(10); | ||
update(); | ||
} | ||
|
||
public void update(){ | ||
var entries = entries().size(); | ||
this.clearEntries(); | ||
var list = screen.getFilteredTextures(); | ||
var columns = (width-25)/25; | ||
var buf = new ArrayList<ResourceLocation>(); | ||
for(var i = 0; i < list.size()/columns; i++){ | ||
for(var j = 0; j < columns; j++){ | ||
buf.add(list.get(i*columns+j)); | ||
} | ||
this.addEntry(new Entry(id,buf)); | ||
buf.clear(); | ||
} | ||
for(var i = 0; i < list.size()%columns; i++){ | ||
buf.add(list.get(list.size()/columns + i)); | ||
} | ||
this.addEntry(new Entry(id,buf)); | ||
if(entries != entries().size()){ | ||
this.setScrollAmount(0); | ||
} | ||
} | ||
|
||
@Override | ||
public int getRowWidth() { | ||
return width-30; | ||
} | ||
|
||
public static class Entry extends EntryListWidget.Entry<Entry> { | ||
public int id; | ||
public final List<ResourceLocation> textures = new ArrayList<>(); | ||
protected final List<Button> spriteButtons = new ArrayList<>(); | ||
|
||
public Entry(int id, List<ResourceLocation> texture) { | ||
this.id = id; | ||
for(var rl : texture){ | ||
textures.add(rl); | ||
var button = new BlockSpriteButton(rl,-1,-1,20,20,Component.empty(),(b) -> Minecraft.getInstance().keyboardHandler.setClipboard(rl.toString())); | ||
button.setTooltip(Tooltip.create(Component.literal(rl.toString()))); | ||
spriteButtons.add(button); | ||
} | ||
} | ||
|
||
@Override | ||
public void setID(int id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public int getID() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public Entry copyWithID(int id) { | ||
return new Entry(id, textures); | ||
} | ||
|
||
@Override | ||
public List<? extends NarratableEntry> narratables() { | ||
return spriteButtons; | ||
} | ||
|
||
@Override | ||
public void render(GuiGraphics guiGraphics, int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean hovering, float partialTick) { | ||
var i = 0; | ||
for (var button : spriteButtons) { | ||
button.setPosition(left + i*25,top); | ||
button.render(guiGraphics, mouseX, mouseY, partialTick); | ||
i+=1; | ||
} | ||
} | ||
|
||
@Override | ||
public List<? extends GuiEventListener> children() { | ||
return spriteButtons; | ||
} | ||
} | ||
|
||
public static class BlockSpriteButton extends Button { | ||
public final ResourceLocation texture; | ||
private final TextureAtlasSprite sprite; | ||
protected BlockSpriteButton(ResourceLocation texture,int x, int y, int width, int height, Component message, OnPress onPress) { | ||
super(x, y, width, height, message, onPress, Button.DEFAULT_NARRATION); | ||
this.texture = texture; | ||
//noinspection deprecation | ||
sprite = Minecraft.getInstance().getModelManager().getAtlas(TextureAtlas.LOCATION_BLOCKS).getSprite(texture); | ||
} | ||
|
||
@Override | ||
protected void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { | ||
if(this.isHoveredOrFocused()){ | ||
guiGraphics.hLine(getX(),getX()+getWidth(),getY(),-1); | ||
guiGraphics.hLine(getX(),getX()+getWidth(),getY()+getHeight(),-1); | ||
guiGraphics.vLine(getX(),getY(),getY()+getHeight(),-1); | ||
guiGraphics.vLine(getX()+getWidth(),getY(),getY()+getHeight(),-1); | ||
} | ||
guiGraphics.blitSprite(sprite,getX()+1,getY()+1,0,getWidth()-1,getHeight()-1); | ||
} | ||
|
||
@Override | ||
public void renderString(GuiGraphics guiGraphics, Font font, int color) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.