mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 06:53:24 +00:00
Added text labels to Travel Anchors and improved rendering and selection.
This commit is contained in:
1 parent
756c893d02
commit
a98584dfdd
14 files changed
+394
-124
No files matched your search
@@ -129,6 +129,7 @@ public final class Config {
|
||||
public static String[] travelStaffBlinkBlackList = new String[] {
|
||||
"minecraft:bedrock"
|
||||
};
|
||||
public static float travelAnchorZoomScale = 0.2f;
|
||||
|
||||
public static int enderIoRange = 8;
|
||||
public static boolean enderIoMeAccessEnabled = true;
|
||||
@@ -588,6 +589,9 @@ public final class Config {
|
||||
.getBoolean(travelStaffBlinkThroughClearBlocksEnabled);
|
||||
travelStaffBlinkBlackList = config.getStringList("travelStaffBlinkBlackList", sectionStaff.name, travelStaffBlinkBlackList,
|
||||
"Lists the blocks that cannot be teleported through in the form 'modID:blockName'");
|
||||
travelAnchorZoomScale = config.getFloat("travelAnchorZoomScale", sectionStaff.name, travelAnchorZoomScale, 0, 1,
|
||||
"Set the max zoomed size of a travel anchor as an aprox. percentage of screen height");
|
||||
|
||||
|
||||
enderIoRange = config.get(sectionEfficiency.name, "enderIoRange", enderIoRange,
|
||||
"Range accessable (in blocks) when using the Ender IO.").getInt(enderIoRange);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.vecmath.Vector3f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
@@ -23,60 +25,11 @@ public class FarmingStationSpecialRenderer extends TileEntitySpecialRenderer{
|
||||
return;
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
glTranslated(x + 0.5, y + 1.5, z + 0.5); // center of block and 1 block up
|
||||
glRotatef(180, 1, 0, 0); // text is upside-down by default (idk)
|
||||
float scale = 0.025f;
|
||||
glScalef(scale, scale, scale); // text is huge!
|
||||
glDisable(GL_LIGHTING);
|
||||
rotateToPlayer();
|
||||
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-fnt.getStringWidth(toRender) / 2, 0, 0);
|
||||
|
||||
renderBackground(tessellator, fnt, toRender);
|
||||
|
||||
fnt.drawString(toRender, 0, 0, 0xFFFFFF);
|
||||
glTranslatef(0.5f, 0.5f, 0.1f);
|
||||
fnt.drawString(toRender, 0, 0, 0x555555); // manual shadow
|
||||
|
||||
RenderUtil.drawBillboardedText(new Vector3f(x + 0.5, y + 1.5, z + 0.5), toRender, 0.25f);
|
||||
glEnable(GL_LIGHTING);
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
private void rotateToPlayer()
|
||||
{
|
||||
glRotatef(RenderManager.instance.playerViewY + 180, 0.0F, 1.0F, 0.0F);
|
||||
glRotatef(-RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
private void renderBackground(Tessellator tessellator, FontRenderer fnt, String toRender) {
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDepthMask(false);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
OpenGlHelper.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); // stop random disappearing
|
||||
|
||||
float width = (float) fnt.getStringWidth(toRender);
|
||||
float height = (float) fnt.FONT_HEIGHT;
|
||||
float padding = 2f;
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA(70, 20, 100, 200);
|
||||
tessellator.addVertex(-padding, -padding, 0);
|
||||
tessellator.addVertex(-padding, height + padding, 0);
|
||||
tessellator.addVertex(width + padding, height + padding, 0);
|
||||
tessellator.addVertex(width + padding, -padding, 0);
|
||||
tessellator.draw();
|
||||
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTickTime) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.teleport.packet.PacketAccessMode;
|
||||
import crazypants.enderio.teleport.packet.PacketConfigSync;
|
||||
import crazypants.enderio.teleport.packet.PacketDrainStaff;
|
||||
import crazypants.enderio.teleport.packet.PacketLabel;
|
||||
import crazypants.enderio.teleport.packet.PacketOpenAuthGui;
|
||||
import crazypants.enderio.teleport.packet.PacketTravelEvent;
|
||||
import crazypants.util.Lang;
|
||||
@@ -44,6 +45,7 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
|
||||
public static BlockTravelAnchor create() {
|
||||
|
||||
PacketHandler.INSTANCE.registerMessage(PacketAccessMode.class, PacketAccessMode.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketLabel.class, PacketLabel.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketTravelEvent.class, PacketTravelEvent.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketDrainStaff.class, PacketDrainStaff.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketOpenAuthGui.class, PacketOpenAuthGui.class, PacketHandler.nextID(), Side.SERVER);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class ContainerTravelAccessable extends Container {
|
||||
}
|
||||
|
||||
arrInv = new PasswordInventory(new ItemStack[] {ta.getItemLabel()}, false);
|
||||
x = 80;
|
||||
x = 125;
|
||||
y = 10;
|
||||
addSlotToContainer(new TemplateSlot(arrInv, 0, x, y));
|
||||
|
||||
|
||||
@@ -5,15 +5,18 @@ import java.awt.Color;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.gui.CheckBoxEIO;
|
||||
import crazypants.enderio.gui.IGuiOverlay;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.teleport.TileTravelAnchor.AccessMode;
|
||||
import crazypants.enderio.teleport.packet.PacketAccessMode;
|
||||
import crazypants.enderio.teleport.packet.PacketLabel;
|
||||
import crazypants.gui.GuiContainerBase;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
@@ -30,6 +33,8 @@ public class GuiTravelAccessable extends GuiContainerBase {
|
||||
private CheckBoxEIO privateCB;
|
||||
private CheckBoxEIO protectedCB;
|
||||
|
||||
private GuiTextField tf;
|
||||
|
||||
private String publicStr;
|
||||
private String privateStr;
|
||||
private String protectedStr;
|
||||
@@ -52,6 +57,8 @@ public class GuiTravelAccessable extends GuiContainerBase {
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
tf = new GuiTextField(fr, 7, 12, 90, 16);
|
||||
|
||||
col1x = 88;
|
||||
col0x = (col1x - fr.getStringWidth(protectedStr) / 2) / 2;
|
||||
col2x = (col1x + fr.getStringWidth(protectedStr) / 2);
|
||||
@@ -98,6 +105,43 @@ public class GuiTravelAccessable extends GuiContainerBase {
|
||||
publicCB.onGuiInit();
|
||||
privateCB.onGuiInit();
|
||||
protectedCB.onGuiInit();
|
||||
|
||||
tf.xPosition = getGuiLeft() + 30;
|
||||
tf.yPosition = getGuiTop() + 10;
|
||||
tf.setCanLoseFocus(false);
|
||||
tf.setMaxStringLength(32);
|
||||
tf.setFocused(true);
|
||||
String txt = te.getLabel();
|
||||
if(txt != null && txt.length() > 0) {
|
||||
tf.setText(txt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char par1, int par2) {
|
||||
if(par2 == 1) {
|
||||
for (IGuiOverlay overlay : overlays) {
|
||||
if(overlay.isVisible()) {
|
||||
overlay.setVisible(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.mc.thePlayer.closeScreen();
|
||||
}
|
||||
tf.textboxKeyTyped(par1, par2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
tf.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int par3) {
|
||||
super.mouseClicked(x, y, par3);
|
||||
tf.mouseClicked(x, y, par3);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,6 +167,40 @@ public class GuiTravelAccessable extends GuiContainerBase {
|
||||
x = sx + col2x - fontRenderer.getStringWidth(publicStr) / 2;
|
||||
fontRenderer.drawStringWithShadow(publicStr, x, y, col);
|
||||
|
||||
tf.drawTextBox();
|
||||
checkLabelForChange();
|
||||
|
||||
}
|
||||
|
||||
private void checkLabelForChange() {
|
||||
String newTxt = tf.getText();
|
||||
if(newTxt != null && newTxt.length() == 0) {
|
||||
newTxt = null;
|
||||
}
|
||||
|
||||
String curText = te.getLabel();
|
||||
if(curText != null && curText.length() == 0) {
|
||||
curText = null;
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
if(newTxt == null) {
|
||||
if(curText == null) {
|
||||
changed = false;
|
||||
} else {
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
changed = !newTxt.equals(curText);
|
||||
}
|
||||
if(!changed) {
|
||||
return;
|
||||
}
|
||||
te.setLabel(newTxt);
|
||||
BlockCoord bc = te.getLocation();
|
||||
PacketLabel p = new PacketLabel(bc.x, bc.y, bc.z, te.getLabel());
|
||||
PacketHandler.INSTANCE.sendToServer(p);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,6 +30,10 @@ public interface ITravelAccessable {
|
||||
ItemStack getItemLabel();
|
||||
|
||||
void setItemLabel(ItemStack lableIcon);
|
||||
|
||||
String getLabel();
|
||||
|
||||
void setLabel(String label);
|
||||
|
||||
String getPlacedBy();
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
|
||||
private ItemStack[] password = new ItemStack[5];
|
||||
|
||||
private ItemStack itemLabel;
|
||||
|
||||
private String label;
|
||||
|
||||
private String placedBy;
|
||||
|
||||
@@ -142,6 +144,16 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
|
||||
this.itemLabel = lableIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlacedBy() {
|
||||
return placedBy;
|
||||
@@ -233,6 +245,10 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
|
||||
sourceBlock = Block.getBlockFromName(sourceBlockStr);
|
||||
sourceBlockMetadata = root.getInteger(KEY_SOURCE_BLOCK_META);
|
||||
|
||||
label = root.getString("label");
|
||||
if(label == null || label.trim().length() == 0) {
|
||||
label = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -269,6 +285,11 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
|
||||
root.setString(KEY_SOURCE_BLOCK_ID, Block.blockRegistry.getNameForObject(sourceBlock));
|
||||
}
|
||||
root.setInteger(KEY_SOURCE_BLOCK_META, sourceBlockMetadata);
|
||||
|
||||
if(label != null && label.trim().length() > 0) {
|
||||
root.setString("label", label);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -248,14 +248,14 @@ public class TravelController {
|
||||
lookAt.add(eye);
|
||||
Matrix4d mv = VecmathUtil.createMatrixAsLookAt(eye, lookAt, new Vector3d(0, 1, 0));
|
||||
|
||||
float fov = 70 + Minecraft.getMinecraft().gameSettings.fovSetting * 40.0F;
|
||||
float fov = Minecraft.getMinecraft().gameSettings.fovSetting;
|
||||
Matrix4d pr = VecmathUtil.createProjectionMatrixAsPerspective(fov, 0.05f, mc.gameSettings.renderDistanceChunks * 16, mc.displayWidth,
|
||||
mc.displayHeight);
|
||||
mc.displayHeight);
|
||||
currentView.setProjectionMatrix(pr);
|
||||
currentView.setViewMatrix(mv);
|
||||
currentView.setViewport(0, 0, mc.displayWidth, mc.displayHeight);
|
||||
|
||||
fovRad = Math.toRadians(fov) / 2;
|
||||
fovRad = Math.toRadians(fov);
|
||||
tanFovRad = Math.tanh(fovRad);
|
||||
}
|
||||
|
||||
@@ -507,24 +507,11 @@ public class TravelController {
|
||||
return;
|
||||
}
|
||||
|
||||
double closestDistance = Double.MAX_VALUE;
|
||||
Vector3d point = new Vector3d();
|
||||
double closestDistance = Double.MAX_VALUE;
|
||||
for (BlockCoord bc : candidates.keySet()) {
|
||||
if(!bc.equals(onBlockCoord)) {
|
||||
point.set(bc.x + 0.5, bc.y + 0.5, bc.z + 0.5);
|
||||
|
||||
Vector2d sp = currentView.getScreenPoint(new Vector3d(point.x, point.y, point.z));
|
||||
Vector2d mid = new Vector2d(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
|
||||
mid.scale(0.5);
|
||||
|
||||
double d = sp.distance(mid);
|
||||
if(d != d) {
|
||||
d = 0f;
|
||||
}
|
||||
float ratio = (float) d / Minecraft.getMinecraft().displayWidth;
|
||||
|
||||
|
||||
candidates.put(bc, ratio);
|
||||
double d = addRatio(bc);
|
||||
if(d < closestDistance) {
|
||||
selectedCoord = bc;
|
||||
closestDistance = d;
|
||||
@@ -539,22 +526,16 @@ public class TravelController {
|
||||
|
||||
Vector2d screenMidPixel = new Vector2d(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
|
||||
screenMidPixel.scale(0.5);
|
||||
double ratio = blockCenterPixel.distance(screenMidPixel) / Minecraft.getMinecraft().displayWidth;
|
||||
|
||||
|
||||
Vector3d blockLeft = new Vector3d();
|
||||
Vector3d up = new Vector3d(0,1,0);
|
||||
up.add(currentView.getEyePoint());
|
||||
blockLeft.cross(currentView.getEyePoint(), up);
|
||||
blockLeft.normalize();
|
||||
blockLeft.scale(0.5);
|
||||
blockLeft.add(blockCenter);
|
||||
|
||||
Vector2d blockLeftPixel = currentView.getScreenPoint(blockLeft);
|
||||
double blockSizeRatio = blockCenterPixel.distance(blockLeftPixel)/ Minecraft.getMinecraft().displayWidth;
|
||||
double maxRatio = Math.max(0.2, blockSizeRatio);
|
||||
if(ratio > maxRatio) {
|
||||
double pixDist = blockCenterPixel.distance(screenMidPixel);
|
||||
double rat = pixDist / Minecraft.getMinecraft().displayHeight;
|
||||
if(rat != rat) {
|
||||
rat = 0;
|
||||
}
|
||||
if(rat > 0.07) {
|
||||
selectedCoord = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -569,12 +550,8 @@ public class TravelController {
|
||||
}
|
||||
if(ratio < 0) {
|
||||
//no cached value
|
||||
Vector2d sp = currentView.getScreenPoint(new Vector3d(bc.x, bc.y, bc.z));
|
||||
Vector2d mid = new Vector2d(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
|
||||
mid.scale(0.5);
|
||||
double d = sp.distance(mid);
|
||||
ratio = (float) d / Minecraft.getMinecraft().displayWidth;
|
||||
candidates.put(bc, ratio);
|
||||
addRatio(bc);
|
||||
ratio = candidates.get(bc);
|
||||
}
|
||||
|
||||
//smoothly zoom to a larger size, starting when the point is the middle 20% of the screen
|
||||
@@ -583,21 +560,37 @@ public class TravelController {
|
||||
double mix = MathHelper.clamp_float((start - ratio) / (start - end), 0, 1);
|
||||
double scale = 1;
|
||||
if(mix > 0) {
|
||||
double d = tanFovRad * currentView.getEyePoint().distance(loc);
|
||||
scale = d / tanFovRad;
|
||||
|
||||
scale = scale * 0.1;// why I need this is completely beyond me.
|
||||
|
||||
Vector3d eyePoint = Util.getEyePositionEio(EnderIO.proxy.getClientPlayer());
|
||||
scale = tanFovRad * eyePoint.distance(loc);
|
||||
|
||||
//Using this scale will give us the block full screen, we will make it 20% of the screen
|
||||
scale *= Config.travelAnchorZoomScale;
|
||||
|
||||
//only apply 70% of the scaling so more distance targets are still smaller than closer targets
|
||||
float nf = 1 - MathHelper.clamp_float((float) currentView.getEyePoint().distanceSquared(loc) / TravelSource.STAFF.maxDistanceTravelledSq, 0, 1);
|
||||
float nf = 1 - MathHelper.clamp_float((float) eyePoint.distanceSquared(loc) / TravelSource.STAFF.maxDistanceTravelledSq, 0, 1);
|
||||
scale = scale * (0.3 + 0.7 * nf);
|
||||
|
||||
scale = (scale * mix) + (1 - mix);
|
||||
scale = Math.max(1, scale);
|
||||
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
private double addRatio(BlockCoord bc) {
|
||||
Vector2d sp = currentView.getScreenPoint(new Vector3d(bc.x + 0.5, bc.y + 0.5, bc.z + 0.5));
|
||||
Vector2d mid = new Vector2d(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
|
||||
mid.scale(0.5);
|
||||
double d = sp.distance(mid);
|
||||
if(d != d) {
|
||||
d = 0f;
|
||||
}
|
||||
float ratio = (float) d / Minecraft.getMinecraft().displayWidth;
|
||||
candidates.put(bc, ratio);
|
||||
return d;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private int getMaxTravelDistanceSqForPlayer(EntityClientPlayerMP player) {
|
||||
if(isTravelItemActive(player)) {
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package crazypants.enderio.teleport;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
@@ -17,8 +22,8 @@ import crazypants.render.CubeRenderer;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.Matrix4d;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
import crazypants.vecmath.Vector3f;
|
||||
import crazypants.vecmath.Vector4f;
|
||||
|
||||
public class TravelEntitySpecialRenderer extends TileEntitySpecialRenderer {
|
||||
@@ -61,7 +66,7 @@ public class TravelEntitySpecialRenderer extends TileEntitySpecialRenderer {
|
||||
TravelController.instance.addCandidate(bc);
|
||||
|
||||
Minecraft.getMinecraft().entityRenderer.disableLightmap(0);
|
||||
|
||||
|
||||
RenderUtil.bindBlockTexture();
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
|
||||
@@ -76,16 +81,17 @@ public class TravelEntitySpecialRenderer extends TileEntitySpecialRenderer {
|
||||
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x, y, z);
|
||||
|
||||
|
||||
|
||||
Tessellator.instance.startDrawingQuads();
|
||||
renderBlock(sf);
|
||||
Tessellator.instance.draw();
|
||||
|
||||
Tessellator.instance.startDrawingQuads();
|
||||
Tessellator.instance.setBrightness(15 << 20 | 15 << 4);
|
||||
if(TravelController.instance.isBlockSelected(bc)) {
|
||||
Tessellator.instance.setColorRGBA_F(selectedColor.x, selectedColor.y, selectedColor.z, selectedColor.w);
|
||||
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(sf + 0.05, sf + 0.05, sf + 0.05), getSelectedIcon());
|
||||
@@ -101,36 +107,82 @@ public class TravelEntitySpecialRenderer extends TileEntitySpecialRenderer {
|
||||
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopAttrib();
|
||||
|
||||
|
||||
Minecraft.getMinecraft().entityRenderer.enableLightmap(0);
|
||||
|
||||
}
|
||||
|
||||
private void renderLabel(TileEntity tileentity, double x, double y, double z, ITravelAccessable ta, double sf) {
|
||||
float globalScale = (float) sf;
|
||||
ItemStack itemLabel = ta.getItemLabel();
|
||||
if(itemLabel != null) {
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_CONSTANT_COLOR);
|
||||
GL14.glBlendColor(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
|
||||
IIcon tex = itemLabel.getIconIndex();
|
||||
if(tex == null) {
|
||||
return;
|
||||
if(itemLabel != null && itemLabel.getItem() != null) {
|
||||
|
||||
boolean isBlock = false;
|
||||
Block block = Block.getBlockFromItem(itemLabel.getItem());
|
||||
if(block != null && block != Blocks.air) {
|
||||
isBlock = true;
|
||||
}
|
||||
if(itemLabel.getItemSpriteNumber() == 0) {
|
||||
RenderUtil.bindBlockTexture();
|
||||
} else {
|
||||
RenderUtil.bindItemTexture();
|
||||
}
|
||||
|
||||
Matrix4d lookMat = RenderUtil.createBillboardMatrix(tileentity, Minecraft.getMinecraft().thePlayer);
|
||||
RenderUtil.renderBillboard(lookMat, tex.getMinU(), tex.getMaxU(), tex.getMaxV(), tex.getMinV(), sf * 0.75, 0);
|
||||
float alpha = 0.5f;
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_CONSTANT_COLOR);
|
||||
float col = 0.5f;
|
||||
GL14.glBlendColor(col, col, col, col);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
RenderUtil.bindBlockTexture();
|
||||
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
||||
if(!isBlock) {
|
||||
GL11.glRotatef(-player.rotationYaw, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glRotatef(player.rotationPitch, 1.0F, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(globalScale, globalScale, globalScale);
|
||||
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
if(isBlock) {
|
||||
GL11.glTranslatef(0f, -0.25f, 0);
|
||||
} else {
|
||||
GL11.glTranslatef(0f, -0.5f, 0);
|
||||
}
|
||||
GL11.glScalef(2, 2, 2);
|
||||
EntityItem ei = new EntityItem(tileentity.getWorldObj(), x, y, z, itemLabel);
|
||||
ei.age = 0;
|
||||
ei.hoverStart = 0;
|
||||
RenderManager.instance.getEntityRenderObject(ei).doRender(ei, 0, 0, 0, 0, 0);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
String toRender = ta.getLabel();
|
||||
if(toRender != null && toRender.trim().length() > 0) {
|
||||
Vector4f bgCol = RenderUtil.DEFAULT_TEXT_BG_COL;
|
||||
if(TravelController.instance.isBlockSelected(new BlockCoord(tileentity))) {
|
||||
bgCol = new Vector4f(selectedColor.x, selectedColor.y, selectedColor.z, selectedColor.w);
|
||||
}
|
||||
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScalef(globalScale, globalScale, globalScale);
|
||||
Vector3f pos = new Vector3f(0, 1.2f, 0);
|
||||
float size = 0.5f;
|
||||
RenderUtil.drawBillboardedText(pos, toRender, size, bgCol);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.teleport.ITravelAccessable;
|
||||
import crazypants.enderio.teleport.TileTravelAnchor;
|
||||
|
||||
/**
|
||||
@@ -47,8 +48,8 @@ public class PacketAccessMode implements IMessage, IMessageHandler<PacketAccessM
|
||||
public IMessage onMessage(PacketAccessMode message, MessageContext ctx) {
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
if(te instanceof TileTravelAnchor) {
|
||||
((TileTravelAnchor) te).setAccessMode(message.mode);
|
||||
if(te instanceof ITravelAccessable) {
|
||||
((ITravelAccessable) te).setAccessMode(message.mode);
|
||||
player.worldObj.markBlockForUpdate(message.x, message.y, message.z);
|
||||
player.worldObj.markTileEntityChunkModified(message.x, message.y, message.z, te);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package crazypants.enderio.teleport.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.teleport.ITravelAccessable;
|
||||
import crazypants.enderio.teleport.TileTravelAnchor;
|
||||
|
||||
public class PacketLabel implements IMessage, IMessageHandler<PacketLabel, IMessage> {
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
boolean labelNull;
|
||||
String label;
|
||||
|
||||
|
||||
public PacketLabel() {
|
||||
}
|
||||
|
||||
public PacketLabel(int x, int y, int z, String label) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.label = label;
|
||||
labelNull = label == null || label.length() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeBoolean(labelNull);
|
||||
if(!labelNull) {
|
||||
ByteBufUtils.writeUTF8String(buf, label);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
labelNull = buf.readBoolean();
|
||||
if(labelNull) {
|
||||
label = null;
|
||||
} else {
|
||||
label = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
}
|
||||
|
||||
public IMessage onMessage(PacketLabel message, MessageContext ctx) {
|
||||
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
||||
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
if(te instanceof ITravelAccessable) {
|
||||
((ITravelAccessable) te).setLabel(message.label);
|
||||
player.worldObj.markBlockForUpdate(message.x, message.y, message.z);
|
||||
player.worldObj.markTileEntityChunkModified(message.x, message.y, message.z, te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,10 @@ public final class ColorUtil {
|
||||
return getRGB((int) (r * 255), (int) (g * 255), (int) (b * 255));
|
||||
}
|
||||
|
||||
public static int getRGBA(Vector4f col) {
|
||||
return getRGBA(col.x, col.y,col.z,col.w);
|
||||
}
|
||||
|
||||
public static int getRGBA(float r, float g, float b, float a) {
|
||||
return getRGBA((int) (r * 255), (int) (g * 255), (int) (b * 255), (int) (a * 255));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
package crazypants.render;
|
||||
|
||||
import static net.minecraftforge.common.util.ForgeDirection.*;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.DOWN;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.EAST;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.NORTH;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.UP;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.WEST;
|
||||
import static org.lwjgl.opengl.GL11.GL_ALL_ATTRIB_BITS;
|
||||
import static org.lwjgl.opengl.GL11.GL_ALPHA_TEST;
|
||||
import static org.lwjgl.opengl.GL11.GL_BLEND;
|
||||
import static org.lwjgl.opengl.GL11.GL_CULL_FACE;
|
||||
import static org.lwjgl.opengl.GL11.GL_ONE;
|
||||
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.GL_SMOOTH;
|
||||
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
||||
import static org.lwjgl.opengl.GL11.GL_ZERO;
|
||||
import static org.lwjgl.opengl.GL11.glDepthMask;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glPopAttrib;
|
||||
import static org.lwjgl.opengl.GL11.glPushAttrib;
|
||||
import static org.lwjgl.opengl.GL11.glRotatef;
|
||||
import static org.lwjgl.opengl.GL11.glShadeModel;
|
||||
import static org.lwjgl.opengl.GL11.glTranslatef;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -11,7 +34,10 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -39,6 +65,12 @@ import crazypants.vecmath.Vertex;
|
||||
|
||||
public class RenderUtil {
|
||||
|
||||
public static final Vector4f DEFAULT_TEXT_SHADOW_COL = new Vector4f(0.33f,0.33f,0.33f,0.33f);
|
||||
|
||||
public static final Vector4f DEFAULT_TXT_COL = new Vector4f(1,1,1,1);
|
||||
|
||||
public static final Vector4f DEFAULT_TEXT_BG_COL = new Vector4f(0.275f,0.08f,0.4f, 0.75f);
|
||||
|
||||
public static final Vector3d UP_V = new Vector3d(0, 1, 0);
|
||||
|
||||
public static final Vector3d ZERO_V = new Vector3d(0, 0, 0);
|
||||
@@ -530,6 +562,65 @@ public class RenderUtil {
|
||||
tessellator.addVertexWithUV(x, y, z, icon.getMinU(), icon.getMinV());
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void drawBillboardedText(Vector3f pos, String text, float size) {
|
||||
drawBillboardedText(pos, text, size, DEFAULT_TXT_COL, true, DEFAULT_TEXT_SHADOW_COL, true, DEFAULT_TEXT_BG_COL);
|
||||
}
|
||||
|
||||
public static void drawBillboardedText(Vector3f pos, String text, float size, Vector4f bgCol) {
|
||||
drawBillboardedText(pos, text, size, DEFAULT_TXT_COL, true, DEFAULT_TEXT_SHADOW_COL, true, bgCol);
|
||||
}
|
||||
|
||||
public static void drawBillboardedText(Vector3f pos, String text, float size, Vector4f txtCol, boolean drawShadow, Vector4f shadowCol, boolean drawBackground, Vector4f bgCol) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(pos.x, pos.y,pos.z);
|
||||
glRotatef(180, 1, 0, 0);
|
||||
|
||||
FontRenderer fnt = Minecraft.getMinecraft().fontRenderer;
|
||||
float scale = size / fnt.FONT_HEIGHT;
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
glRotatef(RenderManager.instance.playerViewY + 180, 0.0F, 1.0F, 0.0F);
|
||||
glRotatef(-RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);
|
||||
|
||||
glTranslatef(-fnt.getStringWidth(text) / 2, 0, 0);
|
||||
if(drawBackground) {
|
||||
renderBackground(fnt, text, bgCol);
|
||||
}
|
||||
fnt.drawString(text, 0, 0, ColorUtil.getRGBA(txtCol));
|
||||
if(drawShadow) {
|
||||
glTranslatef(0.5f, 0.5f, 0.1f);
|
||||
fnt.drawString(text, 0, 0, ColorUtil.getRGBA(shadowCol));
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
|
||||
RenderUtil.bindBlockTexture();
|
||||
}
|
||||
|
||||
public static void renderBackground(FontRenderer fnt, String toRender, Vector4f color) {
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDepthMask(false);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
OpenGlHelper.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); // stop random disappearing
|
||||
|
||||
float width = (float) fnt.getStringWidth(toRender);
|
||||
float height = (float) fnt.FONT_HEIGHT;
|
||||
float padding = 2f;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_F(color.x, color.y, color.z, color.w);
|
||||
tessellator.addVertex(-padding, -padding, 0);
|
||||
tessellator.addVertex(-padding, height + padding, 0);
|
||||
tessellator.addVertex(width + padding, height + padding, 0);
|
||||
tessellator.addVertex(width + padding, -padding, 0);
|
||||
tessellator.draw();
|
||||
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
private static class EdgeNeighbour {
|
||||
final ForgeDirection dir;
|
||||
|
||||
Reference in new issue
Block a user