mirror of
https://github.com/GTNewHorizons/waila.git
synced 2026-11-19 03:49:17 +00:00
Added a more generic Interface for the TipList so I can modify what is going on later on if needed.
This commit is contained in:
1 parent
ae10c1cad2
commit
8c77c19e94
5 files changed
+71
-30
No files matched your search
+1
-1
@@ -35,7 +35,7 @@ apply plugin: 'java'
|
||||
apply plugin: 'forge'
|
||||
apply plugin: 'maven'
|
||||
|
||||
version = "1.5.7_dev1_1.7.10"
|
||||
version = "1.5.7_1.7.10"
|
||||
group= "mcp.mobius.waila" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "Waila"
|
||||
|
||||
|
||||
+3
-3
@@ -11,8 +11,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataProvider;
|
||||
import mcp.mobius.waila.api.impl.TipList;
|
||||
import mcp.mobius.waila.utils.WailaExceptionHandler;
|
||||
import mcp.mobius.waila.api.ITaggedList;
|
||||
|
||||
public class HUDHandlerIEnergyHandler implements IWailaDataProvider {
|
||||
|
||||
@@ -35,8 +35,8 @@ public class HUDHandlerIEnergyHandler implements IWailaDataProvider {
|
||||
int energy = accessor.getNBTInteger(accessor.getNBTData(), "Energy");
|
||||
int maxEnergy = accessor.getNBTInteger(accessor.getNBTData(), "MaxStorage");
|
||||
try {
|
||||
if ((maxEnergy != 0) && (((TipList)currenttip).getEntries("RFEnergyStorage").size() == 0)){
|
||||
((TipList)currenttip).add(String.format("%d / %d RF", energy, maxEnergy), "RFEnergyStorage");
|
||||
if ((maxEnergy != 0) && (((ITaggedList)currenttip).getEntries("RFEnergyStorage").size() == 0)){
|
||||
((ITaggedList)currenttip).add(String.format("%d / %d RF", energy, maxEnergy), "RFEnergyStorage");
|
||||
}
|
||||
} catch (Exception e){
|
||||
currenttip = WailaExceptionHandler.handleErr(e, accessor.getTileEntity().getClass().getName(), currenttip);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package mcp.mobius.waila.api;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public interface ITaggedList<E, T> extends List<E> {
|
||||
public boolean add(E e, T tag);
|
||||
public boolean add(E e, Collection<? extends T> taglst);
|
||||
public Set<T> getTags(E e);
|
||||
public Set<T> getTags(int index);
|
||||
public void addTag(E e, T tag);
|
||||
public void addTag(int index, T tag);
|
||||
public void removeTag(E e, T tag);
|
||||
public void removeTag(int index, T tag);
|
||||
public Set<E> getEntries(T tag);
|
||||
public void removeEntries(T tag);
|
||||
public String getTagsAsString(E e);
|
||||
}
|
||||
@@ -9,77 +9,90 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class TipList<E> extends ArrayList<E> {
|
||||
Map<E, Set<String>> tags = new HashMap();
|
||||
import mcp.mobius.waila.api.ITaggedList;
|
||||
|
||||
public class TipList<E, T> extends ArrayList<E> implements ITaggedList<E, T> {
|
||||
Map<E, Set<T>> tags = new HashMap();
|
||||
|
||||
public boolean add(E e, String tag){
|
||||
@Override
|
||||
public boolean add(E e, T tag){
|
||||
if (!tags.containsKey(e))
|
||||
tags.put(e, new HashSet<String>());
|
||||
tags.put(e, new HashSet<T>());
|
||||
tags.get(e).add(tag);
|
||||
return super.add(e);
|
||||
}
|
||||
|
||||
public boolean add(E e, List<String> taglst){
|
||||
|
||||
@Override
|
||||
public boolean add(E e, Collection<? extends T> taglst){
|
||||
if (!tags.containsKey(e))
|
||||
tags.put(e, new HashSet<String>());
|
||||
tags.put(e, new HashSet<T>());
|
||||
tags.get(e).addAll(taglst);
|
||||
|
||||
return super.add(e);
|
||||
}
|
||||
|
||||
public Set<String> getTags(E e){
|
||||
Set<String> ret = tags.get(e);
|
||||
@Override
|
||||
public Set<T> getTags(E e){
|
||||
Set<T> ret = tags.get(e);
|
||||
if (ret == null && this.contains(e)){
|
||||
tags.put(e, new HashSet<String>());
|
||||
tags.put(e, new HashSet<T>());
|
||||
ret = tags.get(e);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Set<String> getTags(int index){
|
||||
@Override
|
||||
public Set<T> getTags(int index){
|
||||
return this.getTags(this.get(index));
|
||||
}
|
||||
|
||||
public void addTag(E e, String tag){
|
||||
@Override
|
||||
public void addTag(E e, T tag){
|
||||
if (this.contains(e) && !tags.containsKey(e))
|
||||
tags.put(e, new HashSet<String>());
|
||||
tags.put(e, new HashSet<T>());
|
||||
|
||||
tags.get(e).add(tag);
|
||||
}
|
||||
|
||||
public void addTag(int index, String tag){
|
||||
@Override
|
||||
public void addTag(int index, T tag){
|
||||
this.addTag(this.get(index), tag);
|
||||
}
|
||||
|
||||
public void removeTag(E e, String tag){
|
||||
@Override
|
||||
public void removeTag(E e, T tag){
|
||||
if (this.contains(e) && !tags.containsKey(e))
|
||||
tags.put(e, new HashSet<String>());
|
||||
tags.put(e, new HashSet<T>());
|
||||
|
||||
tags.get(e).remove(tag);
|
||||
}
|
||||
|
||||
public void removeTag(int index, String tag){
|
||||
@Override
|
||||
public void removeTag(int index, T tag){
|
||||
this.removeTag(this.get(index), tag);
|
||||
}
|
||||
|
||||
public Set<E> getEntries(String tag){
|
||||
@Override
|
||||
public Set<E> getEntries(T tag){
|
||||
Set<E> ret = new HashSet();
|
||||
for (Entry<E, Set<String>> s : tags.entrySet()){
|
||||
for (Entry<E, Set<T>> s : tags.entrySet()){
|
||||
if (s.getValue().contains(tag))
|
||||
ret.add(s.getKey());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void removeEntries(String tag){
|
||||
@Override
|
||||
public void removeEntries(T tag){
|
||||
for (E e : this.getEntries(tag))
|
||||
this.remove(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTagsAsString(E e){
|
||||
String ret = "";
|
||||
for (String s : tags.get(e))
|
||||
ret += s + ",";
|
||||
for (T s : tags.get(e))
|
||||
ret += s.toString() + ",";
|
||||
|
||||
if (ret.length() > 0)
|
||||
ret = ret.substring(0, ret.length()-1);
|
||||
@@ -87,26 +100,31 @@ public class TipList<E> extends ArrayList<E> {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(){
|
||||
tags.clear();
|
||||
super.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E set(int index, E element){
|
||||
tags.remove(this.get(index));
|
||||
return super.set(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E remove(int index){
|
||||
tags.remove(this.get(index));
|
||||
return super.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o){
|
||||
tags.remove(o);
|
||||
return super.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c){
|
||||
for (Object o : c)
|
||||
tags.remove(o);
|
||||
@@ -114,6 +132,7 @@ public class TipList<E> extends ArrayList<E> {
|
||||
return super.removeAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeRange(int fromIndex, int toIndex){
|
||||
for (int i = fromIndex; i < toIndex; i++)
|
||||
tags.remove(this.get(i));
|
||||
@@ -121,6 +140,7 @@ public class TipList<E> extends ArrayList<E> {
|
||||
super.removeRange(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c){
|
||||
for (E e : tags.keySet())
|
||||
if (!c.contains(e))
|
||||
|
||||
@@ -32,10 +32,10 @@ public class WailaTickHandler{
|
||||
|
||||
private int ticks = 0;
|
||||
public ItemStack identifiedHighlight = new ItemStack(Blocks.dirt);
|
||||
private List<String> currenttip = new TipList<String>();
|
||||
private List<String> currenttipHead = new TipList<String>();
|
||||
private List<String> currenttipBody = new TipList<String>();
|
||||
private List<String> currenttipTail = new TipList<String>();
|
||||
private List<String> currenttip = new TipList<String, String>();
|
||||
private List<String> currenttipHead = new TipList<String, String>();
|
||||
private List<String> currenttipBody = new TipList<String, String>();
|
||||
private List<String> currenttipTail = new TipList<String, String>();
|
||||
public Tooltip tooltip = null;
|
||||
public MetaDataProvider handler = new MetaDataProvider();
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
Reference in new issue
Block a user