Java 在改装旧阿尔法rd-132328地雷艇时遇到问题

Java 在改装旧阿尔法rd-132328地雷艇时遇到问题,java,minecraft,Java,Minecraft,所以,我正在尝试修改Minecraft最古老的版本之一。到目前为止,我做得很好,控制台没有错误,播放测试运行良好,纹理/模型看起来很好,工作正常。但当我试着把它放进我的雷管发射器时,当我运行它时,它就不起作用了。我重命名了.jar和.json文件,引用了其他版本以确保我的文件布局正确,并对.json进行了两次运行,以确保我更改了ID 游戏输出选项卡中的日志(如果需要启动器日志,请在下面发表评论。更新!感谢@u ug!): /terrain.png -> 1 java.lang.Runtim

所以,我正在尝试修改Minecraft最古老的版本之一。到目前为止,我做得很好,控制台没有错误,播放测试运行良好,纹理/模型看起来很好,工作正常。但当我试着把它放进我的雷管发射器时,当我运行它时,它就不起作用了。我重命名了.jar和.json文件,引用了其他版本以确保我的文件布局正确,并对.json进行了两次运行,以确保我更改了ID

游戏输出选项卡中的日志(如果需要启动器日志,请在下面发表评论。更新!感谢@u ug!):

/terrain.png -> 1
java.lang.RuntimeException: !!
at com.mojang.rubydung.Textures.loadTexture(Textures.java:63)
at com.mojang.rubydung.level.Chunk.rebuild(Chunk.java:48)
at com.mojang.rubydung.level.Chunk.render(Chunk.java:78)
at com.mojang.rubydung.level.LevelRenderer.render(LevelRenderer.java:53)
at com.mojang.rubydung.RubyDung.render(RubyDung.java:295)
at com.mojang.rubydung.RubyDung.run(RubyDung.java:122)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.imageio.IIOException: Can't get input stream from URL!
at javax.imageio.ImageIO.read(Unknown Source)
at com.mojang.rubydung.Textures.loadTexture(Textures.java:41)
... 6 more
Caused by: java.io.FileNotFoundException: C:\Users\Isaac_2\AppData\Roaming\.minecraft\versions\Minecraft rd-132328 Mod (The system cannot find the file specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.<init>(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
... 8 more
package com.mojang.rubydung;

import com.mojang.rubydung.character.Creeper;
import com.mojang.rubydung.character.Cube;
import com.mojang.rubydung.character.Zombie;
import com.mojang.rubydung.character.Zombie2;
import com.mojang.rubydung.level.Chunk;
import com.mojang.rubydung.level.Level;
import com.mojang.rubydung.level.LevelRenderer;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

public class RubyDung
  implements Runnable
{
  private static final boolean FULLSCREEN_MODE = false;
  private int width;
  private int height;
  private FloatBuffer fogColor = BufferUtils.createFloatBuffer(4);
  private Timer timer = new Timer(60.0F);
  private Level level;
  private LevelRenderer levelRenderer;
  private Player player;
  private ArrayList<Zombie> zombies = new ArrayList();
  private ArrayList<Zombie2> zombies2 = new ArrayList();
  private ArrayList<Creeper> creeper = new ArrayList();

  private IntBuffer viewportBuffer = BufferUtils.createIntBuffer(16);

  private IntBuffer selectBuffer = BufferUtils.createIntBuffer(2000);
  private HitResult hitResult = null;

  public void init()
    throws LWJGLException, IOException
  {
    int col = 920330;
    float fr = 0.5F;
    float fg = 0.8F;
    float fb = 1.0F;
    this.fogColor.put(new float[] { (col >> 16 & 0xFF) / 255.0F, (col >> 8 & 0xFF) / 255.0F, (col & 0xFF) / 255.0F, 1.0F });
    this.fogColor.flip();

    Display.setDisplayMode(new DisplayMode(1024, 768));

    Display.create();
    Keyboard.create();
    Mouse.create();

    this.width = Display.getDisplayMode().getWidth();
    this.height = Display.getDisplayMode().getHeight();

    GL11.glEnable(3553);
    GL11.glShadeModel(7425);
    GL11.glClearColor(fr, fg, fb, 0.0F);
    GL11.glClearDepth(1.0D);
    GL11.glEnable(2929);
    GL11.glDepthFunc(515);

    GL11.glMatrixMode(5889);
    GL11.glLoadIdentity();

    GL11.glMatrixMode(5888);

    this.level = new Level(256, 256, 64);
    this.levelRenderer = new LevelRenderer(this.level);
    this.player = new Player(this.level);

    Mouse.setGrabbed(true);

    for (int i = 0; i < 100; i++)
    {
      this.zombies.add(new Zombie(this.level, 128.0F, 0.0F, 128.0F));
      this.zombies2.add(new Zombie2(this.level, 128.0F, 0.0F, 128.0F));
      this.creeper.add(new Creeper(this.level, 128.0F, 0.0F, 128.0F));
    }
  }

  public void destroy()
  {
    this.level.save();

    Mouse.destroy();
    Keyboard.destroy();
    Display.destroy();
  }

  public void run()
  {
    try
    {
      init();
    }
    catch (Exception e)
    {
      JOptionPane.showMessageDialog(null, e.toString(), "Failed to start RubyDung", 0);
      System.exit(0);
    }

    long lastTime = System.currentTimeMillis();
    int frames = 0;
    try
    {
      do
      {
        this.timer.advanceTime();
        for (int i = 0; i < this.timer.ticks; i++)
        {
          tick();
        }
        render(this.timer.a);
        frames++;

        while (System.currentTimeMillis() >= lastTime + 1000L)
        {
          System.out.println(frames + " fps, " + Chunk.updates);
          Chunk.updates = 0;

          lastTime += 1000L;
          frames = 0;
        }
        if (Keyboard.isKeyDown(1)) break;  } while (!Display.isCloseRequested());
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    finally
    {
      destroy();
    }
  }

  public void tick()
  {
    for (int i = 0; i < this.zombies.size(); i++)
    {
      ((Zombie)this.zombies.get(i)).tick();
      ((Zombie2)this.zombies2.get(i)).tick();
      ((Creeper)this.creeper.get(i)).tick();
    }

    this.player.tick();
  }

  private void moveCameraToPlayer(float a)
  {
    GL11.glTranslatef(0.0F, 0.0F, -0.3F);
    GL11.glRotatef(this.player.xRot, 1.0F, 0.0F, 0.0F);
    GL11.glRotatef(this.player.yRot, 0.0F, 1.0F, 0.0F);

    float x = this.player.xo + (this.player.x - this.player.xo) * a;
    float y = this.player.yo + (this.player.y - this.player.yo) * a;
    float z = this.player.zo + (this.player.z - this.player.zo) * a;
    GL11.glTranslatef(-x, -y, -z);
  }

  private void setupCamera(float a)
  {
    GL11.glMatrixMode(5889);
    GL11.glLoadIdentity();
    GLU.gluPerspective(70.0F, this.width / this.height, 0.05F, 1000.0F);
    GL11.glMatrixMode(5888);
    GL11.glLoadIdentity();
    moveCameraToPlayer(a);
  }

  private void setupPickCamera(float a, int x, int y)
  {
    GL11.glMatrixMode(5889);
    GL11.glLoadIdentity();
    this.viewportBuffer.clear();
    GL11.glGetInteger(2978, this.viewportBuffer);
    this.viewportBuffer.flip();
    this.viewportBuffer.limit(16);
    GLU.gluPickMatrix(x, y, 5.0F, 5.0F, this.viewportBuffer);
    GLU.gluPerspective(70.0F, this.width / this.height, 0.05F, 1000.0F);
    GL11.glMatrixMode(5888);
    GL11.glLoadIdentity();
    moveCameraToPlayer(a);
  }

  private void pick(float a)
  {
    this.selectBuffer.clear();
    GL11.glSelectBuffer(this.selectBuffer);
    GL11.glRenderMode(7170);
    setupPickCamera(a, this.width / 2, this.height / 2);
    this.levelRenderer.pick(this.player);
    int hits = GL11.glRenderMode(7168);
    this.selectBuffer.flip();
    this.selectBuffer.limit(this.selectBuffer.capacity());

    long closest = 0L;
    int[] names = new int[10];
    int hitNameCount = 0;
    for (int i = 0; i < hits; i++)
    {
      int nameCount = this.selectBuffer.get();
      long minZ = this.selectBuffer.get();
      this.selectBuffer.get();

      long dist = minZ;

      if ((dist < closest) || (i == 0))
      {
        closest = dist;
        hitNameCount = nameCount;
        for (int j = 0; j < nameCount; j++)
          names[j] = this.selectBuffer.get();
      }
      else
      {
        for (int j = 0; j < nameCount; j++) {
          this.selectBuffer.get();
        }
      }
    }
    if (hitNameCount > 0)
    {
      this.hitResult = new HitResult(names[0], names[1], names[2], names[3], names[4]);
    }
    else
    {
      this.hitResult = null;
    }
  }

  public void render(float a)
  {
    float xo = Mouse.getDX();
    float yo = Mouse.getDY();
    this.player.turn(xo, yo);
    pick(a);

    while (Mouse.next())
    {
      if ((Mouse.getEventButton() == 1) && (Mouse.getEventButtonState()))
      {
        if (this.hitResult != null)
        {
          this.level.setTile(this.hitResult.x, this.hitResult.y, this.hitResult.z, 0);
        }
      }
      if ((Mouse.getEventButton() == 0) && (Mouse.getEventButtonState()))
      {
        if (this.hitResult != null)
        {
          int x = this.hitResult.x;
          int y = this.hitResult.y;
          int z = this.hitResult.z;

          if (this.hitResult.f == 0) y--;
          if (this.hitResult.f == 1) y++;
          if (this.hitResult.f == 2) z--;
          if (this.hitResult.f == 3) z++;
          if (this.hitResult.f == 4) x--;
          if (this.hitResult.f == 5) x++;

          this.level.setTile(x, y, z, 1);
        }
      }
    }

    while (Keyboard.next())
    {
      if ((Keyboard.getEventKey() == 28) && (Keyboard.getEventKeyState()))
      {
        this.level.save();
      }

    }

    GL11.glClear(16640);
    setupCamera(a);

    GL11.glEnable(2884);
    GL11.glEnable(2912);
    GL11.glFogi(2917, 2048);
    GL11.glFogf(2914, 0.2F);
    GL11.glFog(2918, this.fogColor);

    GL11.glDisable(2912);
    this.levelRenderer.render(this.player, 0);
    for (int i = 0; i < this.zombies.size(); i++)
    {
      ((Zombie)this.zombies.get(i)).render(a);
      ((Zombie2)this.zombies2.get(i)).render(a);
      ((Creeper)this.creeper.get(i)).render(a);
    }
    GL11.glEnable(2912);
    this.levelRenderer.render(this.player, 1);
    GL11.glDisable(3553);

    if (this.hitResult != null)
    {
      this.levelRenderer.renderHit(this.hitResult);
    }

    new Cube(0, 0);
    GL11.glDisable(2912);

    Display.update();
  }

  public static void checkError()
  {
    int e = GL11.glGetError();
    if (e != 0)
    {
      throw new IllegalStateException(GLU.gluErrorString(e));
    }
  }

  public static void main(String[] args) throws LWJGLException
  {
    new Thread(new RubyDung()).start();
  }
}
package com.mojang.rubydung;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.HashMap;
import javax.imageio.ImageIO;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

public class Textures
{
  private static HashMap<String, Integer> idMap = new HashMap();

  private static int lastId = -9999999;

  public static int loadTexture(String resourceName, int mode)
  {
    try
    {
      if (idMap.containsKey(resourceName))
      {
        return ((Integer)idMap.get(resourceName)).intValue();
      }

      IntBuffer ib = BufferUtils.createIntBuffer(1);
      ib.clear();
      GL11.glGenTextures(ib);
      int id = ib.get(0);
      idMap.put(resourceName, Integer.valueOf(id));
      System.out.println(resourceName + " -> " + id);

      GL11.glBindTexture(3553, id);

      GL11.glTexParameteri(3553, 10241, mode);
      GL11.glTexParameteri(3553, 10240, mode);

      BufferedImage img = ImageIO.read(Textures.class.getResource(resourceName));
      int w = img.getWidth();
      int h = img.getHeight();

      ByteBuffer pixels = BufferUtils.createByteBuffer(w * h * 4);
      int[] rawPixels = new int[w * h];
      img.getRGB(0, 0, w, h, rawPixels, 0, w);
      for (int i = 0; i < rawPixels.length; i++)
      {
        int a = rawPixels[i] >> 24 & 0xFF;
        int r = rawPixels[i] >> 16 & 0xFF;
        int g = rawPixels[i] >> 8 & 0xFF;
        int b = rawPixels[i] & 0xFF;

        rawPixels[i] = (a << 24 | b << 16 | g << 8 | r);
      }
      pixels.asIntBuffer().put(rawPixels);
      GLU.gluBuild2DMipmaps(3553, 6408, w, h, 6408, 5121, pixels);

      return id;
    }
    catch (IOException localIOException) {
    }
    throw new RuntimeException("!!");
  }
}
package com.mojang.rubydung.level;

import com.mojang.rubydung.Textures;
import com.mojang.rubydung.phys.AABB;
import org.lwjgl.opengl.GL11;

public class Chunk
{
  public AABB aabb;
  public final Level level;
  public final int x0;
  public final int y0;
  public final int z0;
  public final int x1;
  public final int y1;
  public final int z1;
  private boolean dirty = true;
  private int lists = -1;

  private static Tesselator t = new Tesselator();

  public static int rebuiltThisFrame = 0;
  public static int updates = 0;

  public Chunk(Level level, int x0, int y0, int z0, int x1, int y1, int z1)
  {
    this.level = level;
    this.x0 = x0;
    this.y0 = y0;
    this.z0 = z0;
    this.x1 = x1;
    this.y1 = y1;
    this.z1 = z1;

    this.aabb = new AABB(x0, y0, z0, x1, y1, z1);
    this.lists = GL11.glGenLists(2);
  }

  private void rebuild(int layer)
  {
    if (rebuiltThisFrame == 2) return;
    this.dirty = false;

    updates += 1;

    rebuiltThisFrame += 1;

    int id = Textures.loadTexture("/terrain.png", 9728);

    GL11.glNewList(this.lists + layer, 4864);
    GL11.glEnable(3553);
    GL11.glBindTexture(3553, id);
    t.init();
    int tiles = 0;
    for (int x = this.x0; x < this.x1; x++)
      for (int y = this.y0; y < this.y1; y++)
        for (int z = this.z0; z < this.z1; z++)
        {
          if (this.level.isTile(x, y, z))
          {
            int tex = y == this.level.depth * 2 / 3 ? 0 : 1;
            tiles++;
            if (tex == 0)
              Tile.rock.render(t, this.level, layer, x, y, z);
            else
              Tile.grass.render(t, this.level, layer, x, y, z);
          }
        }
    t.flush();
    GL11.glDisable(3553);
    GL11.glEndList();
  }

  public void render(int layer)
  {
    if (this.dirty)
    {
      rebuild(0);
      rebuild(1);
    }

    GL11.glCallList(this.lists + layer);
  }

  public void setDirty()
  {
    this.dirty = true;
  }
}
/terrain.png->1
java.lang.RuntimeException:!!
位于com.mojang.rubydung.Textures.loadTexture(Textures.java:63)
位于com.mojang.rubydung.level.Chunk.rebuild(Chunk.java:48)
位于com.mojang.rubydung.level.Chunk.render(Chunk.java:78)
位于com.mojang.rubydung.level.LevelRenderer.render(LevelRenderer.java:53)
位于com.mojang.rubydung.rubydung.render(rubydung.java:295)
访问com.mojang.rubydung.rubydung.run(rubydung.java:122)
位于java.lang.Thread.run(未知源)
原因:javax.imageio.IIOException:无法从URL获取输入流!
位于javax.imageio.imageio.read(未知源)
位于com.mojang.rubydung.Textures.loadTexture(Textures.java:41)
... 还有6个
原因:java.io.FileNotFoundException:C:\Users\Isaac_2\AppData\Roaming\.minecraft\versions\minecraft rd-132328 Mod(系统找不到指定的文件)
位于java.util.zip.ZipFile.open(本机方法)
位于java.util.zip.ZipFile。(未知源)
位于java.util.zip.ZipFile。(未知源)
位于java.util.jar.JarFile。(未知源)
位于java.util.jar.JarFile。(未知源)
位于sun.net.www.protocol.jar.URLJarFile。(来源不明)
位于sun.net.www.protocol.jar.URLJarFile.getJarFile(未知源)
位于sun.net.www.protocol.jar.JarFileFactory.get(未知源)
位于sun.net.www.protocol.jar.JarURLConnection.connect(未知源)
位于sun.net.www.protocol.jar.JarURLConnection.getInputStream(未知源)
位于java.net.URL.openStream(未知源)
... 8个以上
差不多就这些了。我还将输入主代码:

RubyDung(主):

/terrain.png -> 1
java.lang.RuntimeException: !!
at com.mojang.rubydung.Textures.loadTexture(Textures.java:63)
at com.mojang.rubydung.level.Chunk.rebuild(Chunk.java:48)
at com.mojang.rubydung.level.Chunk.render(Chunk.java:78)
at com.mojang.rubydung.level.LevelRenderer.render(LevelRenderer.java:53)
at com.mojang.rubydung.RubyDung.render(RubyDung.java:295)
at com.mojang.rubydung.RubyDung.run(RubyDung.java:122)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.imageio.IIOException: Can't get input stream from URL!
at javax.imageio.ImageIO.read(Unknown Source)
at com.mojang.rubydung.Textures.loadTexture(Textures.java:41)
... 6 more
Caused by: java.io.FileNotFoundException: C:\Users\Isaac_2\AppData\Roaming\.minecraft\versions\Minecraft rd-132328 Mod (The system cannot find the file specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.<init>(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
... 8 more
package com.mojang.rubydung;

import com.mojang.rubydung.character.Creeper;
import com.mojang.rubydung.character.Cube;
import com.mojang.rubydung.character.Zombie;
import com.mojang.rubydung.character.Zombie2;
import com.mojang.rubydung.level.Chunk;
import com.mojang.rubydung.level.Level;
import com.mojang.rubydung.level.LevelRenderer;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

public class RubyDung
  implements Runnable
{
  private static final boolean FULLSCREEN_MODE = false;
  private int width;
  private int height;
  private FloatBuffer fogColor = BufferUtils.createFloatBuffer(4);
  private Timer timer = new Timer(60.0F);
  private Level level;
  private LevelRenderer levelRenderer;
  private Player player;
  private ArrayList<Zombie> zombies = new ArrayList();
  private ArrayList<Zombie2> zombies2 = new ArrayList();
  private ArrayList<Creeper> creeper = new ArrayList();

  private IntBuffer viewportBuffer = BufferUtils.createIntBuffer(16);

  private IntBuffer selectBuffer = BufferUtils.createIntBuffer(2000);
  private HitResult hitResult = null;

  public void init()
    throws LWJGLException, IOException
  {
    int col = 920330;
    float fr = 0.5F;
    float fg = 0.8F;
    float fb = 1.0F;
    this.fogColor.put(new float[] { (col >> 16 & 0xFF) / 255.0F, (col >> 8 & 0xFF) / 255.0F, (col & 0xFF) / 255.0F, 1.0F });
    this.fogColor.flip();

    Display.setDisplayMode(new DisplayMode(1024, 768));

    Display.create();
    Keyboard.create();
    Mouse.create();

    this.width = Display.getDisplayMode().getWidth();
    this.height = Display.getDisplayMode().getHeight();

    GL11.glEnable(3553);
    GL11.glShadeModel(7425);
    GL11.glClearColor(fr, fg, fb, 0.0F);
    GL11.glClearDepth(1.0D);
    GL11.glEnable(2929);
    GL11.glDepthFunc(515);

    GL11.glMatrixMode(5889);
    GL11.glLoadIdentity();

    GL11.glMatrixMode(5888);

    this.level = new Level(256, 256, 64);
    this.levelRenderer = new LevelRenderer(this.level);
    this.player = new Player(this.level);

    Mouse.setGrabbed(true);

    for (int i = 0; i < 100; i++)
    {
      this.zombies.add(new Zombie(this.level, 128.0F, 0.0F, 128.0F));
      this.zombies2.add(new Zombie2(this.level, 128.0F, 0.0F, 128.0F));
      this.creeper.add(new Creeper(this.level, 128.0F, 0.0F, 128.0F));
    }
  }

  public void destroy()
  {
    this.level.save();

    Mouse.destroy();
    Keyboard.destroy();
    Display.destroy();
  }

  public void run()
  {
    try
    {
      init();
    }
    catch (Exception e)
    {
      JOptionPane.showMessageDialog(null, e.toString(), "Failed to start RubyDung", 0);
      System.exit(0);
    }

    long lastTime = System.currentTimeMillis();
    int frames = 0;
    try
    {
      do
      {
        this.timer.advanceTime();
        for (int i = 0; i < this.timer.ticks; i++)
        {
          tick();
        }
        render(this.timer.a);
        frames++;

        while (System.currentTimeMillis() >= lastTime + 1000L)
        {
          System.out.println(frames + " fps, " + Chunk.updates);
          Chunk.updates = 0;

          lastTime += 1000L;
          frames = 0;
        }
        if (Keyboard.isKeyDown(1)) break;  } while (!Display.isCloseRequested());
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    finally
    {
      destroy();
    }
  }

  public void tick()
  {
    for (int i = 0; i < this.zombies.size(); i++)
    {
      ((Zombie)this.zombies.get(i)).tick();
      ((Zombie2)this.zombies2.get(i)).tick();
      ((Creeper)this.creeper.get(i)).tick();
    }

    this.player.tick();
  }

  private void moveCameraToPlayer(float a)
  {
    GL11.glTranslatef(0.0F, 0.0F, -0.3F);
    GL11.glRotatef(this.player.xRot, 1.0F, 0.0F, 0.0F);
    GL11.glRotatef(this.player.yRot, 0.0F, 1.0F, 0.0F);

    float x = this.player.xo + (this.player.x - this.player.xo) * a;
    float y = this.player.yo + (this.player.y - this.player.yo) * a;
    float z = this.player.zo + (this.player.z - this.player.zo) * a;
    GL11.glTranslatef(-x, -y, -z);
  }

  private void setupCamera(float a)
  {
    GL11.glMatrixMode(5889);
    GL11.glLoadIdentity();
    GLU.gluPerspective(70.0F, this.width / this.height, 0.05F, 1000.0F);
    GL11.glMatrixMode(5888);
    GL11.glLoadIdentity();
    moveCameraToPlayer(a);
  }

  private void setupPickCamera(float a, int x, int y)
  {
    GL11.glMatrixMode(5889);
    GL11.glLoadIdentity();
    this.viewportBuffer.clear();
    GL11.glGetInteger(2978, this.viewportBuffer);
    this.viewportBuffer.flip();
    this.viewportBuffer.limit(16);
    GLU.gluPickMatrix(x, y, 5.0F, 5.0F, this.viewportBuffer);
    GLU.gluPerspective(70.0F, this.width / this.height, 0.05F, 1000.0F);
    GL11.glMatrixMode(5888);
    GL11.glLoadIdentity();
    moveCameraToPlayer(a);
  }

  private void pick(float a)
  {
    this.selectBuffer.clear();
    GL11.glSelectBuffer(this.selectBuffer);
    GL11.glRenderMode(7170);
    setupPickCamera(a, this.width / 2, this.height / 2);
    this.levelRenderer.pick(this.player);
    int hits = GL11.glRenderMode(7168);
    this.selectBuffer.flip();
    this.selectBuffer.limit(this.selectBuffer.capacity());

    long closest = 0L;
    int[] names = new int[10];
    int hitNameCount = 0;
    for (int i = 0; i < hits; i++)
    {
      int nameCount = this.selectBuffer.get();
      long minZ = this.selectBuffer.get();
      this.selectBuffer.get();

      long dist = minZ;

      if ((dist < closest) || (i == 0))
      {
        closest = dist;
        hitNameCount = nameCount;
        for (int j = 0; j < nameCount; j++)
          names[j] = this.selectBuffer.get();
      }
      else
      {
        for (int j = 0; j < nameCount; j++) {
          this.selectBuffer.get();
        }
      }
    }
    if (hitNameCount > 0)
    {
      this.hitResult = new HitResult(names[0], names[1], names[2], names[3], names[4]);
    }
    else
    {
      this.hitResult = null;
    }
  }

  public void render(float a)
  {
    float xo = Mouse.getDX();
    float yo = Mouse.getDY();
    this.player.turn(xo, yo);
    pick(a);

    while (Mouse.next())
    {
      if ((Mouse.getEventButton() == 1) && (Mouse.getEventButtonState()))
      {
        if (this.hitResult != null)
        {
          this.level.setTile(this.hitResult.x, this.hitResult.y, this.hitResult.z, 0);
        }
      }
      if ((Mouse.getEventButton() == 0) && (Mouse.getEventButtonState()))
      {
        if (this.hitResult != null)
        {
          int x = this.hitResult.x;
          int y = this.hitResult.y;
          int z = this.hitResult.z;

          if (this.hitResult.f == 0) y--;
          if (this.hitResult.f == 1) y++;
          if (this.hitResult.f == 2) z--;
          if (this.hitResult.f == 3) z++;
          if (this.hitResult.f == 4) x--;
          if (this.hitResult.f == 5) x++;

          this.level.setTile(x, y, z, 1);
        }
      }
    }

    while (Keyboard.next())
    {
      if ((Keyboard.getEventKey() == 28) && (Keyboard.getEventKeyState()))
      {
        this.level.save();
      }

    }

    GL11.glClear(16640);
    setupCamera(a);

    GL11.glEnable(2884);
    GL11.glEnable(2912);
    GL11.glFogi(2917, 2048);
    GL11.glFogf(2914, 0.2F);
    GL11.glFog(2918, this.fogColor);

    GL11.glDisable(2912);
    this.levelRenderer.render(this.player, 0);
    for (int i = 0; i < this.zombies.size(); i++)
    {
      ((Zombie)this.zombies.get(i)).render(a);
      ((Zombie2)this.zombies2.get(i)).render(a);
      ((Creeper)this.creeper.get(i)).render(a);
    }
    GL11.glEnable(2912);
    this.levelRenderer.render(this.player, 1);
    GL11.glDisable(3553);

    if (this.hitResult != null)
    {
      this.levelRenderer.renderHit(this.hitResult);
    }

    new Cube(0, 0);
    GL11.glDisable(2912);

    Display.update();
  }

  public static void checkError()
  {
    int e = GL11.glGetError();
    if (e != 0)
    {
      throw new IllegalStateException(GLU.gluErrorString(e));
    }
  }

  public static void main(String[] args) throws LWJGLException
  {
    new Thread(new RubyDung()).start();
  }
}
package com.mojang.rubydung;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.HashMap;
import javax.imageio.ImageIO;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

public class Textures
{
  private static HashMap<String, Integer> idMap = new HashMap();

  private static int lastId = -9999999;

  public static int loadTexture(String resourceName, int mode)
  {
    try
    {
      if (idMap.containsKey(resourceName))
      {
        return ((Integer)idMap.get(resourceName)).intValue();
      }

      IntBuffer ib = BufferUtils.createIntBuffer(1);
      ib.clear();
      GL11.glGenTextures(ib);
      int id = ib.get(0);
      idMap.put(resourceName, Integer.valueOf(id));
      System.out.println(resourceName + " -> " + id);

      GL11.glBindTexture(3553, id);

      GL11.glTexParameteri(3553, 10241, mode);
      GL11.glTexParameteri(3553, 10240, mode);

      BufferedImage img = ImageIO.read(Textures.class.getResource(resourceName));
      int w = img.getWidth();
      int h = img.getHeight();

      ByteBuffer pixels = BufferUtils.createByteBuffer(w * h * 4);
      int[] rawPixels = new int[w * h];
      img.getRGB(0, 0, w, h, rawPixels, 0, w);
      for (int i = 0; i < rawPixels.length; i++)
      {
        int a = rawPixels[i] >> 24 & 0xFF;
        int r = rawPixels[i] >> 16 & 0xFF;
        int g = rawPixels[i] >> 8 & 0xFF;
        int b = rawPixels[i] & 0xFF;

        rawPixels[i] = (a << 24 | b << 16 | g << 8 | r);
      }
      pixels.asIntBuffer().put(rawPixels);
      GLU.gluBuild2DMipmaps(3553, 6408, w, h, 6408, 5121, pixels);

      return id;
    }
    catch (IOException localIOException) {
    }
    throw new RuntimeException("!!");
  }
}
package com.mojang.rubydung.level;

import com.mojang.rubydung.Textures;
import com.mojang.rubydung.phys.AABB;
import org.lwjgl.opengl.GL11;

public class Chunk
{
  public AABB aabb;
  public final Level level;
  public final int x0;
  public final int y0;
  public final int z0;
  public final int x1;
  public final int y1;
  public final int z1;
  private boolean dirty = true;
  private int lists = -1;

  private static Tesselator t = new Tesselator();

  public static int rebuiltThisFrame = 0;
  public static int updates = 0;

  public Chunk(Level level, int x0, int y0, int z0, int x1, int y1, int z1)
  {
    this.level = level;
    this.x0 = x0;
    this.y0 = y0;
    this.z0 = z0;
    this.x1 = x1;
    this.y1 = y1;
    this.z1 = z1;

    this.aabb = new AABB(x0, y0, z0, x1, y1, z1);
    this.lists = GL11.glGenLists(2);
  }

  private void rebuild(int layer)
  {
    if (rebuiltThisFrame == 2) return;
    this.dirty = false;

    updates += 1;

    rebuiltThisFrame += 1;

    int id = Textures.loadTexture("/terrain.png", 9728);

    GL11.glNewList(this.lists + layer, 4864);
    GL11.glEnable(3553);
    GL11.glBindTexture(3553, id);
    t.init();
    int tiles = 0;
    for (int x = this.x0; x < this.x1; x++)
      for (int y = this.y0; y < this.y1; y++)
        for (int z = this.z0; z < this.z1; z++)
        {
          if (this.level.isTile(x, y, z))
          {
            int tex = y == this.level.depth * 2 / 3 ? 0 : 1;
            tiles++;
            if (tex == 0)
              Tile.rock.render(t, this.level, layer, x, y, z);
            else
              Tile.grass.render(t, this.level, layer, x, y, z);
          }
        }
    t.flush();
    GL11.glDisable(3553);
    GL11.glEndList();
  }

  public void render(int layer)
  {
    if (this.dirty)
    {
      rebuild(0);
      rebuild(1);
    }

    GL11.glCallList(this.lists + layer);
  }

  public void setDirty()
  {
    this.dirty = true;
  }
}
package com.mojang.rubydung;
进口com.mojang.rubydung.character.croper;
导入com.mojang.rubydung.character.Cube;
导入com.mojang.rubydung.character.Zombie;
导入com.mojang.rubydung.character.Zombie2;
导入com.mojang.rubydung.level.Chunk;
导入com.mojang.rubydung.level.level;
导入com.mojang.rubydung.level.LevelRenderer;
导入java.io.IOException;
导入java.io.PrintStream;
导入java.nio.FloatBuffer;
导入java.nio.IntBuffer;
导入java.util.ArrayList;
导入javax.swing.JOptionPane;
导入org.lwjgl.BufferUtils;
导入org.lwjgl.LWJGLException;
导入org.lwjgl.input.Keyboard;
导入org.lwjgl.input.Mouse;
导入org.lwjgl.opengl.Display;
导入org.lwjgl.opengl.DisplayMode;
导入org.lwjgl.opengl.GL11;
导入org.lwjgl.util.glu.glu;
公共类鲁比东
实现可运行
{
私有静态最终布尔全屏模式=false;
私有整数宽度;
私人内部高度;
private FloatBuffer fogColor=BufferUtils.createFloatBuffer(4);
专用定时器=新定时器(60.0F);
私人层面;
私有级渲染器;
私人玩家;
私有ArrayList zombies=新ArrayList();
私有ArrayList zombies2=新ArrayList();
私有ArrayList爬行器=新ArrayList();
私有IntBuffer viewportBuffer=BufferUtils.createIntBuffer(16);
私有IntBuffer selectBuffer=BufferUtils.createIntBuffer(2000);
私有HitResult HitResult=null;
公共void init()
抛出LWJGLException、IOException
{
int col=920330;
浮球fr=0.5F;
浮动fg=0.8F;
浮球fb=1.0F;
this.fogColor.put(新浮点[]{(col>>16&0xFF)/255.0F,(col>>8&0xFF)/255.0F,(col&0xFF)/255.0F,1.0F});
this.fogColor.flip();
设置显示模式(新的显示模式(1024768));
Display.create();
create();
Mouse.create();
this.width=Display.getDisplayMode().getWidth();
this.height=Display.getDisplayMode().getHeight();
GL11.glEnable(3553);
GL11.glShadeModel(7425);
GL11.glClearColor(fr、fg、fb、0.0F);
GL11.GLC清除深度(1.0D);
glEnable(2929);
GL11.glDepthFunc(515);
GL11.glMatrixMode(5889);
GL11.glLoadIdentity();
GL11.glMatrixMode(5888);
this.level=新级别(256、256、64);
this.levelRenderer=新的levelRenderer(this.level);
this.player=新玩家(此.level);
鼠标。setgrapped(true);
对于(int i=0;i<100;i++)
{
this.zombies.add(新僵尸(this.level,128.0F,0.0F,128.0F));
this.zombies2.add(新的Zombie2(this.level,128.0F,0.0F,128.0F));
此.爬行器.添加(新爬行器(此.级别,128.0F,0.0F,128.0F));
}
}
公共空间销毁()
{
this.level.save();
老鼠。破坏();
键盘。销毁();
Display.destroy();
}
公开募捐
{
尝试
{
init();
}
捕获(例外e)
{
showMessageDialog(null,例如toString(),“无法启动RubyDung”,0);
系统出口(0);
}
long lastTime=System.currentTimeMillis();
int帧=0;
尝试
{
做
{
this.timer.advanceTime();
for(int i=0;i=lastTime+1000L)
{
System.out.println(frames+fps,+Chunk.updates);
Chunk.updates=0;
最后时间+=1000L;
帧=0;
}
if(Keyboard.isKeyDown(1))break;}while(!Display.isCloseRequested());
}
捕获(例外e)
{
e、 printStackTrace();
}
最后
{
破坏();
}
}
公共空白勾号()
{
for(int i=0;i