Jump to content

Recommended Posts

Posted

OK, so I've been playing with tile entities for a week and I actually learned a lot, well kinda. But anyway. I wanted to make a block with more than 100 metadatas/subtypes and I already knew that I need tile entities. I was looking on the forums if anyone ever actually needed help with this and I found one but it helped me partially. What I did make is 100 blocks to appear in one creative tab and  I learned how to put textures on those block that are actually tile entities. Now I've got problems that I can't solve and I need your help. The problems are:

1. Blocks don't have textures when placed on the world but they do have in the creative tab.

2. When I drop the block with metadata 1 and 0, they both make a single stack and after I pick it up, the stack will be blocks wit metadata 0.

3. A weird problem with names.

 

This is actually the fist time I'm "playing" with tile entities, because I was stuck with blocks that have metadatas, so if there are some silly parts of my code feel free to laugh 'till you die. Here it is

ItemBlockMegaBlock

package asphaltMod.common;


import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class ItemBlockMegaBlock extends ItemBlock
{
   
private static final TileEntity TE = new TileEntityMegaBlock();

public ItemBlockMegaBlock(int ID)
{	
	super(ID);
	setHasSubtypes(true);
	this.setCreativeTab(CreativeTabs.tabBlock);
}

@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int metadata)
{		 
		TE.blockMetadata = metadata;
		return AsphaltMod.tileEntityTest.getIcon(2, this.TE.blockMetadata);
}

public int getMetadata(int metadata)
{
	return this.TE.blockMetadata;
}


    public int damageDropped(int par1)
    {
        return this.TE.blockMetadata;
    }
    
public String getItemNameIS(ItemStack is)
{
	this.TE.blockMetadata = is.getItemDamage();
	return "asphaltBlocks_" + this.TE.blockMetadata;
}

public String getUnlocalizedName(ItemStack itemstack)
 {
  return getUnlocalizedName() + "." + itemstack.getItemDamage();
 }
}

 

BlockMegaBlock

package asphaltMod.common;

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

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockMegaBlock extends BlockContainer
{
private static TileEntity TE  = new TileEntityMegaBlock();
@SideOnly(Side.CLIENT)
private Icon AT_0;
@SideOnly(Side.CLIENT)
private Icon AT_1;

@SideOnly(Side.CLIENT)
private Icon[][] iconBuffer;

public BlockMegaBlock(int par1, Material material)
{
	super(par1, material);
}



public boolean hasTileEntity(int meta)
{
	return true;
}

public TileEntity createNewTileEntity(World world)
{
	this.TE.blockMetadata = 100;
	return new TileEntityMegaBlock();
}

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{	
	this.AT_0 = iconRegister.registerIcon("asphalt_0");
	this.AT_1 = iconRegister.registerIcon("asphalt_1");
}

 public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int side)
 {
	 return this.getIcon(side, TE.blockMetadata);
 }

public Icon getIcon(int side, int meta)
{

	return meta == 0 ? (side == 0 ? this.AT_0 : (side == 1 ? this.AT_0 : (side == 2 ? this.AT_0 : (side == 3 ? this.AT_0 : (side == 4 ? this.AT_0 : (side == 5 ? this.AT_0 : this.blockIcon))))))
		: (meta == 1 ? (side == 0 ? this.AT_0 : (side == 1 ? this.AT_1 : (side == 2 ? this.AT_0 : (side == 3 ? this.AT_0 : (side == 4 ? this.AT_0 : (side == 5 ? this.AT_0 : this.blockIcon)))))) : this.blockIcon);
}


public int idDropped(int ID, Random par2Random, int par3)
    {
	return this.blockID;
    }

 protected ItemStack createStackedBlock(int par1)
    {
        return new ItemStack(AsphaltMod.tileEntityTest.blockID, 1, par1);
    }

public int damageDropped(int metadata)
{
	return TE.blockMetadata;
}

@SideOnly(Side.CLIENT)
public void getSubBlocks(int ID, CreativeTabs creativeTabs, List list)
{
	int metadata = TE.blockMetadata;
	for(metadata = 0; metadata <= 100; metadata++)
	{
		list.add(new ItemStack(ID, 1, metadata));
	}
}
}

TileEntityMegaBlock

package asphaltMod.common;

import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;

public class TileEntityMegaBlock extends TileEntity
{
public static int blockMetadata;

public TileEntityMegaBlock()
{
}


@Override
public void writeToNBT(NBTTagCompound nbt)
{
nbt.setInteger("metadata", blockMetadata);
super.writeToNBT(nbt);
}

@Override
public void readFromNBT(NBTTagCompound nbt)
{
	blockMetadata = nbt.getInteger("metadata");
	super.readFromNBT(nbt);
}

public int getBlockMetadata()
{
	return this.blockMetadata;
}

public void setMeta(int metadata)
{
	this.blockMetadata = metadata;
}

public TileEntity returnTE()
{
	return this;
}

}

And things in my mods' main class:

public static Block tileEntityTest;

 

tileEntityTest = new BlockMegaBlock(700, Material.rock).setCreativeTab(CreativeTabs.tabTransport);

 

GameRegistry.registerBlock(tileEntityTest, ItemBlockMegaBlock.class, "TET");

            GameRegistry.registerTileEntity(TileEntityMegaBlock.class, "watafak");

 

Note:

This is only just a test for me to see how to make blocks with more than 16 metadatas. This isn't the final code. So can anyone help me?

Posted
1. Blocks don't have textures when placed on the world but they do have in the creative tab.

2. When I drop the block with metadata 1 and 0, they both make a single stack and after I pick it up, the stack will be blocks wit metadata 0.

3. A weird problem with names.

I think all problems are related to your implementation of custom ItemBlock. But looking at your TE, it can't really work.

 

public class TileEntityMegaBlock extends TileEntity
{
// definitely wrong, or is your intention to have only placed one subtype of blocks at one time in all your worlds?
public static int blockMetadata;

....	
// ehm, what for?
public TileEntity returnTE()
{
	return this;
}
}

 

You have to implement placing method in ItemBlock and make sure the TE of newly placed block has set proper subtype (matching item damage of ItemBlock). Your TE must implement NBT serialization or you lose your subtype information every time a custom block is unloaded/loaded. Also when breaking a block the item which drops must have set damage matching the destroyed block's subtype (from its TE) .

 

public class BlockMegaBlock extends BlockContainer
{
    private static TileEntity TE  = new TileEntityMegaBlock();

 

Looking at this I see you should read more about basic classes Minecraft uses before trying to implement "subtypes" - e.g. this blog is nice.

 

PS: I recommend to not exchange terms metadata and item damage. Item damage can be used when placing a block (in custom ItemBlock), but it does not map 1:1 to metadata (which are limited to 16 values, item damage has full integer range [~65k?]).

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Posted
I do think that I need to read more about classes.

 

Fixed.  It's not about the classes Minecraft has, you just need to learn more about classes in general.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Well, you can begin by removing all the shit in your code.

 

Delete the ItemBlockMegaBlock.

In BlockMegaBlock, remove:

private static TileEntity TE  = new TileEntityMegaBlock();
...
this.TE.blockMetadata = 100;
...

public int idDropped(int ID, Random par2Random, int par3)
    {
	return this.blockID;
    }

public int damageDropped(int metadata)
{
	return TE.blockMetadata;
}

In TileEntityMegaBlock, remove the static here

public static int blockMetadata;

 

Then fix all errors following, using your brain and not an auto fix.

Posted

A thing before you can not load tile entities on your way (or i am wrong) you have to add a new form of block placing for that. And textures for that you can use extended item.

 

public class yourTile extends TileEntity
{
     public int facing = 0;
     public int extendedMeta = 0;
     
     public int getExtendedMeta()
     {
          return extendedMeta;
     }

     public void setExtendedMeta(int i)
     {
          extendedMeta = i;
     }

     public int getFacing()
     {
         return facing;
     }

      public void setFacing(int i)
      {
          facing = i;
      }
}

 

this should stay at your tile entity.

And when you place the itemBlock you say place your normal block with meta 0 and set the extended meta in the tile like you want. And when you want to know which name it has and which texture then you look at the extended meta id.

By the way with names and creative tab i would use itemNBTData. is a lot easier^^".

Posted

But their right. When you do not know how to handel a problem then you should learn.

I give you just a hint how it should look like when you get everything done than its good. This way i explained to you is ok but when you extend it to much then it could lag.

 

Posted

realise were not telling you to learn java because we really love to make people suffer. We really mean you SHOULD REALLY learn java before trying anything. I mean you can TRY to code without knowing that, but as soon as youll try doing something more difficult you'll have to surrender because you'll have NO idea what the hell is going on. SO ... here the deal, do both at the same time. Try to do wtv mod you're trying to do and whenever you have a question, if people tell you its relevant to java knowledge, learn it. Because most of the time its not going to be a thing you'll use only once. The concepts you'll learn will be used over and over. It would suck for you to have to wait for an answer EVERYTIME you encounter the SAME thing over and over :\

 

By the way, you might be wondering what is the difference between someone who knows java and someone who doesn't ?

 

here a small mod i made, literally I spent 1h on it:

http://www.minecraftforge.net/forum/index.php/topic,11375.0.html

someone who doesn't know how to code ... would probably never finish it, he would forfeit before (at least not before learning to code... and some openGL, but that doesn't matter)

 

good luck have fun :D

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Yeah you are right people should learn java.

But and that i think is interesting.

I had just readed 1 book of java (which did not really help me)

and i have not much problems with coding.

When i have a problem then i solve it very fast.

 

I think people can learn as much java if they want, but when

they do not know how to search for something what they need,

like: how do i make a tool that does not extends the vanilla codes.

then they do not need to learn anything.

 

Also i think just give people a chance and give him little hints instead of telling them:

What are you doing with that and that.

I mean when they still asking the same question then you can say it or in another stiuation:

give hints but remeber them you should learn java.

 

I myself use minecraft to understand how to programm,

i mean to get the thinking how to solve something, or how to start with something.

Also when i have a error that i know where i can search.

xD i only ask about things i never coded before xD

But enought about my self^^" But you get the point?

Posted

Moritz, you're only half-right,

 

yes people who can use google will be fine. but what if you want to make something NO-ONE else has done before?

 

you

are

f***ed

 

example:

i can guarantee that no one who hasnt learned a bit of java will be able to do this mod

 

http://www.minecraftforge.net/forum/index.php/topic,11435.0.html

 

its from scratch, it uses a bunch of very complex java mechanics, completelly impossible to reproduce without knowing where you're going. Afaik 3 mod are like this: the forge revolution, Quadom and hack slash mine. the creator of all these mods had extremelly strong java skills before even starting to code the mod.

 

none the less modding is "somewhat" a good way to learn to code IF and ONLY IF you dont overdo it. Dont try to make competitors to the mods ive mentionned above if you are not confident in your skills and have a pretty good idea how to make everything BEFORE starting.

 

 

edit: yes the forge rev is my mod and im only using it as an example because i know for a fact that its a complex mod. I could have used a lot of other liiiiiiiike buildcraft. but buildcraft has certain api, so its a huge help to make something similar which a new modder wouldnt have to create from scratch

 

 

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

If you have background in any language, then you should be OK.  I picked up Java (well enough to mod) by trying to mod.  There's no way I could ever create a huge chunk of something like Minecraft from scratch (managing GUIs, rendering, multiplayer...nope, can't build from scratch)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I started as noob with no clue about coding. And now i have made a lot of Cool technic stuff that helps people a lot out. xD and a lot of more things are planned!

 

here my mod: speiger.jimdo.com

 

xD

  • 3 weeks later...

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.