知識がまだ浅いせいか、おかしな記述等や不足している点があるかもしれませんが、それをふまえた上で教えていただければ幸いです。
練習として自作のモデルを読み込んでレンダリングするMODを作ろうとしています。
簡単なものとして以下のようなものを作りました。
ProjectSample.java
- コード: 全て選択
package mod.sample.common;
import java.io.IOException;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.config.Configuration;
@Mod(
modid = "sample",
name = "sample",
version = "1.7.10_1.0a"
)
public class ProjectSample{
//proxy
@SidedProxy(clientSide="mod.sample.client.ClientProxy",
serverSide="mod.sample.common.CommonProxy")
public static CommonProxy proxy;
@Instance("sample")
public static ProjectSample instance;
public static Item sampleitem;
@EventHandler
public void preInit(FMLPreInitializationEvent event){
//itemの登録
this.sampleitem = new ItemSample().setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("sample:sample");
GameRegistry.registerItem(sampleitem,"sample:sample");
EntityRegistry.registerModEntity(EntitySample.class,"sample.entity",1, this,128,3,true);
}
@EventHandler
public void Init(FMLInitializationEvent event) throws IOException{
proxy.registerRenderers();
}
@EventHandler
public void postInit(FMLPostInitializationEvent evnet){
}
}
CommonProxy.java
- コード: 全て選択
package mod.sample.common;
public class CommonProxy {
public void registerRenderers(){
}
}
ClientProxy.java
- コード: 全て選択
package mod.sample.client;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraftforge.client.MinecraftForgeClient;
public class ClientProxy extends CommonProxy{
public void registerRenderers(){
RenderingRegistry.registerEntityRenderingHandler(EntitySample.class,new RenderSample());
}
}
ItemSample.java
- コード: 全て選択
package mod.sample.common;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItemSample extends Item{
public ItemSample(){
this.setMaxStackSize(1);
this.setMaxDamage(4);
this.setNoRepair();
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister){
this.itemIcon = iconRegister.registerIcon("sample:sample");
}
@Override
@SideOnly(Side.CLIENT)
public boolean isFull3D(){
return true;
}
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world,EntityPlayer entityPlayer){
boolean creative = entityPlayer.capabilities.isCreativeMode;
double x = entityPlayer.posX;
double y = entityPlayer.posY;
double z = entityPlayer.posZ;
System.out.println("call onItemRightClick");
EntitySample entity = new EntitySample(world,(double)(x+0.5d),(double)(y+0.5d),(double)(z+1d));
if(!world.isRemote){
System.out.println("!world.isRemote::"+world.isRemote);
world.spawnEntityInWorld(entity);
}
return itemStack;
}
}
EntitySample.java
- コード: 全て選択
package mod.sample.common;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class EntitySample extends Entity{
public EntitySample(World world,double posx,double posy,double posz){
super(world);
this.posX = posx;
this.posY = posy;
this.posZ = posz;
setPosition(this.posX,this.posY,this.posZ);
}
public EntitySample(World world,EntityPlayer entityPlayer){
super(world);
this.setSize(0.5f,0.5f);
//初期状態での向き
this.setLocationAndAngles(entityPlayer.posX,entityPlayer.posY+(double)entityPlayer.getEyeHeight(),entityPlayer.posZ,entityPlayer.rotationYaw,entityPlayer.rotationPitch);
//位置の調整
this.posX = (double)entityPlayer.posX+2f;
this.posY = (double)entityPlayer.posY;
this.posZ = (double)entityPlayer.posZ+2f;
setPosition(this.posX,this.posY,this.posZ);
}
@Override
protected void entityInit() {
}
@Override
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {
}
@Override
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {
}
public void onUpdate(){
super.onUpdate();
System.out.println("EntitySample onUpdate!");
}
}
RenderSample.java
- コード: 全て選択
package mod.sample.client;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
public class RenderSample extends Render{
private ModelSample modesample;
public RenderSample() {
super();
this.shadowSize = 0.0f;
this.modelsample = new ModelSample();
System.out.println("CALL RenderSample");
System.out.println("this.modelsample = "+this.modelsample);
}
@Override
protected ResourceLocation getEntityTexture(Entity p_110775_1_) {
return null;
}
//doRender
public void doRender(EntitySample entitysample, double x, double y, double z, float f4,float f5){
System.out.println("RenderSample doRender(2)");
GL11.glPushMatrix();
GL11.glTranslatef((float)x,(float)y,(float)z);
GL11.glScalef(0.75f,0.75f,0.75f);
this.modelsample.render(entitySample, f5, f5, f5, f5, f5, f5);
GL11.glPopMatrix();
}
@Override
public void doRender(Entity entity, double f1, double f2, double f3, float f4,float f5) {
System.out.println("RenderSample doRender");
this.doRender((EntitySample)entity, f1, f2, f3);
}
}
ModelSample.java
- コード: 全て選択
package mod.sample.client;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
@SideOnly(Side.CLIENT)
public class ModelSample extends ModelBase{
private IModelCustom modelCustom;
//自作の3dモデル
ResourceLocation res = new ResourceLocation("sample","textures/models/untitled.obj");
public ModelSamaple(){
modelCustom = AdvancedModelLoader.loadModel(res);
}
public void render(){
System.out.println("render()");
modelCustom.renderAll();
}
public void render(Entity entity,double x,double y,double z){
System.out.println("render(Entity,double,double,double)");
this.render();
}
}
http://minecraftjp.info/modding/index.p ... Model.java
http://www.minecraftforge.net/wiki/Usin ... ront_model
上記を3つを参考に書いてみました。
一部不必要なメソッドや変数等があるかもしれません。
自分の書いた上記達を実行すると、RenderSample.javaのdoRender()が呼び出さていませんでした。
どなたか上記のコードの問題点を教えて頂けないでしょうか。
ご教授の方をよろしくお願いします。