Posted December 9, 201311 yr 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
December 10, 201311 yr //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.
December 10, 201311 yr Author 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.
December 10, 201311 yr Hi This link might help with some of the background understanding.. http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html In particular the first four topics, plus Minecraft Game Loop, plus "How Forge starts up your code", plus "Client <--> Server communication" -TGG
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.