Modding: Dimension Teleportation Block

In this tutorial I will show you how to create the block that will teleport you from and to your new dimension.
I will be starting with this file.


package Tutorial.common;

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;

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial {
// proxy
@SidedProxy(clientSide = “Tutorial.client.ClientProxyTutorial”, serverSide = “Tutorial.common.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

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


If you don’t know what this code is I suggest you read the tutorials about the basic file and custom textures first.
This is the code you will have to add in your mod file for the teleportation block. I have also added a recipe, but you don’t need that.


public static Block teleporter;

teleporter = new BlockTutorialPortal(233, 0).setHardness(-1F).setStepSound(Block.soundGlassFootstep).setLightValue(0.75F).setBlockName(“teleporter”);

GameRegistry.registerBlock(teleporter);

LanguageRegistry.addName(teleporter, “Portal”);

GameRegistry.addShapelessRecipe(new ItemStack(teleporter, 5), new Object[] 

new ItemStack(Block.dirt)
});


If you don’t know what this code does you should take a look at the block tutorials.
The only bit of new code is .setLightValue(0.75F). 0.75F is the amount of light the block emits. 1F is the highest possible light level.
.setHardness(-1F) means that it is not breakable. Set it to above 0.1F to make it breakable.

The whole file should now look like this.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.ItemStack;
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.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
// proxy
@SidedProxy(clientSide = “Tutorial.client.ClientProxyTutorial”, serverSide = “Tutorial.common.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

public static Block teleporter;

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

//blocks
teleporter = new BlockTutorialPortal(233, 0).setHardness(-1F).setStepSound(Block.soundGlassFootstep).setLightValue(0.75F).setBlockName(“teleporter”);

GameRegistry.registerBlock(teleporter);

LanguageRegistry.addName(teleporter, “Portal”);

GameRegistry.addShapelessRecipe(new ItemStack(teleporter, 5), new Object[] 

new ItemStack(Block.dirt)
});
}
}


Now you should create your block file. It should look like this.


package Tutorial.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.BlockPortalBase;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Material;
import net.minecraft.src.Teleporter;
import net.minecraft.src.World;
import net.minecraft.src.WorldProviderBase;

public class BlockTutorialPortal extends BlockPortalBase
{
    public BlockTutorialPortal(int i, int j)
    {
        super(i, j, Material.portal);
        this.setCreativeTab(CreativeTabs.tabBlock);
    }
    
    public String getTextureFile()
    {
            return “/TutTextures.png”;
    }
    
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
        return null;
    }
    
    public WorldProviderBase getDimension()
{
return new WorldProviderTutorial();
}
    
    public Teleporter getTeleporter()
{
return new TeleporterTutorial();
}
    
    public List canTeleportFromDimension()
{
ArrayList list = new ArrayList();
list.add(0);
list.add(-1);
return list;
}
    
public boolean displayPortalOverlay()
    {
        return true;
    }

public int getOverlayTexture()
{
return blockIndexInTexture;
}

public String getEnteringMessage() 
{
return “Entering The Dimension.”;
}

public String getLeavingMessage() 
{
return “Leaving The Dimension.”;
}

    public int quantityDropped(Random par1Random)
    {
        return 1;
    }
}


A part of this code is taken from the block tutorials. If you haven’t read that one yet you should do that.
getCollisionBoundingBoxFromPool is a very important method. In this block you have to make it return null. If it isn’t null you can’t enter the block and can’t be teleported by it.
getDimension is a method that should return the file that has your dimension in it. We will be creating this in a later tutorial.
getTeleporter is a method that should return the Teleporter file of your dimension. We will make this in a later tutorial as well.
canTeleportFromDimension is a method that should return a list of dimensions you can teleport from into your dimension. 0 is the overworld -1 is the nether.
displayPortalOverlay creates the portal animation on the screen.
getOverlayTexture gets the file that the animation should look like.
getEnteringMessage and getLeavingMessage should be pretty logical. This is simply the message displayed when you enter and leave the dimension.

In the next tutorial I will show you how to create a basic WorldProvider.

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="">