Modding 1.4.7: Custom Dimension Part 1: Portal Block Basics

In this tutorial I will show you how to make a basic Portal block.
A part of this code is done in your mod file. This is the file I will be starting with.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityEggInfo;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
public static Block tutorialBlock;

@SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

static int startEntityId = 300;

@Init
public void load(FMLInitializationEvent event)
{
proxy.registerRenderThings();

tutorialBlock = new BlockTutorialBlock(250, 0).setBlockName(“tutorialBlock”);

GameRegistry.registerBlock(tutorialBlock, “Wuppy29_TutorialBlock”);

LanguageRegistry.addName(tutorialBlock, “Tutorial Block”);

EntityRegistry.registerModEntity(EntityTutorial.class, “Tutorial”, 1, this, 80, 3, true);

EntityRegistry.addSpawn(EntityTutorial.class, 10, 2, 4, EnumCreatureType.monster, BiomeGenBase.desert, BiomeGenBase.desertHills, BiomeGenBase.forest);

LanguageRegistry.instance().addStringLocalization(“entity.Tutorial_Tutorialmod.Tutorial.name”, “Tutorial”);

registerEntityEgg(EntityTutorial.class, 0x7A65CF, 0x4DF200);
}

public static int getUniqueEntityId()
{
do
{
startEntityId++;
}
while(EntityList.getStringFromID(startEntityId) != null);

return startEntityId;
}

public static void registerEntityEgg(Class <? extends Entity> entity, int primaryColor, int secondaryColor)
{
int id = getUniqueEntityId();
EntityList.IDtoClassMapping.put(id, entity);
EntityList.entityEggs.put(id, new EntityEggInfo(id, primaryColor, secondaryColor));
}
}


You don’t really need the Entity or Block code in the file right now, but later I’m going to show you how to get custom blocks and Entities in your dimension.
The first thing you need to do is make a new block. In the mod file it’s exactly the same as with a basic block. If you don’t now how to create a basic Block read through this tutorial first and after that also this one.
So this is the code you will need inside of your mod file for a portal block.


public static Block portal;
portal = new BlockPortalTutorial(251, 1).setBlockName(“portal”);
GameRegistry.registerBlock(portal, “Wuppy29_Portal”);
LanguageRegistry.addName(portal, “Custom Portal”);


The whole file should now look something like this.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityEggInfo;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
public static Block tutorialBlock;
public static Block portal;

@SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

static int startEntityId = 300;

@Init
public void load(FMLInitializationEvent event)
{
proxy.registerRenderThings();

tutorialBlock = new BlockTutorialBlock(250, 0).setBlockName(“tutorialBlock”);
portal = new BlockPortalTutorial(251, 1).setBlockName(“portal”);

GameRegistry.registerBlock(tutorialBlock, “Wuppy29_TutorialBlock”);
GameRegistry.registerBlock(portal, “Wuppy29_Portal”);

LanguageRegistry.addName(tutorialBlock, “Tutorial Block”);
LanguageRegistry.addName(portal, “Custom Portal”);

EntityRegistry.registerModEntity(EntityTutorial.class, “Tutorial”, 1, this, 80, 3, true);

EntityRegistry.addSpawn(EntityTutorial.class, 10, 2, 4, EnumCreatureType.monster, BiomeGenBase.desert, BiomeGenBase.desertHills, BiomeGenBase.forest);

LanguageRegistry.instance().addStringLocalization(“entity.Tutorial_Tutorialmod.Tutorial.name”, “Tutorial”);

registerEntityEgg(EntityTutorial.class, 0x7A65CF, 0x4DF200);
}

public static int getUniqueEntityId()
{
do
{
startEntityId++;
}
while(EntityList.getStringFromID(startEntityId) != null);

return startEntityId;
}

public static void registerEntityEgg(Class <? extends Entity> entity, int primaryColor, int secondaryColor)
{
int id = getUniqueEntityId();
EntityList.IDtoClassMapping.put(id, entity);
EntityList.entityEggs.put(id, new EntityEggInfo(id, primaryColor, secondaryColor));
}
}


Now hover your mouse over the BlockPortalTutorial and click create Class. You should make it extend Block and add a constructor. After that the file should look like this.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;

public class BlockPortalTutorial extends Block
{
public BlockPortalTutorial(int id, int texture)
{
super(id, texture, Material.portal);
this.setCreativeTab(CreativeTabs.tabBlock);
}
}


This is mostly the same as with the basic Block tutorial. The only difference is that the Material is now portal.
Another method you have to add to this file is for the texture. It should look like this.


public String getTextureFile()
    {
            return “/tutorialblocks.png”;
    }


If you don’t know how this method works or where it comes from you have to read through this tutorial.
The whole file should now look like this.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;

public class BlockPortalTutorial extends Block
{
public BlockPortalTutorial(int id, int texture)
{
super(id, texture, Material.portal);
this.setCreativeTab(CreativeTabs.tabBlock);
}

public String getTextureFile()
    {
            return “/tutorialblocks.png”;
    }
}


In the next tutorial there will be some changes and improvements to this file.
The source code will be available at the end of the last dimension tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">