mirror of
https://github.com/GTNewHorizons/waila.git
synced 2026-11-28 15:56:20 +00:00
Added skeleton DataAccessorCommon that will be used instead of individual Accessors (via param interface cast)
IWailaTooltipRenderer uses this new more generic accessor. All internals of the accessors are now private.
This commit is contained in:
1 parent
14bee7ab58
commit
9050654e42
13 files changed
+200
-43
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package mcp.mobius.waila.api;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* The Accessor is used to get some basic data out of the game without having to request direct access to the game engine.<br>
|
||||
* It will also return things that are unmodified by the overriding systems (like getWailaStack).<br>
|
||||
* Common accessor for both Entity and Block/TileEntity.<br>
|
||||
* Available data depends on what it is called upon (ie : getEntity() will return null if looking at a block, etc).<br>
|
||||
*
|
||||
*/
|
||||
public interface IWailaCommonAccessor {
|
||||
World getWorld();
|
||||
EntityPlayer getPlayer();
|
||||
Block getBlock();
|
||||
int getBlockID();
|
||||
int getMetadata();
|
||||
TileEntity getTileEntity();
|
||||
Entity getEntity();
|
||||
MovingObjectPosition getPosition();
|
||||
Vec3 getRenderingPosition();
|
||||
NBTTagCompound getNBTData();
|
||||
int getNBTInteger(NBTTagCompound tag, String keyname);
|
||||
double getPartialFrame();
|
||||
ForgeDirection getSide();
|
||||
ItemStack getStack();
|
||||
}
|
||||
@@ -5,6 +5,6 @@ import java.awt.Point;
|
||||
|
||||
|
||||
public interface IWailaTooltipRenderer {
|
||||
Dimension getSize(String[] params, IWailaDataAccessor accessor);
|
||||
void draw (String[] params, IWailaDataAccessor accessor, int x, int y);
|
||||
Dimension getSize(String[] params, IWailaCommonAccessor accessor);
|
||||
void draw (String[] params, IWailaCommonAccessor accessor, int x, int y);
|
||||
}
|
||||
@@ -15,18 +15,18 @@ import mcp.mobius.waila.utils.NBTUtil;
|
||||
|
||||
public class DataAccessorBlock implements IWailaDataAccessor {
|
||||
|
||||
public World world;
|
||||
public EntityPlayer player;
|
||||
public MovingObjectPosition mop;
|
||||
public Vec3 renderingvec = null;
|
||||
public Block block;
|
||||
public int blockID;
|
||||
public int metadata;
|
||||
public TileEntity entity;
|
||||
public NBTTagCompound remoteNbt = null;
|
||||
public long timeLastUpdate = System.currentTimeMillis();
|
||||
public double partialFrame;
|
||||
public ItemStack stack;
|
||||
World world;
|
||||
EntityPlayer player;
|
||||
MovingObjectPosition mop;
|
||||
Vec3 renderingvec = null;
|
||||
Block block;
|
||||
int blockID;
|
||||
int metadata;
|
||||
TileEntity entity;
|
||||
NBTTagCompound remoteNbt = null;
|
||||
long timeLastUpdate = System.currentTimeMillis();
|
||||
double partialFrame;
|
||||
ItemStack stack;
|
||||
|
||||
public static DataAccessorBlock instance = new DataAccessorBlock();
|
||||
|
||||
@@ -116,6 +116,10 @@ public class DataAccessorBlock implements IWailaDataAccessor {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setNBTData(NBTTagCompound tag){
|
||||
this.remoteNbt = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNBTInteger(NBTTagCompound tag, String keyname){
|
||||
return NBTUtil.getNBTInteger(tag, keyname);
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package mcp.mobius.waila.api.impl;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import mcp.mobius.waila.api.IWailaCommonAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaEntityAccessor;
|
||||
|
||||
public class DataAccessorCommon implements IWailaCommonAccessor, IWailaDataAccessor, IWailaEntityAccessor{
|
||||
|
||||
public World world;
|
||||
public EntityPlayer player;
|
||||
public MovingObjectPosition mop;
|
||||
public Vec3 renderingvec = null;
|
||||
public Block block;
|
||||
public int blockID;
|
||||
public int metadata;
|
||||
public TileEntity tileEntity;
|
||||
public Entity entity;
|
||||
public NBTTagCompound remoteNbt = null;
|
||||
public long timeLastUpdate = System.currentTimeMillis();
|
||||
public double partialFrame;
|
||||
public ItemStack stack;
|
||||
|
||||
public static DataAccessorCommon instance = new DataAccessorCommon();
|
||||
|
||||
public void set(World _world, EntityPlayer _player, MovingObjectPosition _mop) {
|
||||
this.set(_world, _player, _mop, null, 0.0);
|
||||
}
|
||||
|
||||
public void set(World _world, EntityPlayer _player, MovingObjectPosition _mop, EntityLivingBase viewEntity, double partialTicks) {
|
||||
this.world = _world;
|
||||
this.player = _player;
|
||||
this.mop = _mop;
|
||||
|
||||
if (this.mop.typeOfHit == MovingObjectType.BLOCK){
|
||||
//this.blockID = world.getBlockId(_mop.blockX, _mop.blockY, _mop.blockZ);
|
||||
//this.block = Block.blocksList[this.blockID];
|
||||
this.block = world.getBlock(_mop.blockX, _mop.blockY, _mop.blockZ);
|
||||
this.metadata = world.getBlockMetadata(_mop.blockX, _mop.blockY, _mop.blockZ);
|
||||
this.tileEntity = world.getTileEntity(_mop.blockX, _mop.blockY, _mop.blockZ);
|
||||
try{ this.stack = new ItemStack(this.block, 1, this.metadata); } catch (Exception e) {}
|
||||
} else if (this.mop.typeOfHit == MovingObjectType.ENTITY){
|
||||
this.entity = _mop.entityHit;
|
||||
}
|
||||
|
||||
if (viewEntity != null){
|
||||
double px = viewEntity.lastTickPosX + (viewEntity.posX - viewEntity.lastTickPosX) * partialTicks;
|
||||
double py = viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * partialTicks;
|
||||
double pz = viewEntity.lastTickPosZ + (viewEntity.posZ - viewEntity.lastTickPosZ) * partialTicks;
|
||||
this.renderingvec = Vec3.createVectorHelper(_mop.blockX - px, _mop.blockY - py, _mop.blockZ - pz);
|
||||
this.partialFrame = partialTicks;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {return null;}
|
||||
|
||||
@Override
|
||||
public EntityPlayer getPlayer() {return null;}
|
||||
|
||||
@Override
|
||||
public Block getBlock() {return null;}
|
||||
|
||||
@Override
|
||||
public int getBlockID() {return 0;}
|
||||
|
||||
@Override
|
||||
public int getMetadata() {return 0;}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity() {return null;}
|
||||
|
||||
@Override
|
||||
public Entity getEntity() {return null;}
|
||||
|
||||
@Override
|
||||
public MovingObjectPosition getPosition() {return null;}
|
||||
|
||||
@Override
|
||||
public Vec3 getRenderingPosition() {return null;}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTData() {return null;}
|
||||
|
||||
@Override
|
||||
public int getNBTInteger(NBTTagCompound tag, String keyname) {return 0;}
|
||||
|
||||
@Override
|
||||
public double getPartialFrame() {return 0;}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getSide() {return null;}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {return null;}
|
||||
|
||||
}
|
||||
@@ -12,14 +12,14 @@ import mcp.mobius.waila.utils.NBTUtil;
|
||||
|
||||
public class DataAccessorEntity implements IWailaEntityAccessor {
|
||||
|
||||
public World world;
|
||||
public EntityPlayer player;
|
||||
public MovingObjectPosition mop;
|
||||
public Vec3 renderingvec = null;
|
||||
public Entity entity;
|
||||
public NBTTagCompound remoteNbt = null;
|
||||
public long timeLastUpdate = System.currentTimeMillis();
|
||||
public double partialFrame;
|
||||
World world;
|
||||
EntityPlayer player;
|
||||
MovingObjectPosition mop;
|
||||
Vec3 renderingvec = null;
|
||||
Entity entity;
|
||||
NBTTagCompound remoteNbt = null;
|
||||
long timeLastUpdate = System.currentTimeMillis();
|
||||
double partialFrame;
|
||||
|
||||
public static DataAccessorEntity instance = new DataAccessorEntity();
|
||||
|
||||
@@ -97,6 +97,10 @@ public class DataAccessorEntity implements IWailaEntityAccessor {
|
||||
return NBTUtil.getNBTInteger(tag, keyname);
|
||||
}
|
||||
|
||||
public void setNBTData(NBTTagCompound tag){
|
||||
this.remoteNbt = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3 getRenderingPosition() {
|
||||
return this.renderingvec;
|
||||
|
||||
@@ -11,16 +11,16 @@ import mcp.mobius.waila.utils.NBTUtil;
|
||||
|
||||
public class DataAccessorFMP implements IWailaFMPAccessor {
|
||||
|
||||
public String id;
|
||||
public World world;
|
||||
public EntityPlayer player;
|
||||
public MovingObjectPosition mop;
|
||||
public Vec3 renderingvec = null;
|
||||
public TileEntity entity;
|
||||
public NBTTagCompound partialNBT = null;
|
||||
public NBTTagCompound remoteNBT = null;
|
||||
public long timeLastUpdate = System.currentTimeMillis();
|
||||
public double partialFrame;
|
||||
String id;
|
||||
World world;
|
||||
EntityPlayer player;
|
||||
MovingObjectPosition mop;
|
||||
Vec3 renderingvec = null;
|
||||
TileEntity entity;
|
||||
NBTTagCompound partialNBT = null;
|
||||
NBTTagCompound remoteNBT = null;
|
||||
long timeLastUpdate = System.currentTimeMillis();
|
||||
double partialFrame;
|
||||
|
||||
public static DataAccessorFMP instance = new DataAccessorFMP();
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class MetaDataProvider{
|
||||
try{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
accessor.getTileEntity().writeToNBT(tag);
|
||||
accessor.remoteNbt = tag;
|
||||
accessor.setNBTData(tag);
|
||||
} catch (Exception e){
|
||||
WailaExceptionHandler.handleErr(e, this.getClass().getName(), null);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Message0x02TENBTData extends SimpleChannelInboundHandler<Message0x0
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, Message0x02TENBTData msg) throws Exception {
|
||||
DataAccessorBlock.instance.remoteNbt = msg.tag;
|
||||
DataAccessorBlock.instance.setNBTData(msg.tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Message0x04EntNBTData extends SimpleChannelInboundHandler<Message0x
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, Message0x04EntNBTData msg) throws Exception {
|
||||
DataAccessorEntity.instance.remoteNbt = msg.tag;
|
||||
DataAccessorEntity.instance.setNBTData(msg.tag);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import mcp.mobius.waila.api.IWailaTooltipRenderer;
|
||||
import mcp.mobius.waila.api.impl.DataAccessorBlock;
|
||||
import mcp.mobius.waila.api.impl.DataAccessorCommon;
|
||||
import mcp.mobius.waila.api.impl.ModuleRegistrar;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -32,7 +33,7 @@ public class DisplayUtil {
|
||||
while (renderMatcher.find()){
|
||||
IWailaTooltipRenderer renderer = ModuleRegistrar.instance().getTooltipRenderer(renderMatcher.group("name"));
|
||||
if (renderer != null)
|
||||
width += renderer.getSize(renderMatcher.group("args").split(","), DataAccessorBlock.instance).width;
|
||||
width += renderer.getSize(renderMatcher.group("args").split(","), DataAccessorCommon.instance).width;
|
||||
}
|
||||
|
||||
width += fontRenderer.getStringWidth(stripSymbols(s));
|
||||
|
||||
@@ -10,10 +10,12 @@ import java.awt.Point;
|
||||
import scala.actors.threadpool.Arrays;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import mcp.mobius.waila.api.IWailaCommonAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaTooltipRenderer;
|
||||
import mcp.mobius.waila.api.impl.ConfigHandler;
|
||||
import mcp.mobius.waila.api.impl.DataAccessorBlock;
|
||||
import mcp.mobius.waila.api.impl.DataAccessorCommon;
|
||||
import mcp.mobius.waila.api.impl.ModuleRegistrar;
|
||||
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderString;
|
||||
import mcp.mobius.waila.utils.Constants;
|
||||
@@ -36,7 +38,7 @@ public class Tooltip {
|
||||
boolean hasIcon = false;
|
||||
ItemStack stack;
|
||||
|
||||
IWailaDataAccessor accessor = DataAccessorBlock.instance;
|
||||
IWailaCommonAccessor accessor = DataAccessorCommon.instance;
|
||||
|
||||
/////////////////////////////////////Renderable///////////////////////////////////////
|
||||
private class Renderable{
|
||||
@@ -62,11 +64,11 @@ public class Tooltip {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
public Dimension getSize(IWailaDataAccessor accessor) {
|
||||
public Dimension getSize(IWailaCommonAccessor accessor) {
|
||||
return this.renderer.getSize(this.params, accessor);
|
||||
}
|
||||
|
||||
public void draw(IWailaDataAccessor accessor, int x, int y) {
|
||||
public void draw(IWailaCommonAccessor accessor, int x, int y) {
|
||||
this.renderer.draw(this.params, accessor, x + this.pos.x, y + this.pos.y);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,18 +2,19 @@ package mcp.mobius.waila.overlay.tooltiprenderers;
|
||||
|
||||
import java.awt.Dimension;
|
||||
|
||||
import mcp.mobius.waila.api.IWailaCommonAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaTooltipRenderer;
|
||||
|
||||
public class TTRenderIcon implements IWailaTooltipRenderer {
|
||||
|
||||
@Override
|
||||
public Dimension getSize(String[] params, IWailaDataAccessor accessor) {
|
||||
public Dimension getSize(String[] params, IWailaCommonAccessor accessor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(String[] params, IWailaDataAccessor accessor, int x, int y) {
|
||||
public void draw(String[] params, IWailaCommonAccessor accessor, int x, int y) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package mcp.mobius.waila.overlay.tooltiprenderers;
|
||||
import java.awt.Dimension;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import mcp.mobius.waila.api.IWailaCommonAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaTooltipRenderer;
|
||||
import mcp.mobius.waila.overlay.DisplayUtil;
|
||||
@@ -19,12 +20,12 @@ public class TTRenderString implements IWailaTooltipRenderer{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize(String[] params, IWailaDataAccessor accessor) {
|
||||
public Dimension getSize(String[] params, IWailaCommonAccessor accessor) {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(String[] params, IWailaDataAccessor accessor, int x, int y) {
|
||||
public void draw(String[] params, IWailaCommonAccessor accessor, int x, int y) {
|
||||
GuiDraw.drawString(data, x, y, OverlayConfig.fontcolor, true);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user