Last active
December 15, 2015 00:58
-
-
Save nanase/5176305 to your computer and use it in GitHub Desktop.
MinecraftでMOD開発2日目。異なるチャンクへ移動した時、チャンク高度データの最初8個、現在プレイヤーが立っている場所の晴天光量(晴れている日中時)、暗黒光量(天体による光源が存在しない時)をチャット欄に流す。
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; | |
import net.minecraft.client.multiplayer.WorldClient; | |
import net.minecraft.world.chunk.Chunk; | |
public class mod_Test extends BaseMod { | |
private Logger logger; | |
private Chunk old_chunk; | |
public mod_Test() { | |
super(); | |
this.logger = ModLoader.getLogger(); | |
} | |
@Override | |
public String getVersion() { | |
return "0.1-test"; | |
} | |
@Override | |
public void load() { | |
} | |
@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.process(minecraft); | |
return true; | |
} | |
private void process(Minecraft mc) { | |
EntityClientPlayerMP player = mc.thePlayer; | |
WorldClient world = mc.theWorld; | |
// 現在位置のチャンク取得 | |
Chunk chunk = world.getChunkFromChunkCoords(player.chunkCoordX, | |
player.chunkCoordZ); | |
// 下半身座標 | |
int posX = (int) player.posX - 1, | |
posY = (int) player.posY - 1, | |
posZ = (int) player.posZ; | |
if (chunk != this.old_chunk) { | |
// 高度データを取得 | |
int[] hm = chunk.heightMap; | |
String message = String.format( | |
"%d, %d : %d %d %d %d %d %d %d %d...", | |
chunk.xPosition, chunk.zPosition, | |
hm[0], hm[1], hm[2], hm[3], hm[4], hm[5], hm[6], hm[7]); | |
player.addChatMessage(message); | |
// 光量データを取得 | |
int dark = chunk.getBlockLightValue(posX & 15, posY, posZ & 15, 15); | |
int sunlight = chunk.getBlockLightValue(posX & 15, posY, posZ & 15, 0); | |
// sunlightは単に world.getBlockLightValue(posX, posY, posZ); でも可能 | |
message = String.format("Light : %d (%d)", actual, sunlight); | |
player.addChatMessage(message); | |
this.old_chunk = chunk; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment