Not all of this will make sense; working on implementing custom models from Wavefront OBJ model files.
This commit is contained in:
parent
2d7987cd9b
commit
811bbfe9f7
11 changed files with 109 additions and 13 deletions
|
@ -40,6 +40,7 @@ public class BlockAludel extends BlockEE {
|
|||
this.setUnlocalizedName(Strings.ALUDEL_NAME);
|
||||
this.setCreativeTab(EquivalentExchange3.tabsEE3);
|
||||
this.setHardness(5F);
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.66F, 1.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -67,5 +67,6 @@ public abstract class BlockEE extends BlockContainer {
|
|||
}
|
||||
|
||||
((TileEE) world.getBlockTileEntity(x, y, z)).setOwner(entityLiving.getEntityName());
|
||||
((TileEE) world.getBlockTileEntity(x, y, z)).setOrientation(direction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,15 @@ package com.pahimar.ee3.client.model;
|
|||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.obj.Face;
|
||||
import com.obj.Group;
|
||||
import com.obj.WavefrontObject;
|
||||
import com.pahimar.ee3.lib.Models;
|
||||
import com.pahimar.ee3.lib.Sprites;
|
||||
import com.pahimar.ee3.tileentity.TileAludel;
|
||||
|
||||
|
@ -28,11 +34,18 @@ public class ModelAludel extends ModelBase {
|
|||
private static final int TEXTURE_WIDTH = 128;
|
||||
|
||||
private float scale;
|
||||
|
||||
private WavefrontObject objModel;
|
||||
|
||||
private ModelRenderer baseStand, northStand, southStand, eastStand, westStand;
|
||||
private ModelRenderer bottomBulb, topBulb;
|
||||
private ModelRenderer chute;
|
||||
|
||||
public ModelAludel() {
|
||||
|
||||
this.objModel = new WavefrontObject(this.getClass().getResource("/" + Models.ALUDEL).getFile());
|
||||
}
|
||||
|
||||
public ModelAludel(float scale) {
|
||||
|
||||
this.scale = scale;
|
||||
|
@ -81,15 +94,59 @@ public class ModelAludel extends ModelBase {
|
|||
topBulb.render(scale);
|
||||
|
||||
}
|
||||
|
||||
public void render(Tessellator tessellator, float scale) {
|
||||
|
||||
if (objModel.getGroups().size() != 0) {
|
||||
for (Group group : objModel.getGroups()) {
|
||||
if (group.getFaces().size() != 0) {
|
||||
for (Face face : group.getFaces()) {
|
||||
tessellator.startDrawing(GL11.GL_TRIANGLE_STRIP);
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
tessellator.addVertexWithUV(face.getVertices()[i].getX(), face.getVertices()[i].getY(), face.getVertices()[i].getZ(), face.getTextures()[i].getU(), face.getTextures()[i].getV());
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void render(TileAludel aludel, double x, double y, double z) {
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glTranslated(x, y, z);
|
||||
correctRotation(x, y, z, aludel.getOrientation());
|
||||
FMLClientHandler.instance().getClient().renderEngine.func_98187_b(Sprites.MODEL_ALUDEL);
|
||||
this.render(scale);
|
||||
//this.render(scale);
|
||||
this.render(Tessellator.instance, scale);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private void correctRotation(double x, double y, double z, ForgeDirection orientation) {
|
||||
|
||||
if (orientation == ForgeDirection.NORTH) {
|
||||
GL11.glTranslated(x + 1, y, z);
|
||||
GL11.glRotatef(180F, 0F, 1F, 0F);
|
||||
GL11.glRotatef(-90F, 1F, 0F, 0F);
|
||||
}
|
||||
else if (orientation == ForgeDirection.EAST) {
|
||||
GL11.glTranslated(x + 1, y, z + 1);
|
||||
GL11.glRotatef(90F, 0F, 1F, 0F);
|
||||
GL11.glRotatef(-90F, 1F, 0F, 0F);
|
||||
}
|
||||
else if (orientation == ForgeDirection.SOUTH) {
|
||||
GL11.glTranslated(x, y, z + 1);
|
||||
GL11.glRotatef(0F, 0F, 1F, 0F);
|
||||
GL11.glRotatef(-90F, 1F, 0F, 0F);
|
||||
}
|
||||
else if (orientation == ForgeDirection.WEST) {
|
||||
GL11.glTranslated(x, y, z);
|
||||
GL11.glRotatef(-90F, 0F, 1F, 0F);
|
||||
GL11.glRotatef(-90F, 1F, 0F, 0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.pahimar.ee3.client.renderer;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
|
||||
|
@ -28,7 +29,8 @@ public class ItemAludelRenderer implements IItemRenderer {
|
|||
|
||||
public ItemAludelRenderer() {
|
||||
|
||||
aludelModel = new ModelAludel(1 / 16F);
|
||||
//aludelModel = new ModelAludel(1 / 16F);
|
||||
aludelModel = new ModelAludel();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,15 +50,16 @@ public class ItemAludelRenderer implements IItemRenderer {
|
|||
|
||||
switch (type) {
|
||||
case ENTITY: {
|
||||
//renderAludel(-0.5F, 0F, -0.5F);
|
||||
renderAludel(-0.5F, 0F, -0.5F);
|
||||
break;
|
||||
}
|
||||
case EQUIPPED: {
|
||||
renderAludel(0F, 0.4F, 0F);
|
||||
renderAludel(0F, 0.0F, 1F);
|
||||
break;
|
||||
}
|
||||
case INVENTORY: {
|
||||
renderAludel(1F, 0.65F, 1F);
|
||||
renderAludel(-1.0F, -1.0F, 0.0F);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -69,7 +72,9 @@ public class ItemAludelRenderer implements IItemRenderer {
|
|||
FMLClientHandler.instance().getClient().renderEngine.func_98187_b(Sprites.MODEL_ALUDEL);
|
||||
GL11.glPushMatrix(); //start
|
||||
GL11.glTranslatef(x, y, z); //size
|
||||
aludelModel.render(0.0625F);
|
||||
GL11.glRotatef(-90F, 1F, 0, 0);
|
||||
//aludelModel.render(0.0625F);
|
||||
aludelModel.render(Tessellator.instance, 0.0625F);
|
||||
GL11.glPopMatrix(); //end
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,14 @@ public class TileEntityAludelRenderer extends TileEntitySpecialRenderer {
|
|||
|
||||
static final float scale = (float) (1.0 / 16.0);
|
||||
|
||||
private ModelAludel modelAludel = new ModelAludel(scale);
|
||||
//private ModelAludel modelAludel = new ModelAludel(scale);
|
||||
private ModelAludel modelAludelObj = new ModelAludel();
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) {
|
||||
|
||||
modelAludel.render((TileAludel) tileEntity, x, y, z);
|
||||
//modelAludel.render((TileAludel) tileEntity, x, y, z);
|
||||
modelAludelObj.render((TileAludel) tileEntity, x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -156,12 +156,13 @@ public class ClientProxy extends CommonProxy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleTileEntityPacket(int x, int y, int z, short state, String owner, String customName) {
|
||||
public void handleTileEntityPacket(int x, int y, int z, ForgeDirection orientation, short state, String owner, String customName) {
|
||||
|
||||
TileEntity tileEntity = FMLClientHandler.instance().getClient().theWorld.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null) {
|
||||
if (tileEntity instanceof TileEE) {
|
||||
((TileEE) tileEntity).setOrientation(orientation);
|
||||
((TileEE) tileEntity).setState(state);
|
||||
((TileEE) tileEntity).setOwner(owner);
|
||||
((TileEE) tileEntity).setCustomName(customName);
|
||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import com.pahimar.ee3.client.gui.inventory.GuiAlchemicalBag;
|
||||
import com.pahimar.ee3.client.gui.inventory.GuiAlchemicalChest;
|
||||
|
@ -85,7 +86,7 @@ public class CommonProxy implements IGuiHandler {
|
|||
|
||||
}
|
||||
|
||||
public void handleTileEntityPacket(int x, int y, int z, short state, String player, String customName) {
|
||||
public void handleTileEntityPacket(int x, int y, int z, ForgeDirection orientation, short state, String player, String customName) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.DataOutputStream;
|
|||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import com.pahimar.ee3.network.PacketTypeHandler;
|
||||
|
@ -23,6 +24,7 @@ import cpw.mods.fml.common.network.Player;
|
|||
public class PacketTileUpdate extends PacketEE {
|
||||
|
||||
public int x, y, z;
|
||||
public byte orientation;
|
||||
public short state;
|
||||
public String owner;
|
||||
public String customName;
|
||||
|
@ -32,12 +34,13 @@ public class PacketTileUpdate extends PacketEE {
|
|||
super(PacketTypeHandler.TILE, true);
|
||||
}
|
||||
|
||||
public PacketTileUpdate(int x, int y, int z, short state, String owner, String customName) {
|
||||
public PacketTileUpdate(int x, int y, int z, ForgeDirection orientation, short state, String owner, String customName) {
|
||||
|
||||
super(PacketTypeHandler.TILE, true);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.orientation = (byte) orientation.ordinal();
|
||||
this.state = state;
|
||||
this.owner = owner;
|
||||
this.customName = customName;
|
||||
|
@ -49,6 +52,7 @@ public class PacketTileUpdate extends PacketEE {
|
|||
data.writeInt(x);
|
||||
data.writeInt(y);
|
||||
data.writeInt(z);
|
||||
data.writeByte(orientation);
|
||||
data.writeShort(state);
|
||||
data.writeUTF(owner);
|
||||
data.writeUTF(customName);
|
||||
|
@ -60,6 +64,7 @@ public class PacketTileUpdate extends PacketEE {
|
|||
x = data.readInt();
|
||||
y = data.readInt();
|
||||
z = data.readInt();
|
||||
orientation = data.readByte();
|
||||
state = data.readShort();
|
||||
owner = data.readUTF();
|
||||
customName = data.readUTF();
|
||||
|
@ -68,7 +73,7 @@ public class PacketTileUpdate extends PacketEE {
|
|||
@Override
|
||||
public void execute(INetworkManager manager, Player player) {
|
||||
|
||||
EquivalentExchange3.proxy.handleTileEntityPacket(x, y, z, state, owner, customName);
|
||||
EquivalentExchange3.proxy.handleTileEntityPacket(x, y, z, ForgeDirection.getOrientation(orientation), state, owner, customName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import com.pahimar.ee3.lib.Strings;
|
||||
import com.pahimar.ee3.network.PacketTypeHandler;
|
||||
|
@ -20,16 +21,33 @@ import com.pahimar.ee3.network.packet.PacketTileUpdate;
|
|||
*/
|
||||
public class TileEE extends TileEntity {
|
||||
|
||||
private ForgeDirection orientation;
|
||||
private short state;
|
||||
private String owner;
|
||||
private String customName;
|
||||
|
||||
public TileEE() {
|
||||
|
||||
orientation = ForgeDirection.SOUTH;
|
||||
state = 0;
|
||||
owner = "";
|
||||
customName = "";
|
||||
}
|
||||
|
||||
public ForgeDirection getOrientation() {
|
||||
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(ForgeDirection orientation) {
|
||||
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(int orientation) {
|
||||
|
||||
this.orientation = ForgeDirection.getOrientation(orientation);
|
||||
}
|
||||
|
||||
public short getState() {
|
||||
|
||||
|
@ -81,6 +99,10 @@ public class TileEE extends TileEntity {
|
|||
|
||||
super.readFromNBT(nbtTagCompound);
|
||||
|
||||
if (nbtTagCompound.hasKey(Strings.NBT_TE_DIRECTION_KEY)) {
|
||||
orientation = ForgeDirection.getOrientation(nbtTagCompound.getByte(Strings.NBT_TE_DIRECTION_KEY));
|
||||
}
|
||||
|
||||
if (nbtTagCompound.hasKey(Strings.NBT_TE_STATE_KEY)) {
|
||||
state = nbtTagCompound.getShort(Strings.NBT_TE_STATE_KEY);
|
||||
}
|
||||
|
@ -99,6 +121,7 @@ public class TileEE extends TileEntity {
|
|||
|
||||
super.writeToNBT(nbtTagCompound);
|
||||
|
||||
nbtTagCompound.setByte(Strings.NBT_TE_DIRECTION_KEY, (byte)orientation.ordinal());
|
||||
nbtTagCompound.setShort(Strings.NBT_TE_STATE_KEY, state);
|
||||
|
||||
if (hasOwner()) {
|
||||
|
@ -113,7 +136,7 @@ public class TileEE extends TileEntity {
|
|||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
|
||||
return PacketTypeHandler.populatePacket(new PacketTileUpdate(xCoord, yCoord, zCoord, state, owner, customName));
|
||||
return PacketTypeHandler.populatePacket(new PacketTileUpdate(xCoord, yCoord, zCoord, orientation, state, owner, customName));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.9 KiB |
Loading…
Reference in a new issue