minecraft 클론을 프로그래밍하려고합니다. 현재 나는 작은 세계를 가지고 있으며 걸어 다니기도하지만 이제는 틱 (tick) 방식으로 붙어 있습니다. while 루프의 main 메서드에서이 tick 메서드를 호출합니다. tick() 메서드 호출하는 방법
동안 주요 방법 루프 :boolean closeRequested = false;
while(!closeRequested){
mc.tick();
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
closeRequested = true;
}
if(Display.isCloseRequested()){
closeRequested = true;
}
눈금 방법 :
public void tick()
{
while (Keyboard.next()) {
if (Keyboard.getEventKeyState())
{
if (Keyboard.getEventKey() == 28) {
Minecraft.level.save();
}
if (Keyboard.getEventKey() == 2) {
this.paintTexture = 1;
}
if (Keyboard.getEventKey() == 3) {
this.paintTexture = 3;
}
if (Keyboard.getEventKey() == 4) {
this.paintTexture = 4;
}
if (Keyboard.getEventKey() == 5) {
this.paintTexture = 5;
}
if (Keyboard.getEventKey() == 7) {
this.paintTexture = 6;
}
}
}
Minecraft.level.tick();
Minecraft.particleEngine.tick();
Minecraft.player.tick(); //This is the movement
}
플레이어 눈금 방법 :
public void tick()
{
this.xo = this.x;
this.yo = this.y;
this.zo = this.z;
float xa = 0.0F;
float ya = 0.0F;
if (Keyboard.isKeyDown(19)) {
resetPos();
}
if ((Keyboard.isKeyDown(200)) || (Keyboard.isKeyDown(17))) {
ya -= 1.0F;
}
if ((Keyboard.isKeyDown(208)) || (Keyboard.isKeyDown(31))) {
ya += 1.0F;
}
if ((Keyboard.isKeyDown(203)) || (Keyboard.isKeyDown(30))) {
xa -= 1.0F;
}
if ((Keyboard.isKeyDown(205)) || (Keyboard.isKeyDown(32))) {
xa += 1.0F;
}
if ((Keyboard.isKeyDown(57)) || (Keyboard.isKeyDown(219))) {
if (this.onGround) {
this.yd = 0.5F;
}
}
moveRelative(xa, ya, this.onGround ? 0.1F : 0.02F);
this.yd = ((float)(this.yd - 0.08D));
move(this.xd, this.yd, this.zd);
this.xd *= 0.91F;
this.yd *= 0.98F;
this.zd *= 0.91F;
if (this.onGround)
{
this.xd *= 0.7F;
this.zd *= 0.7F;
}
}
제가이 방법을 추천 호출
이 선수 mov es는 음향을 좋아하고 fps에 따라 플레이어가 얼마나 빨리 움직이는지를 보여줍니다.나는이 코드를 minecraft 알파 버전에서 가지고 있지만 tick()
메서드가 호출되는 지점을 찾을 수 없습니다.
플레이어를 일정한 속도로 움직이기를 원합니다.
나는 timepassed, fps 또는 ticks와 같은 몇 가지 변수를 얻을 수있는 타이머도 가지고 있습니다 (타이머는 원래의 minecraft 코드에서도 제공됩니다).
글쎄, 당신은 일시 중지없이 이것을 실행하고 있습니다. 따라서'tick '호출은 CPU/OS가 허용하는 한 빨리 수행됩니다. 편집 : 어떤 방법 으로든 스레드의 수면/일시 중지를하지 않으면 더 많은 코드를 추가 할 필요가 없습니다;) – AxelH
또한, 당신의 코드를 조금 더 잘 구조화해야한다고 생각해야합니다. while 루프 '단지'main' 메쏘드에 있습니다. – CraigR8806