Posted October 12, 201312 yr My forge version is Build 1.6.4-9.11.0.884. I am creating a custom potion effect that places a brick block in front of the player, and when the player moves, the game changes the brick block to whatever type of block was there before. For some reason, when I use setBlock(int xPos, int yPos, int zPos, int blockID), the proper block is changed and the ID of the block is changed(I checked using world.getBlockID(int x, int y, int z)). However, the block is not physically loaded into the world i.e. no texture and no collision box. Does anyone know a fix for this? Here is my custom potion effect class that handles the commands: package eclipse.MoreApples.potion; import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.PotionEffect; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class BuildingPotionEffect extends PotionEffect{ private EntityPlayer p = null; private World w; private boolean doOnce; private boolean firstTime; private boolean moved; private int blockX; private int blockY; private int blockZ; private int oldBlockX; private int oldBlockY; private int oldBlockZ; private int oldBlockID; private int dir; public BuildingPotionEffect(int par1, int par2) { super(par1, par2); doOnce = true; firstTime = true; moved = true; } //This method is called every tick by the potion and is stopped from being called when the potion duration reaches 0 @Override public boolean onUpdate(EntityLivingBase par1EntityLivingBase) { if(doOnce) { p =(EntityPlayer) par1EntityLivingBase; w = p.worldObj; doOnce = false; } else if(this.duration <= 1) { doOnce = true; } //This is the player direction in degrees from 0-360 South is 0, East is 90, North is 180, and West is 270 degrees, dir = MathHelper.floor_double((double)((p.rotationYaw ) + 0.5D)); //This if statement makes sure that 'dir' is positive if(dir < 0) dir*= -1; //This method makes sure that 'dir' stays in the range of 0-360 degrees if(dir >= 360 || dir <0) dir %= 360; //See the method description near the method declaration setVals(dir); w.setBlock(blockX, blockY, blockZ, Block.brick.blockID); int temp =p.worldObj.getBlockId(blockX, blockY, blockZ); p.addChatMessage("Should place brick block"); p.addChatMessage("X: " + blockX + " Y: " + blockY + " Z: " + blockZ); p.addChatMessage("ID of brick is" + Block.brick.blockID + "ID of placed bloc is" + temp); if(moved) { w.setBlock(oldBlockX, oldBlockY, oldBlockZ, oldBlockID); p.addChatMessage("Replacing old block"); } p.addChatMessage("Direction is :" + dir); return super.onUpdate(par1EntityLivingBase); } //This method decides which blocks to change according to which direction the player is facing private void setVals(double dir) { if(dir <=180) { if(dir <= 90) { if(dir <= 45) { if(dir - 22.5 >= 0) { blockX = (int) (p.prevPosX-1); blockZ = (int) (p.prevPosZ+1); } else { blockX = (int) (p.prevPosX); blockZ = (int) (p.prevPosZ+1); } } else { if(dir - 67.5 >= 0) { blockX = (int) (p.prevPosX-1); blockZ = (int) (p.prevPosZ); } else { blockX = (int) (p.prevPosX-1); blockZ = (int) (p.prevPosZ+1); } } } else { if(dir <= 135) { if(dir - 112.5 >= 0) { blockX = (int) (p.prevPosX-1); blockZ = (int) (p.prevPosZ-1); } else { blockX = (int) (p.prevPosX-1); blockZ = (int) (p.prevPosZ); } } else { if(dir - 157.5 >= 0) { blockX = (int) (p.prevPosX); blockZ = (int) (p.prevPosZ-1); } else { blockX = (int) (p.prevPosX-1); blockZ = (int) (p.prevPosZ-1); } } } } else { if(dir <= 270) { if(dir <= 225) { if(dir - 202.5 >= 0) { blockX = (int) (p.prevPosX+1); blockZ = (int) (p.prevPosZ-1); } else { blockX = (int) (p.prevPosX); blockZ = (int) (p.prevPosZ-1); } } else { if(dir - 247.5 >= 0) { blockX = (int) (p.prevPosX+1); blockZ = (int) (p.prevPosZ); } else { blockX = (int) (p.prevPosX+1); blockZ = (int) (p.prevPosZ-1); } } } else { if(dir <= 315) { if(dir - 292.5 >= 0) { blockX = (int) (p.prevPosX+1); blockZ = (int) (p.prevPosZ+1); } else { blockX = (int) (p.prevPosX+1); blockZ = (int) (p.prevPosZ); } } else { if(dir - 337.5 >= 0) { blockX = (int) (p.prevPosX); blockZ = (int) (p.prevPosZ+1); } else { blockX = (int) (p.prevPosX+1); blockZ = (int) (p.prevPosZ+1); } } } } blockY = (int) (p.posY-1); //Correcting the values instead of re-writing all of those if statements blockX-=1; blockZ-=1; blockX *= -1; if(oldBlockX != blockX || oldBlockY != blockY || oldBlockZ != blockZ) moved = true; else moved = false; if(!moved) { oldBlockX = blockX; oldBlockY = blockY; oldBlockZ = blockZ; } //This if statement is used to initially get the old block coordinates if(firstTime) { oldBlockID = w.getBlockId(oldBlockX, oldBlockY, oldBlockZ); firstTime = false; p.addChatMessage("First time"); } } } Thanks for reading and helping! =)
October 12, 201312 yr Use the bult in debugging tools and println calls to figure out which values the x, y, z's are set too, I'm guessing its not getting the correct coords If you guys dont get it.. then well ya.. try harder...
October 12, 201312 yr Now that I look at your setVals function, I can tell you're doing it wrong. double xx = par3Entity.posX; double yy = par3Entity.posY-1; double zz = par3Entity.posZ; Vec3 v = par3Entity.getLookVec(); xx += v.xCoord; zz += v.zCoord; int x = (int)xx; int y = (int)yy; int z = (int)zz; world.setBlock(x, y, z, Block.brick.blockID); That sets the block directly in front of the player, at the level that they're walking, to bricks. It doesn't take into account strafing, but your intent doesn't appear to need that (my own use could benefit from it, but I'm more amused by the fact that it doesn't). 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.
October 12, 201312 yr Author I tried this, however, when the blocks were placed, they were placed at the player's y-value, but when I closed Minecraft and opened it up again(all in the IDE of course), the blocks were set one y value lower(beneath the player's feet). Do you know why this happens and how I can account for strafing? Thanks =)
October 12, 201312 yr My blocks are temporary in nature (allowing the player to "walk on air") so I don't know why the Y value would be off. As to the section question: no, I don't, which is why I decided that it was totally ok for my item to have "downsides" if the user wasn't careful. >:3 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.
October 12, 201312 yr Author Ok, I guess I will play around with it some more and see if I can find a fix. I will post it if I find one. Also, Draco, why was my setVals method wrong?
October 12, 201312 yr Also, Draco, why was my setVals method wrong? Way too complex. 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.
October 12, 201312 yr To account for strafing, you could use moveForward /moveStrafing in EntityLivingBase...or the motionX.Z fields in Entity.
October 12, 201312 yr or the motionX.Z fields in Entity. Funny, I didn't think of that. Oh wait, I did. They're always 0. 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.
October 13, 201312 yr Funny, I didn't think of that. Oh wait, I did. They're always 0. Oh right, Mojang changed that with the "boat update". Then use moveStrafing
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.