Stopped the user from placing overlapping components

Fixed GUI String rendering size
Fixed panel components not stacking in some situations
Slider length has to be greater than 0.125 now
This commit is contained in:
malte0811 2017-04-23 17:23:10 +02:00
parent 0327322198
commit 3739fc127c
6 changed files with 42 additions and 35 deletions

View file

@ -30,9 +30,6 @@ import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
@ -104,7 +101,7 @@ public class GuiPanelCreator extends GuiContainer {
pc.setX(x / (float) panelSize);
pc.setY(y / (float) panelSize);
}
if (!pc.isValidPos()) {
if (!pc.isValidPos(container.tile.components)) {
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
int left = (int) (getX0()+aabb.minX*panelSize)-1;
int top = (int) (getY0()+aabb.minZ*panelSize)-1;
@ -126,17 +123,6 @@ public class GuiPanelCreator extends GuiContainer {
buttonList.add(new GuiButton(2, guiLeft+2, buttonTop+44, 20, 20, "S"));
}
private void drawTexturedRect(float xMin, float xMax, float yMin, float yMax, float uMin, float uMax, float vMin, float vMax) {
Tessellator tes = Tessellator.getInstance();
VertexBuffer buf = tes.getBuffer();
buf.begin(7, DefaultVertexFormats.POSITION_TEX);
buf.pos(xMin, yMax, zLevel).tex(uMin, vMax).endVertex();
buf.pos(xMax, yMax, zLevel).tex(uMax, vMax).endVertex();
buf.pos(xMax, yMin, zLevel).tex(uMax, vMin).endVertex();
buf.pos(xMin, yMin, zLevel).tex(uMin, vMin).endVertex();
tes.draw();
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
@ -150,7 +136,7 @@ public class GuiPanelCreator extends GuiContainer {
}
PanelComponent curr = getFloatingPC();
if (curr != null && 0 <= xRel && xRel <= panelSize && 0 <= yRel && yRel <= panelSize) {
if (curr.isValidPos()) {
if (curr.isValidPos(container.tile.components)) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setFloat("x", curr.getX());
nbt.setFloat("y", curr.getY());

View file

@ -24,6 +24,7 @@ import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.client.panelmodel.RawModelFontRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
@ -119,7 +120,12 @@ public class Label extends PanelComponent implements IConfigurableComponent {
public void renderInGUI(GuiPanelCreator gui) {
int left = (int) (gui.getX0()+getX()*gui.panelSize);
int top = (int) (gui.getY0()+getY()*gui.panelSize);
gui.mc.fontRendererObj.drawString(text, left, top, 0xff000000|color);
GlStateManager.pushMatrix();
float scale = gui.mc.fontRendererObj.FONT_HEIGHT*gui.panelSize/(16F*9F*9F);
GlStateManager.translate(left, top, 0);
GlStateManager.scale(scale, scale, scale);
gui.mc.fontRendererObj.drawString(text, 0, 0, 0xff000000|color);
GlStateManager.popMatrix();
}
@Override

View file

@ -26,8 +26,6 @@ import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
@ -164,7 +162,7 @@ public abstract class PanelComponent {
}
public boolean isValidPos() {
public boolean isValidPos(List<PanelComponent> components) {
AxisAlignedBB aabb = getBlockRelativeAABB().offset(0, panelHeight, 0);
if (aabb.minX<0||aabb.maxX>1) {
return false;
@ -175,6 +173,16 @@ public abstract class PanelComponent {
if (aabb.minZ<0||aabb.maxZ>1) {
return false;
}
aabb = getBlockRelativeAABB();
for (PanelComponent pc:components) {
if (pc==this) {
continue;
}
AxisAlignedBB otherBB = pc.getBlockRelativeAABB();
if (PanelUtils.intersectXZ(aabb, otherBB)) {
return false;
}
}
return true;
}
@ -199,8 +207,4 @@ public abstract class PanelComponent {
result = 31 * result + type.hashCode();
return result;
}
//TODO make abstract & implement
public ItemStack getIngredientStack() {
return new ItemStack(Items.BEETROOT_SOUP);
}
}

View file

@ -35,6 +35,7 @@ import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3i;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.obj.OBJModel;
@ -223,7 +224,7 @@ public final class PanelUtils {
public static void addCommonInfo(NBTTagCompound data, List<String> list, boolean color, boolean rs) {
if (color && data.hasKey(COLOR)) {
String hexCol = String.format("%6s", Integer.toHexString(data.getInteger(COLOR)&0xffffff)).replace(' ', '0');
String hexCol = String.format("%6s", Integer.toHexString(data.getInteger(COLOR) & 0xffffff)).replace(' ', '0');
list.add(I18n.format(Lib.DESC_INFO + "colour", "<hexcol=" + hexCol + ":#" + hexCol + ">"));
}
if (rs && data.hasKey(RS_CHANNEL)) {
@ -237,7 +238,7 @@ public final class PanelUtils {
}
public static int setColor(int color, int id, NBTBase value) {
id = 2-id;
id = 2 - id;
color &= ~(0xff << (8 * id));
color |= (int) (2.55 * (((NBTTagFloat) value).getFloat())) << (8 * id);
return color;
@ -251,4 +252,8 @@ public final class PanelUtils {
}
return ret;
}
public static boolean intersectXZ(AxisAlignedBB aabb1, AxisAlignedBB aabb2) {
return aabb1.minX < aabb2.maxX && aabb1.maxX > aabb2.minX && aabb1.minZ < aabb2.maxZ && aabb1.maxZ > aabb2.minZ;
}
}

View file

@ -227,12 +227,16 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
if (id<3) {
color = PanelUtils.setColor(color, id, value);
} else {
length = ((NBTTagFloat)value).getFloat()/100;
length = scaleToRangePercent(((NBTTagFloat)value).getFloat(), .125F, 1);
}
break;
}
}
private float scaleToRangePercent(float x, float min, float max) {
return min + x / 100F * (max - min);
}
@Override
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
@ -294,7 +298,7 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
new FloatConfig("red", x, yOffset+20, color[0], 60),
new FloatConfig("green", x, yOffset+40, color[1], 60),
new FloatConfig("blue", x, yOffset+60, color[2], 60),
new FloatConfig("length", x, yOffset, length, 60)
new FloatConfig("length", x, yOffset, (length-.125F)/(1-.125F), 60)
};
}
}

View file

@ -99,9 +99,7 @@ public class ItemPanelComponent extends Item {
NBTTagCompound outer = new NBTTagCompound();
outer.setTag("data", inner);
int meta = getMetaFromPC(inner.getString("type"));
inner.removeTag("x");
inner.removeTag("y");
inner.removeTag("type");
removeIrrelevantTags(inner);
if (meta>=0) {
ItemStack ret = new ItemStack(this, 1, meta);
ret.setTagCompound(outer);
@ -110,6 +108,13 @@ public class ItemPanelComponent extends Item {
return null;
}
private static void removeIrrelevantTags(NBTTagCompound inner) {
inner.removeTag("x");
inner.removeTag("y");
inner.removeTag("type");
inner.removeTag("panelHeight");
}
private int getMetaFromPC(String pc) {
for (int i = 0;i<types.length;i++) {
if (pc.equals(types[i])) {
@ -131,10 +136,7 @@ public class ItemPanelComponent extends Item {
if (asCmp != null) {
NBTTagCompound written = new NBTTagCompound();
asCmp.writeToNBT(written, true);
written.removeTag("x");
written.removeTag("y");
written.removeTag("type");
written.removeTag("panelHeight");
removeIrrelevantTags(written);
nbt.setTag("data", written);
}
}