Jump to content

Recommended Posts

Posted

I am a tutorial-reading, source-code-speculating newb, so pardon my ignorance.

 

When I try to make a block plant something, the plant appears, but as soon as I interact with it (right-click, left-click, etc.), it disappears.  I hope that this is a problem that you veterans are familiar with, because I have no real idea what's going on.

 

I want to make a version of a dropper that plants on tilled soil.  To do this, I made a block, extended the dropper class, and overwrote the dispense method. 

 

In the method, I call the onItemUse method of the seeds, and according to a println, the 'player', ' x' ,'y' ,'z' , and 'direction' of the onItemUse call are the same as when I do it myself (manually planting still works).

 

here is what I added to the dispense method.

                	//first, we parasitically use the first player in the world list.
                	//(change this later)
                	World world=Minecraft.getMinecraft().theWorld;
                	int tarx=x + Facing.offsetsXForSide[i1],
                		tary=y + Facing.offsetsYForSide[i1],
                		tarz=z + Facing.offsetsZForSide[i1];
                	float	f1=1, f2=1, f3=1;
                	boolean used = false;
                    if (world.playerEntities.size()>0)
                    {
                    	EntityPlayer oddballPlayer = (EntityPlayer) world.playerEntities.get(0);
                		used = itemstack.getItem().onItemUse(itemstack, oddballPlayer, world, tarx, tary, tarz, 1, f1, f2, f3);
                    	if (used){
                			System.out.println("I PLANTED!");
                		}else{
                			System.out.println("I tried...");
                		}
                	}

                    if (used){
                    	itemstack1 = itemstack.copy();

                    	if (--itemstack1.stackSize == 0)
                    	{
                    		itemstack1 = null;
                    	}	
                    }else{
                    	itemstack1 = getBehaviorForItemStack(itemstack).dispense(blocksourceimpl, itemstack);
                    }

 

the full class is here:

http://pastebin.com/2cQKdpGE

Posted

//first, we parasitically use the first player in the world list.
                	//(change this later)
                	World world=Minecraft.getMinecraft().theWorld;

You need to change that now. It is client-side only, while placing blocks is server side.

Posted
You need to change that now.

 

Thanks GoToLink!

 

I wondered if this was some client/server thing, but as I said, I'm new, and I really don't know how the client/server thing works.  If you have any advice on learning the client/server thing, I'll eat it up, but if not, I'm sure I can figure it out somewhere else.

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.