Jump to content

Custom Door Help?


Killjoy0593

Recommended Posts

Hi

 

Why not just use the existing door?

 

i.e. what do you want to do differently?

 

Door is a bit complicated because it needs its own renderer and it's made up of two blocks not one.  It's also got a pile of logic  related to opening & closing, whether entities can pass through it or not, changes to the bounding box, etc.

 

If you want to tweak something simple, like the sound it makes when it opens, then it's easy.  Otherwise it's going to take a fair bit of skill and knowledge about the vanilla door and renderers in particular.

 

-TGG

 

 

Link to comment
Share on other sites

Hi

 

Why not just use the existing door?

 

i.e. what do you want to do differently?

 

Door is a bit complicated because it needs its own renderer and it's made up of two blocks not one.  It's also got a pile of logic  related to opening & closing, whether entities can pass through it or not, changes to the bounding box, etc.

 

If you want to tweak something simple, like the sound it makes when it opens, then it's easy.  Otherwise it's going to take a fair bit of skill and knowledge about the vanilla door and renderers in particular.

 

-TGG

I want to create a new door. with the material of rock, my own texture, name, and id. Doesn't it use the texture-map?

Link to comment
Share on other sites

Hi

 

In that case, I think you're in luck.  I'd suggest

 

create your

class BlockMyNewDoor extends BlockDoor

add a constructor

add icon member variables (copy the ones from BlockDoor)

override

    public void registerIcons(IconRegister par1IconRegister)

to register your new icons/textures into BlockMyNewDoor member variables (the BlockDoor ones are private unfortunately)

 

and override

    public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)

copy the code from BlockDoor.getBlockTexture into BlockMyNewDoor.getBlockTexture and change the references to the icon fields to your own icon texture member variables.

 

The material is in the constructor so it's relatively easy - and if you want your stone door to act like a wooden door (i.e. players can open it) then you probably don't need to change onBlockActivated either.

 

-TGG

 

 

Link to comment
Share on other sites

Thanks Man, Figured It Out :) Here's The Code For Those Who Are Struggling With This :)

 

Main Class

//Making The Door And Item
public final static Block AdobeDoor = new AdobeDoor(900, Material.rock)
		.setHardness(2.0F).setResistance(10.0F)
		.setStepSound(Block.soundStoneFootstep)
		.setUnlocalizedName("adobe_door");
public final static Item AdobeDoorItem = new AdobeDoorItem(901, AdobeDoor)
		.setUnlocalizedName("adobe_door_icon");
//Registering The Door And Items
LanguageRegistry.addName(AdobeDoorItem, "Adobe Door");
GameRegistry.registerBlock(AdobeDoor, "AdobeDoor");
LanguageRegistry.addName(AdobeDoor, "Adobe Door");

 

Item Class

package SavageCraft.Adobe;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class AdobeDoorItem extends Item {
public Block doorBlock;

public AdobeDoorItem(int par1, Block block) {
	super(par1);
	this.doorBlock = block;
	this.maxStackSize = 1;
	this.setCreativeTab(CreativeTabs.tabRedstone);
}

public boolean onItemUse(ItemStack par1ItemStack,
		EntityPlayer par2EntityPlayer, World par3World, int par4, int par5,
		int par6, int par7, float par8, float par9, float par10) {
	if (par7 != 1) {
		return false;
	} else {
		++par5;
		Block block = this.doorBlock;

		if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7,
				par1ItemStack)
				&& par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6,
						par7, par1ItemStack)) {
			if (!block.canPlaceBlockAt(par3World, par4, par5, par6)) {
				return false;
			} else {
				int i1 = MathHelper
						.floor_double((double) ((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
				ItemDoor.placeDoorBlock(par3World, par4, par5, par6, i1,
						block);
				--par1ItemStack.stackSize;
				return true;
			}
		} else {
			return false;
		}
	}
}

@Override
public void registerIcons(IconRegister iconRegister) {
	itemIcon = iconRegister.registerIcon(AdobeInfo.NAME.toLowerCase()
			+ ":adobe_door_icon");
}
}

 

Door block Class

package SavageCraft.Adobe;

import java.util.Random;

import net.minecraft.block.BlockDoor;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.IconFlipped;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class AdobeDoor extends BlockDoor {
public Item placerItem;
public Icon topDoorIcon;
public Icon[] flippedIcons = new Icon[2];

public AdobeDoor(int par1, Material par2Material) {
	super(par1, par2Material);
	float f = 0.5F;
	float f1 = 1.0F;
	this.setLightOpacity(0);
	this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
}

public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2,
		int par3, int par4, int par5) {
	if (par5 == 1 || par5 == 0) {
		return this.blockIcon;
	}
	int meta = getFullMetadata(par1IBlockAccess, par2, par3, par4);
	boolean flag = (meta & 4) != 0;
	int halfMeta = meta & 3;
	boolean flipped = false;

	if (flag) {
		if (halfMeta == 0 && par5 == 2)
			flipped = !flipped;
		else if (halfMeta == 1 && par5 == 5)
			flipped = !flipped;
		else if (halfMeta == 2 && par5 == 3)
			flipped = !flipped;
		else if (halfMeta == 3 && par5 == 4)
			flipped = !flipped;
	} else {
		if (halfMeta == 0 && par5 == 5)
			flipped = !flipped;
		else if (halfMeta == 1 && par5 == 3)
			flipped = !flipped;
		else if (halfMeta == 2 && par5 == 4)
			flipped = !flipped;
		else if (halfMeta == 3 && par5 == 2)
			flipped = !flipped;
		if ((meta & 16) != 0)
			flipped = !flipped;
	}

	if (flipped)
		return flippedIcons[(meta &  != 0 ? 1 : 0];
	else
		return (meta &  != 0 ? this.topDoorIcon : this.blockIcon;
}

public Icon getIcon(int par1, int par2) {
	return this.blockIcon;
}

@Override
public void registerIcons(IconRegister iconRegister) {
	this.blockIcon = iconRegister.registerIcon(AdobeInfo.NAME.toLowerCase()
			+ ":adobe_door_lower");
	this.topDoorIcon = iconRegister.registerIcon(AdobeInfo.NAME
			.toLowerCase() + ":adobe_door_upper");
	this.flippedIcons[0] = new IconFlipped(blockIcon, true, false);
	this.flippedIcons[1] = new IconFlipped(topDoorIcon, true, false);
}

public int idPicked(World par1World, int par2, int par3, int par4) {
	return AdobeBlock.AdobeDoorItem.itemID;
}

public int idDropped(int par1, Random par2Random, int par3) {
	return (par1 &  != 0 ? 0 : (AdobeBlock.AdobeDoorItem.itemID);
}
        
        //Remove This Below If You Want It To Open Like A Wooden Door
public boolean onBlockActivated(World par1World, int par2, int par3,
		int par4, EntityPlayer par5EntityPlayer, int par6, float par7,
		float par8, float par9) {
	return false;
}

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.