Last active
December 14, 2015 23:59
-
-
Save nanase/5170081 to your computer and use it in GitHub Desktop.
MinecraftでModLoaderを用いたMODテスト。足元(プレイヤー直下)のブロックIDおよびデータIDをチャット欄に表示させる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.minecraft.src; | |
import java.util.logging.Logger; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.entity.EntityClientPlayerMP; | |
import net.minecraft.client.multiplayer.NetClientHandler; | |
public class mod_Test extends BaseMod { | |
private Logger logger; | |
private int old_posX, old_posZ; | |
public mod_Test() { | |
super(); | |
this.logger = ModLoader.getLogger(); | |
} | |
@Override | |
public String getVersion() { | |
return "0.1-test"; | |
} | |
@Override | |
// Modが読み込まれた時に呼び出されるイベントハンドラ | |
public void load() { | |
this.logger.info("[TestMod] ロード完了"); | |
} | |
@Override | |
// ゲームが開始(接続)された時に呼び出されるイベントハンドラ | |
public void clientConnect(NetClientHandler handler) { | |
// onTickInGame イベントを有効化 | |
ModLoader.setInGameHook(this, true, true); | |
this.logger.info("[TestMod] ゲーム開始"); | |
} | |
@Override | |
// 周期的に呼び出されるイベントハンドラ | |
public boolean onTickInGame(float f, Minecraft minecraft) { | |
this.output(minecraft); | |
// true で再度読み出される | |
return true; | |
} | |
private void output(Minecraft mc) { | |
EntityClientPlayerMP player = mc.thePlayer; | |
// 下半身座標 | |
int posX = (int) player.posX - 1, | |
posY = (int) player.posY - 1, | |
posZ = (int) player.posZ; | |
if (posX != this.old_posX || posZ != this.old_posZ) { | |
// 足元座標でブロックID、データを取得 | |
int id = mc.theWorld.getBlockId(posX, posY - 1, posZ); | |
int data = mc.theWorld.getBlockMetadata(posX, posY - 1, posZ); | |
String message = String.format("%d/%d", id, data); | |
// チャットに送出 | |
mc.thePlayer.addChatMessage(message); | |
this.old_posX = posX; | |
this.old_posZ = posZ; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment