mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 19:15:11 +00:00
Caching Some Paths for Efficiency
This commit is contained in:
1 parent
79955f549e
commit
efcdeecbf2
3 files changed
+328
-311
No files matched your search
@@ -7,84 +7,101 @@ import net.minecraft.client.audio.SoundHandler;
|
||||
import net.minecraft.client.audio.SoundRegistry;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.controllers.MusicController;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollListener{
|
||||
public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollListener {
|
||||
|
||||
private GuiCustomScroll scrollCategories;
|
||||
private GuiCustomScroll scrollSounds;
|
||||
private GuiCustomScroll scrollCategories;
|
||||
private GuiCustomScroll scrollSounds;
|
||||
|
||||
private String selectedDomain;
|
||||
public ResourceLocation selectedResource;
|
||||
private String selectedDomain;
|
||||
public ResourceLocation selectedResource;
|
||||
|
||||
private String catSearch = "";
|
||||
private String soundSearch = "";
|
||||
|
||||
private HashMap<String,List<String>> domains = new HashMap<String,List<String>>();
|
||||
// Map: domain -> list of sound paths
|
||||
private HashMap<String, List<String>> domains = new HashMap<>();
|
||||
|
||||
public GuiSoundSelection(String sound){
|
||||
drawDefaultBackground = false;
|
||||
title = "";
|
||||
setBackground("menubg.png");
|
||||
xSize = 366;
|
||||
ySize = 226;
|
||||
// --- Cache static fields ---
|
||||
private static final long CACHE_DURATION = 180000L; // 3 minutes in ms
|
||||
private static long lastCacheTime = 0;
|
||||
public static HashMap<String, List<String>> cachedDomains = new HashMap<>();
|
||||
|
||||
SoundHandler handler = Minecraft.getMinecraft().getSoundHandler();
|
||||
SoundRegistry registry = ReflectionHelper.getPrivateValue(SoundHandler.class, handler, 4);
|
||||
public GuiSoundSelection(String sound) {
|
||||
drawDefaultBackground = false;
|
||||
title = "";
|
||||
setBackground("menubg.png");
|
||||
xSize = 366;
|
||||
ySize = 226;
|
||||
|
||||
Set<ResourceLocation> set = registry.getKeys();
|
||||
for(ResourceLocation location : set){
|
||||
List<String> list = domains.get(location.getResourceDomain());
|
||||
if(list == null)
|
||||
domains.put(location.getResourceDomain(), list = new ArrayList<String>());
|
||||
list.add(location.getResourcePath());
|
||||
domains.put(location.getResourceDomain(), list);
|
||||
}
|
||||
if(sound != null && !sound.isEmpty()){
|
||||
selectedResource = new ResourceLocation(sound);
|
||||
selectedDomain = selectedResource.getResourceDomain();
|
||||
if(!domains.containsKey(selectedDomain)) {
|
||||
selectedDomain = null;
|
||||
}
|
||||
}
|
||||
long now = System.currentTimeMillis();
|
||||
// Use cached data if it's fresh
|
||||
if (now - lastCacheTime < CACHE_DURATION && !cachedDomains.isEmpty()) {
|
||||
domains.putAll(cachedDomains);
|
||||
} else {
|
||||
// Otherwise, load domains from the SoundRegistry
|
||||
SoundHandler handler = Minecraft.getMinecraft().getSoundHandler();
|
||||
SoundRegistry registry = ReflectionHelper.getPrivateValue(SoundHandler.class, handler, 4);
|
||||
Set<ResourceLocation> set = registry.getKeys();
|
||||
for (ResourceLocation location : set) {
|
||||
List<String> list = domains.get(location.getResourceDomain());
|
||||
if (list == null) {
|
||||
domains.put(location.getResourceDomain(), list = new ArrayList<String>());
|
||||
}
|
||||
list.add(location.getResourcePath());
|
||||
}
|
||||
// Update the static cache
|
||||
cachedDomains.clear();
|
||||
cachedDomains.putAll(domains);
|
||||
lastCacheTime = now;
|
||||
}
|
||||
if (sound != null && !sound.isEmpty()) {
|
||||
selectedResource = new ResourceLocation(sound);
|
||||
selectedDomain = selectedResource.getResourceDomain();
|
||||
if (!domains.containsKey(selectedDomain)) {
|
||||
selectedDomain = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
this.addButton(new GuiNpcButton(2, guiLeft + xSize - 45, guiTop + ySize - 35, 40, 20, "gui.done"));
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + ySize - 35, 70, 20, "gui.play"));
|
||||
this.addButton(new GuiNpcButton(2, guiLeft + xSize - 45, guiTop + ySize - 35, 40, 20, "gui.done"));
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + ySize - 35, 70, 20, "gui.play"));
|
||||
getButton(1).enabled = selectedResource != null;
|
||||
|
||||
if(scrollCategories == null){
|
||||
scrollCategories = new GuiCustomScroll(this,0, 0);
|
||||
scrollCategories.setSize(90, 163);
|
||||
if (scrollCategories == null) {
|
||||
scrollCategories = new GuiCustomScroll(this, 0);
|
||||
scrollCategories.setSize(90, 163);
|
||||
}
|
||||
scrollCategories.setList(Lists.newArrayList(domains.keySet()));
|
||||
if(selectedDomain != null) {
|
||||
scrollCategories.setSelected(selectedDomain);
|
||||
if (selectedDomain != null) {
|
||||
scrollCategories.setSelected(selectedDomain);
|
||||
}
|
||||
|
||||
scrollCategories.guiLeft = guiLeft + 4;
|
||||
scrollCategories.guiTop = guiTop + 4;
|
||||
this.addScroll(scrollCategories);
|
||||
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 4, guiTop + 169, 90, 20, catSearch));
|
||||
|
||||
if(scrollSounds == null){
|
||||
scrollSounds = new GuiCustomScroll(this,1, 0);
|
||||
scrollSounds.setSize(265, 163);
|
||||
if (scrollSounds == null) {
|
||||
scrollSounds = new GuiCustomScroll(this, 1);
|
||||
scrollSounds.setSize(265, 163);
|
||||
}
|
||||
if(selectedDomain != null) {
|
||||
scrollSounds.setList(domains.get(selectedDomain));
|
||||
if (selectedDomain != null) {
|
||||
scrollSounds.setList(domains.get(selectedDomain));
|
||||
}
|
||||
if(selectedResource != null) {
|
||||
scrollSounds.setSelected(selectedResource.getResourcePath());
|
||||
if (selectedResource != null) {
|
||||
scrollSounds.setSelected(selectedResource.getResourcePath());
|
||||
}
|
||||
scrollSounds.guiLeft = guiLeft + 95;
|
||||
scrollSounds.guiTop = guiTop + 4;
|
||||
@@ -93,25 +110,24 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
|
||||
addTextField(new GuiNpcTextField(66, this, fontRendererObj, guiLeft + 95, guiTop + 169, 265, 20, soundSearch));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton){
|
||||
super.actionPerformed(guibutton);
|
||||
if(guibutton.id == 1){
|
||||
MusicController.Instance.stopMusic();
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton){
|
||||
super.actionPerformed(guibutton);
|
||||
if (guibutton.id == 1) {
|
||||
MusicController.Instance.stopMusic();
|
||||
MusicController.Instance.playSound(selectedResource.toString(), (float)player.posX, (float)player.posY, (float)player.posZ);
|
||||
}
|
||||
if(guibutton.id == 2){
|
||||
close();
|
||||
if (guibutton.id == 2) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if(selectedResource == null)
|
||||
return;
|
||||
close();
|
||||
}
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (selectedResource == null)
|
||||
return;
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
@@ -121,7 +137,7 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
||||
if(guiCustomScroll.id == 0){
|
||||
if (guiCustomScroll.id == 0) {
|
||||
selectedDomain = guiCustomScroll.getSelected();
|
||||
selectedResource = null;
|
||||
scrollSounds.selected = -1;
|
||||
@@ -129,15 +145,14 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
|
||||
getTextField(66).setText("");
|
||||
soundSearch = "";
|
||||
}
|
||||
if(guiCustomScroll.id == 1){
|
||||
if (guiCustomScroll.id == 1) {
|
||||
selectedResource = new ResourceLocation(selectedDomain, guiCustomScroll.getSelected());
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i)
|
||||
{
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if(getTextField(55) != null){
|
||||
if(getTextField(55).isFocused()){
|
||||
@@ -175,7 +190,6 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
|
||||
if(selectedDomain == null){
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
if(soundSearch.isEmpty()){
|
||||
return new ArrayList<String>(this.domains.get(selectedDomain));
|
||||
}
|
||||
|
||||
@@ -29,114 +29,130 @@ import java.util.zip.ZipFile;
|
||||
|
||||
public class GuiTextureSelection extends SubGuiInterface implements ICustomScrollListener {
|
||||
|
||||
private final String up = "..<" + StatCollector.translateToLocal("gui.up") + ">..";
|
||||
private GuiCustomScroll scrollCategories;
|
||||
private GuiCustomScroll scrollTextures;
|
||||
private final String up = "..<" + StatCollector.translateToLocal("gui.up") + ">..";
|
||||
private GuiCustomScroll scrollCategories;
|
||||
private GuiCustomScroll scrollTextures;
|
||||
|
||||
private String location = "";
|
||||
private String selectedDomain;
|
||||
public ResourceLocation selectedResource;
|
||||
private String location = "";
|
||||
private String selectedDomain;
|
||||
public ResourceLocation selectedResource;
|
||||
|
||||
private final HashMap<String,List<TextureData>> domains = new HashMap<String,List<TextureData>>();
|
||||
private final HashMap<String, TextureData> textures = new HashMap<String, TextureData>();
|
||||
// Instance maps to be populated
|
||||
private final HashMap<String, List<TextureData>> domains = new HashMap<>();
|
||||
private final HashMap<String, TextureData> textures = new HashMap<>();
|
||||
|
||||
// --- Cache static fields ---
|
||||
private static final long CACHE_DURATION = 180000L; // 3 minutes in milliseconds
|
||||
private static long lastCacheTime = 0;
|
||||
private static HashMap<String, List<TextureData>> cachedDomains = new HashMap<>();
|
||||
public static HashMap<String, TextureData> cachedTextures = new HashMap<>();
|
||||
|
||||
public GuiTextureSelection(EntityNPCInterface npc, String texture){
|
||||
this.npc = npc;
|
||||
drawDefaultBackground = false;
|
||||
title = "";
|
||||
setBackground("menubg.png");
|
||||
xSize = 366;
|
||||
ySize = 226;
|
||||
this.npc = npc;
|
||||
drawDefaultBackground = false;
|
||||
title = "";
|
||||
setBackground("menubg.png");
|
||||
xSize = 366;
|
||||
ySize = 226;
|
||||
|
||||
SimpleReloadableResourceManager simplemanager = (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
|
||||
|
||||
Map<String, FallbackResourceManager> map = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, simplemanager, 2);
|
||||
HashSet<String> set = new HashSet<String>();
|
||||
for(String name: map.keySet()){
|
||||
if(!(map.get(name) instanceof FallbackResourceManager))
|
||||
continue;
|
||||
FallbackResourceManager manager = (FallbackResourceManager) map.get(name);
|
||||
List<IResourcePack> list = ObfuscationReflectionHelper.getPrivateValue(FallbackResourceManager.class, manager, 0);
|
||||
for(IResourcePack pack : list){
|
||||
if(pack instanceof AbstractResourcePack){
|
||||
AbstractResourcePack p = (AbstractResourcePack) pack;
|
||||
File file = NPCResourceHelper.getPackFile(p);
|
||||
if(file != null)
|
||||
set.add(file.getAbsolutePath());
|
||||
// First, try to use cached domain data if it exists and is recent
|
||||
long now = System.currentTimeMillis();
|
||||
if(cachedDomains != null && now - lastCacheTime < CACHE_DURATION) {
|
||||
domains.putAll(cachedDomains);
|
||||
textures.putAll(cachedTextures);
|
||||
}
|
||||
else {
|
||||
// Build the domains and textures maps
|
||||
SimpleReloadableResourceManager simplemanager = (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
|
||||
Map<String, FallbackResourceManager> map = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, simplemanager, 2);
|
||||
HashSet<String> set = new HashSet<String>();
|
||||
for(String name: map.keySet()){
|
||||
if(!(map.get(name) instanceof FallbackResourceManager))
|
||||
continue;
|
||||
FallbackResourceManager manager = (FallbackResourceManager) map.get(name);
|
||||
List<IResourcePack> list = ObfuscationReflectionHelper.getPrivateValue(FallbackResourceManager.class, manager, 0);
|
||||
for(IResourcePack pack : list){
|
||||
if(pack instanceof AbstractResourcePack){
|
||||
AbstractResourcePack p = (AbstractResourcePack) pack;
|
||||
File file = NPCResourceHelper.getPackFile(p);
|
||||
if(file != null)
|
||||
set.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(String file : set){
|
||||
File f = new File(file);
|
||||
if(f.isDirectory()) {
|
||||
checkFolder(new File(f, "assets"), f.getAbsolutePath().length());
|
||||
}
|
||||
else {
|
||||
progressFile(f);
|
||||
}
|
||||
}
|
||||
for (ModContainer mod : Loader.instance().getModList()) {
|
||||
if(mod.getSource().exists())
|
||||
progressFile(mod.getSource());
|
||||
for(String file : set){
|
||||
File f = new File(file);
|
||||
if(f.isDirectory()) {
|
||||
checkFolder(new File(f, "assets"), f.getAbsolutePath().length());
|
||||
}
|
||||
else {
|
||||
progressFile(f);
|
||||
}
|
||||
}
|
||||
for (ModContainer mod : Loader.instance().getModList()) {
|
||||
if(mod.getSource().exists())
|
||||
progressFile(mod.getSource());
|
||||
}
|
||||
ResourcePackRepository repos = Minecraft.getMinecraft().getResourcePackRepository();
|
||||
repos.updateRepositoryEntriesAll();
|
||||
List<ResourcePackRepository.Entry> list = repos.getRepositoryEntries();
|
||||
for(ResourcePackRepository.Entry entry : list) {
|
||||
File file = new File(repos.getDirResourcepacks(), entry.getResourcePackName());
|
||||
if(file.exists()){
|
||||
progressFile(file);
|
||||
}
|
||||
}
|
||||
checkFolder(new File(CustomNpcs.Dir, "assets"), CustomNpcs.Dir.getAbsolutePath().length());
|
||||
URL url = DefaultResourcePack.class.getResource("/");
|
||||
if(url != null) {
|
||||
File f = decodeFile(url.getFile());
|
||||
if(f.isDirectory()) {
|
||||
checkFolder(new File(f, "assets"), url.getFile().length());
|
||||
}
|
||||
else {
|
||||
progressFile(f);
|
||||
}
|
||||
}
|
||||
url = CraftingManager.class.getResource("/assets/.mcassetsroot");
|
||||
if(url != null) {
|
||||
File f = decodeFile(url.getFile());
|
||||
if(f.isDirectory()) {
|
||||
checkFolder(new File(f, "assets"), url.getFile().length());
|
||||
}
|
||||
else {
|
||||
progressFile(f);
|
||||
}
|
||||
}
|
||||
// Update the cache
|
||||
cachedDomains = new HashMap<>(domains);
|
||||
cachedTextures = new HashMap<>(textures);
|
||||
lastCacheTime = now;
|
||||
}
|
||||
|
||||
ResourcePackRepository repos = Minecraft.getMinecraft().getResourcePackRepository();
|
||||
repos.updateRepositoryEntriesAll();
|
||||
List<ResourcePackRepository.Entry> list = repos.getRepositoryEntries();
|
||||
for(ResourcePackRepository.Entry entry : list) {
|
||||
File file = new File(repos.getDirResourcepacks(),entry.getResourcePackName());
|
||||
if(file.exists()){
|
||||
progressFile(file);
|
||||
}
|
||||
}
|
||||
checkFolder(new File(CustomNpcs.Dir,"assets"),CustomNpcs.Dir.getAbsolutePath().length());
|
||||
|
||||
URL url = DefaultResourcePack.class.getResource("/");
|
||||
if(url != null) {
|
||||
File f = decodeFile(url.getFile());
|
||||
if(f.isDirectory()) {
|
||||
checkFolder(new File(f,"assets"), url.getFile().length());
|
||||
}
|
||||
else {
|
||||
progressFile(f);
|
||||
}
|
||||
if(texture != null && !texture.isEmpty()){
|
||||
selectedResource = new ResourceLocation(texture);
|
||||
selectedDomain = selectedResource.getResourceDomain();
|
||||
if(!domains.containsKey(selectedDomain)) {
|
||||
selectedDomain = null;
|
||||
}
|
||||
int i = selectedResource.getResourcePath().lastIndexOf('/');
|
||||
location = selectedResource.getResourcePath().substring(0, i + 1);
|
||||
}
|
||||
|
||||
url = CraftingManager.class.getResource("/assets/.mcassetsroot");
|
||||
if(url != null) {
|
||||
File f = decodeFile(url.getFile());
|
||||
if(f.isDirectory()) {
|
||||
checkFolder(new File(f,"assets"), url.getFile().length());
|
||||
}
|
||||
else {
|
||||
progressFile(f);
|
||||
}
|
||||
}
|
||||
|
||||
if(texture != null && !texture.isEmpty()){
|
||||
selectedResource = new ResourceLocation(texture);
|
||||
selectedDomain = selectedResource.getResourceDomain();
|
||||
if(!domains.containsKey(selectedDomain)) {
|
||||
selectedDomain = null;
|
||||
}
|
||||
int i = selectedResource.getResourcePath().lastIndexOf('/');
|
||||
location = selectedResource.getResourcePath().substring(0, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private File decodeFile(String url) {
|
||||
if(url.startsWith("file:")) {
|
||||
url = url.substring(5);
|
||||
}
|
||||
url = url.replace('/', File.separatorChar);
|
||||
int i = url.indexOf('!');
|
||||
if(i > 0) {
|
||||
url = url.substring(0, i);
|
||||
}
|
||||
try {
|
||||
url = URLDecoder.decode(url, StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException ignored) {
|
||||
}
|
||||
return new File(url);
|
||||
if(url.startsWith("file:")) {
|
||||
url = url.substring(5);
|
||||
}
|
||||
url = url.replace('/', File.separatorChar);
|
||||
int i = url.indexOf('!');
|
||||
if(i > 0) {
|
||||
url = url.substring(0, i);
|
||||
}
|
||||
try {
|
||||
url = URLDecoder.decode(url, StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException ignored) {}
|
||||
return new File(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,39 +163,38 @@ public class GuiTextureSelection extends SubGuiInterface implements ICustomScrol
|
||||
title = selectedDomain + ":" + location;
|
||||
}
|
||||
else {
|
||||
title = "";
|
||||
title = "";
|
||||
}
|
||||
|
||||
this.addButton(new GuiNpcButton(2, guiLeft + 264, guiTop + 170, 90, 20, "gui.done"));
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 264, guiTop + 190, 90, 20, "gui.cancel"));
|
||||
this.addButton(new GuiNpcButton(2, guiLeft + 264, guiTop + 170, 90, 20, "gui.done"));
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 264, guiTop + 190, 90, 20, "gui.cancel"));
|
||||
|
||||
if(scrollCategories == null){
|
||||
scrollCategories = new GuiCustomScroll(this,0);
|
||||
scrollCategories.setSize(120, 200);
|
||||
scrollCategories = new GuiCustomScroll(this, 0);
|
||||
scrollCategories.setSize(120, 200);
|
||||
}
|
||||
|
||||
if(selectedDomain == null) {
|
||||
scrollCategories.setList(Lists.newArrayList(domains.keySet()));
|
||||
if(selectedDomain != null) {
|
||||
scrollCategories.setSelected(selectedDomain);
|
||||
scrollCategories.setSelected(selectedDomain);
|
||||
}
|
||||
}
|
||||
else {
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(up);
|
||||
List<TextureData> data = domains.get(selectedDomain);
|
||||
for(TextureData td : data) {
|
||||
if(location.isEmpty() || td.path.startsWith(location) && !td.path.equals(location)) {
|
||||
String path = td.path.substring(location.length());
|
||||
int i = path.indexOf('/');
|
||||
if(i < 0)
|
||||
continue;
|
||||
path = path.substring(0, i);
|
||||
if(!path.isEmpty() && !list.contains(path)) {
|
||||
list.add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(up);
|
||||
List<TextureData> data = domains.get(selectedDomain);
|
||||
for(TextureData td : data) {
|
||||
if(location.isEmpty() || td.path.startsWith(location) && !td.path.equals(location)) {
|
||||
String path = td.path.substring(location.length());
|
||||
int i = path.indexOf('/');
|
||||
if(i < 0)
|
||||
continue;
|
||||
path = path.substring(0, i);
|
||||
if(!path.isEmpty() && !list.contains(path)) {
|
||||
list.add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
scrollCategories.setList(list);
|
||||
}
|
||||
scrollCategories.guiLeft = guiLeft + 4;
|
||||
@@ -187,67 +202,64 @@ public class GuiTextureSelection extends SubGuiInterface implements ICustomScrol
|
||||
this.addScroll(scrollCategories);
|
||||
|
||||
if(scrollTextures == null){
|
||||
scrollTextures = new GuiCustomScroll(this,1);
|
||||
scrollTextures.setSize(130, 200);
|
||||
scrollTextures = new GuiCustomScroll(this, 1);
|
||||
scrollTextures.setSize(130, 200);
|
||||
}
|
||||
if(selectedDomain != null) {
|
||||
textures.clear();
|
||||
List<TextureData> data = domains.get(selectedDomain);
|
||||
List<String> list = new ArrayList<String>();
|
||||
String loc = location;
|
||||
if(scrollCategories.hasSelected() && !scrollCategories.getSelected().equals(up)) {
|
||||
loc += scrollCategories.getSelected() + '/';
|
||||
}
|
||||
for(TextureData td : data) {
|
||||
if(td.path.equals(loc) && !list.contains(td.name)) {
|
||||
list.add(td.name);
|
||||
textures.put(td.name, td);
|
||||
}
|
||||
}
|
||||
scrollTextures.setList(list);
|
||||
textures.clear();
|
||||
List<TextureData> data = domains.get(selectedDomain);
|
||||
List<String> list = new ArrayList<String>();
|
||||
String loc = location;
|
||||
if(scrollCategories.hasSelected() && !scrollCategories.getSelected().equals(up)) {
|
||||
loc += scrollCategories.getSelected() + '/';
|
||||
}
|
||||
for(TextureData td : data) {
|
||||
if(td.path.equals(loc) && !list.contains(td.name)) {
|
||||
list.add(td.name);
|
||||
textures.put(td.name, td);
|
||||
}
|
||||
}
|
||||
scrollTextures.setList(list);
|
||||
}
|
||||
if(selectedResource != null) {
|
||||
scrollTextures.setSelected(selectedResource.getResourcePath());
|
||||
scrollTextures.setSelected(selectedResource.getResourcePath());
|
||||
}
|
||||
scrollTextures.guiLeft = guiLeft + 125;
|
||||
scrollTextures.guiTop = guiTop + 14;
|
||||
this.addScroll(scrollTextures);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton){
|
||||
super.actionPerformed(guibutton);
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton){
|
||||
super.actionPerformed(guibutton);
|
||||
if(guibutton.id == 2){
|
||||
npc.display.setSkinTexture(selectedResource.toString());
|
||||
npc.display.setSkinTexture(selectedResource.toString());
|
||||
}
|
||||
npc.textureLocation = null;
|
||||
close();
|
||||
parent.initGui();
|
||||
close();
|
||||
parent.initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int i, int j, float f){
|
||||
super.drawScreen(i, j, f);
|
||||
|
||||
npc.textureLocation = selectedResource;
|
||||
npc.textureLocation = selectedResource;
|
||||
drawNpc(npc, 307, 150, 1.5F, 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
||||
if(scroll == scrollTextures) {
|
||||
if(scroll.id == 1){
|
||||
TextureData data = textures.get(scroll.getSelected());
|
||||
selectedResource = new ResourceLocation(selectedDomain, data.absoluteName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
initGui();
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
||||
if(scroll == scrollTextures) {
|
||||
if(scroll.id == 1){
|
||||
TextureData data = textures.get(scroll.getSelected());
|
||||
selectedResource = new ResourceLocation(selectedDomain, data.absoluteName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
initGui();
|
||||
scrollTextures.resetScroll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
@@ -281,90 +293,89 @@ public class GuiTextureSelection extends SubGuiInterface implements ICustomScrol
|
||||
}
|
||||
}
|
||||
|
||||
private void progressFile(File file){
|
||||
try {
|
||||
if (!file.isDirectory() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip")))
|
||||
{
|
||||
ZipFile zip = new ZipFile(file);
|
||||
Enumeration<? extends ZipEntry> entries = zip.entries();
|
||||
while(entries.hasMoreElements()){
|
||||
ZipEntry zipentry = entries.nextElement();
|
||||
String entryName = zipentry.getName();
|
||||
addFile(entryName);
|
||||
}
|
||||
zip.close();
|
||||
}
|
||||
else if(file.isDirectory()){
|
||||
int length = file.getAbsolutePath().length();
|
||||
checkFolder(file,length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void progressFile(File file){
|
||||
try {
|
||||
if (!file.isDirectory() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip"))) {
|
||||
ZipFile zip = new ZipFile(file);
|
||||
Enumeration<? extends ZipEntry> entries = zip.entries();
|
||||
while(entries.hasMoreElements()){
|
||||
ZipEntry zipentry = entries.nextElement();
|
||||
String entryName = zipentry.getName();
|
||||
addFile(entryName);
|
||||
}
|
||||
zip.close();
|
||||
}
|
||||
else if(file.isDirectory()){
|
||||
int length = file.getAbsolutePath().length();
|
||||
checkFolder(file, length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFolder(File file, int length){
|
||||
File[] files = file.listFiles();
|
||||
if(files == null){
|
||||
return;
|
||||
}
|
||||
for(File f : files){
|
||||
String name = null;
|
||||
try {
|
||||
name = f.getAbsolutePath().substring(length);
|
||||
name = name.replace("\\", "/");
|
||||
private void checkFolder(File file, int length){
|
||||
File[] files = file.listFiles();
|
||||
if(files == null){
|
||||
return;
|
||||
}
|
||||
for(File f : files){
|
||||
String name = null;
|
||||
try {
|
||||
name = f.getAbsolutePath().substring(length);
|
||||
name = name.replace("\\", "/");
|
||||
if(!name.startsWith("/"))
|
||||
name = "/" + name;
|
||||
if(f.isDirectory()){
|
||||
addFile(name + "/");
|
||||
checkFolder(f, length);
|
||||
}
|
||||
else
|
||||
addFile(name);
|
||||
}
|
||||
catch(Throwable e) {
|
||||
LogWriter.error("error with: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void addFile(String name) {
|
||||
if(name.startsWith("/")) {
|
||||
name = name.substring(1);
|
||||
}
|
||||
if(!name.startsWith("assets/") || !name.endsWith(".png")) {
|
||||
return;
|
||||
}
|
||||
name = name.substring(7);
|
||||
int i = name.indexOf('/');
|
||||
String domain = name.substring(0, i);
|
||||
name = name.substring(i + 1);
|
||||
name = "/" + name;
|
||||
if(f.isDirectory()){
|
||||
addFile(name + "/");
|
||||
checkFolder(f, length);
|
||||
}
|
||||
else
|
||||
addFile(name);
|
||||
}
|
||||
catch(Throwable e) {
|
||||
LogWriter.error("error with: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void addFile(String name) {
|
||||
if(name.startsWith("/")) {
|
||||
name = name.substring(1);
|
||||
}
|
||||
if(!name.startsWith("assets/") || !name.endsWith(".png")) {
|
||||
return;
|
||||
}
|
||||
name = name.substring(7);
|
||||
int i = name.indexOf('/');
|
||||
String domain = name.substring(0, i);
|
||||
name = name.substring(i + 1);
|
||||
|
||||
List<TextureData> list = domains.get(domain);
|
||||
if(list == null) {
|
||||
domains.put(domain, list = new ArrayList<TextureData>());
|
||||
}
|
||||
boolean contains = false;
|
||||
for(TextureData data : list) {
|
||||
if(data.absoluteName.equals(name)) {
|
||||
contains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!contains)
|
||||
list.add(new TextureData(domain, name));
|
||||
}
|
||||
|
||||
List<TextureData> list = domains.get(domain);
|
||||
if(list == null) {
|
||||
domains.put(domain, list = new ArrayList<TextureData>());
|
||||
}
|
||||
boolean contains = false;
|
||||
for(TextureData data : list) {
|
||||
if(data.absoluteName.equals(name)) {
|
||||
contains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!contains)
|
||||
list.add(new TextureData(domain, name));
|
||||
}
|
||||
|
||||
static class TextureData {
|
||||
String domain;
|
||||
String absoluteName;
|
||||
String name;
|
||||
String path;
|
||||
public TextureData(String domain, String absoluteName) {
|
||||
this.domain = domain;
|
||||
int i = absoluteName.lastIndexOf('/');
|
||||
name = absoluteName.substring(i + 1);
|
||||
path = absoluteName.substring(0, i + 1);
|
||||
this.absoluteName = absoluteName;
|
||||
}
|
||||
}
|
||||
String domain;
|
||||
String absoluteName;
|
||||
String name;
|
||||
String path;
|
||||
public TextureData(String domain, String absoluteName) {
|
||||
this.domain = domain;
|
||||
int i = absoluteName.lastIndexOf('/');
|
||||
name = absoluteName.substring(i + 1);
|
||||
path = absoluteName.substring(0, i + 1);
|
||||
this.absoluteName = absoluteName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -689,15 +689,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
public EntityProjectile shoot(double x, double y, double z, int accuracy, ItemStack proj, boolean indirect){
|
||||
EntityProjectile projectile = new EntityProjectile(this.worldObj, this, proj.copy(), true);
|
||||
|
||||
double throwerHeight = this.getEyeHeight(); // default eye height
|
||||
if (this.currentAnimation == EnumAnimation.LYING || this.currentAnimation == EnumAnimation.CRAWLING) {
|
||||
// When lying or crawling, assume the effective throw point is roughly halfway up the entity
|
||||
throwerHeight = this.height * 0.5;
|
||||
} else if (this.currentAnimation == EnumAnimation.SITTING) {
|
||||
// When sitting, adjust accordingly (example factor)
|
||||
throwerHeight = this.height * 0.7;
|
||||
}
|
||||
|
||||
double throwerHeight = this.getEyeHeight();
|
||||
double varX = x - this.posX;
|
||||
double varY = y - (this.posY + throwerHeight);
|
||||
double varZ = z - this.posZ;
|
||||
|
||||
Reference in new issue
Block a user