use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.
the class ScreenRenderer method renderModules.
private void renderModules(FontRenderer fontrenderer, ScreenTileEntity tileEntity, IClientScreenModule.TransformMode mode, List<IClientScreenModule> modules, Map<Integer, IModuleData> screenData, int size) {
float f3;
float factor = size + 1.0f;
int currenty = 7;
int moduleIndex = 0;
BlockPos pos = tileEntity.getPos();
RayTraceResult mouseOver = Minecraft.getMinecraft().objectMouseOver;
IClientScreenModule hitModule = null;
ScreenTileEntity.ModuleRaytraceResult hit = null;
IBlockState blockState = getWorld().getBlockState(pos);
Block block = blockState.getBlock();
if (block != ScreenSetup.screenBlock && block != ScreenSetup.creativeScreenBlock && block != ScreenSetup.screenHitBlock) {
// Safety
return;
}
if (mouseOver != null) {
if (mouseOver.sideHit == blockState.getValue(BaseBlock.FACING)) {
double xx = mouseOver.hitVec.x - pos.getX();
double yy = mouseOver.hitVec.y - pos.getY();
double zz = mouseOver.hitVec.z - pos.getZ();
EnumFacing horizontalFacing = blockState.getValue(ScreenBlock.HORIZONTAL_FACING);
hit = tileEntity.getHitModule(xx, yy, zz, mouseOver.sideHit, horizontalFacing);
if (hit != null) {
hitModule = modules.get(hit.getModuleIndex());
}
tileEntity.focusModuleClient(xx, yy, zz, mouseOver.sideHit, horizontalFacing);
}
}
if (tileEntity.isBright()) {
Minecraft.getMinecraft().entityRenderer.disableLightmap();
}
for (IClientScreenModule module : modules) {
if (module != null) {
int height = module.getHeight();
// Check if this module has enough room
if (currenty + height <= 124) {
if (module.getTransformMode() != mode) {
if (mode != IClientScreenModule.TransformMode.NONE) {
GlStateManager.popMatrix();
}
GlStateManager.pushMatrix();
mode = module.getTransformMode();
switch(mode) {
case TEXT:
GlStateManager.translate(-0.5F, 0.5F, 0.07F);
f3 = 0.0075F;
GlStateManager.scale(f3 * factor, -f3 * factor, f3);
GL11.glNormal3f(0.0F, 0.0F, -1.0F);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
break;
case TEXTLARGE:
GlStateManager.translate(-0.5F, 0.5F, 0.07F);
f3 = 0.0075F * 2;
GlStateManager.scale(f3 * factor, -f3 * factor, f3);
GL11.glNormal3f(0.0F, 0.0F, -1.0F);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
break;
case ITEM:
break;
default:
break;
}
}
IModuleData data = screenData.get(moduleIndex);
// @todo this is a bit clumsy way to check if the data is compatible with the given module:
try {
int hitx = -1;
int hity = -1;
if (module == hitModule) {
hitx = hit.getX();
hity = hit.getY() - hit.getCurrenty();
}
TrueTypeFont font = null;
switch(tileEntity.getTrueTypeMode()) {
case -1:
break;
case 1:
font = ClientProxy.font;
break;
case 0:
font = ScreenConfiguration.useTruetype ? ClientProxy.font : null;
break;
}
ModuleRenderInfo renderInfo = new ModuleRenderInfo(factor, pos, hitx, hity, font);
module.render(clientScreenModuleHelper, fontrenderer, currenty, data, renderInfo);
} catch (ClassCastException e) {
}
currenty += height;
}
}
moduleIndex++;
}
if (tileEntity.isBright()) {
Minecraft.getMinecraft().entityRenderer.enableLightmap();
}
if (mode != IClientScreenModule.TransformMode.NONE) {
GlStateManager.popMatrix();
}
}
use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.
the class PacketReturnScreenData method toBytes.
@Override
public void toBytes(ByteBuf buf) {
NetworkTools.writePos(buf, pos.getCoordinate());
buf.writeInt(pos.getDimension());
buf.writeInt(screenData.size());
for (Map.Entry<Integer, IModuleData> me : screenData.entrySet()) {
buf.writeInt(me.getKey());
IModuleData c = me.getValue();
buf.writeInt(RFTools.screenModuleRegistry.getShortId(c.getId()));
c.writeToBuf(buf);
}
}
use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.
the class ScreenRenderer method updateScreenData.
private Map<Integer, IModuleData> updateScreenData(ScreenTileEntity screenTileEntity) {
long millis = System.currentTimeMillis();
if ((millis - screenTileEntity.lastTime > 500) && screenTileEntity.isNeedsServerData()) {
screenTileEntity.lastTime = millis;
GlobalCoordinate pos = new GlobalCoordinate(screenTileEntity.getPos(), screenTileEntity.getWorld().provider.getDimension());
RFToolsMessages.INSTANCE.sendToServer(new PacketGetScreenData(RFTools.MODID, pos, millis));
}
GlobalCoordinate key = new GlobalCoordinate(screenTileEntity.getPos(), screenTileEntity.getWorld().provider.getDimension());
Map<Integer, IModuleData> screenData = ScreenTileEntity.screenData.get(key);
if (screenData == null) {
screenData = Collections.emptyMap();
}
return screenData;
}
use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.
the class ScreenRenderer method render.
@Override
public void render(ScreenTileEntity tileEntity, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
float xRotation = 0.0F, yRotation = 0.0F;
EnumFacing facing = EnumFacing.SOUTH, horizontalFacing = EnumFacing.SOUTH;
if (tileEntity != null) {
IBlockState state = Minecraft.getMinecraft().world.getBlockState(tileEntity.getPos());
if (state.getBlock() instanceof ScreenBlock) {
facing = state.getValue(BaseBlock.FACING);
horizontalFacing = state.getValue(ScreenBlock.HORIZONTAL_FACING);
} else {
return;
}
}
GlStateManager.pushMatrix();
switch(horizontalFacing) {
case NORTH:
yRotation = -180.0F;
break;
case WEST:
yRotation = -90.0F;
break;
case EAST:
yRotation = 90.0F;
}
switch(facing) {
case DOWN:
xRotation = 90.0F;
break;
case UP:
xRotation = -90.0F;
}
// TileEntity can be null if this is used for an item renderer.
GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
GlStateManager.rotate(yRotation, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(xRotation, 1.0F, 0.0F, 0.0F);
GlStateManager.translate(0.0F, 0.0F, -0.4375F);
if (tileEntity == null) {
GlStateManager.disableLighting();
renderScreenBoard(0, 0);
} else if (!tileEntity.isTransparent()) {
GlStateManager.disableLighting();
renderScreenBoard(tileEntity.getSize(), tileEntity.getColor());
}
if (tileEntity != null && tileEntity.isRenderable()) {
FontRenderer fontrenderer = this.getFontRenderer();
IClientScreenModule.TransformMode mode = IClientScreenModule.TransformMode.NONE;
GlStateManager.depthMask(false);
GlStateManager.disableLighting();
Map<Integer, IModuleData> screenData = updateScreenData(tileEntity);
List<IClientScreenModule> modules = tileEntity.getClientScreenModules();
if (tileEntity.isShowHelp()) {
modules = ScreenTileEntity.getHelpingScreenModules();
}
renderModules(fontrenderer, tileEntity, mode, modules, screenData, tileEntity.getSize());
}
GlStateManager.enableLighting();
GlStateManager.depthMask(true);
GlStateManager.popMatrix();
}
use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.
the class PacketReturnScreenData method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
pos = new GlobalCoordinate(NetworkTools.readPos(buf), buf.readInt());
int size = buf.readInt();
screenData = new HashMap<>(size);
for (int i = 0; i < size; i++) {
int key = buf.readInt();
int shortId = buf.readInt();
String id = RFTools.screenModuleRegistry.getNormalId(shortId);
IModuleDataFactory<?> dataFactory = RFTools.screenModuleRegistry.getModuleDataFactory(id);
IModuleData data = dataFactory.createData(buf);
screenData.put(key, data);
}
}
Aggregations