
Code Wrecker
Members-
Posts
8 -
Joined
-
Last visited
Everything posted by Code Wrecker
-
Well, I wrote a simple test, and I think I figured out what was happening... ... onItemUse will prevent onItemRightClick from being called, if onItemUse returns true. So if you return false for onItemUse, onItemRightClick fires off. So all my double building problems, and phantom reports, and everything else... I solved. (I hope) World.isRemote Detect inventory Handle block placement in one function, by having the other always return false, just set locations with onItemUse, and false to the other fires. I still don't know if this is the 'right' way to do this, but after a lot of trial and error. I guess I should have just been more methodical. --Code Wrecker
-
Okay, I saw an example where they are checking if(!world.isRemote) So let me ask two different questions that will hopefully will get an answer. Should I fire placing the block only remote, or only client side? Second question, I had onItemUse, and onItemRightClick calling the same building method. Sometimes it fires twice, sometimes it only fires once. Is it supposed to fire like that? What determines if onItemUse will fire, or if onItemRightClick will fire? --Code Wrecker
-
So, I'm making an item that helps you place blocks at odd locations. You set the opposite side you want the block to place on. So you can build down under your feet. Or behind the block your standing on, so you can build a bridge out in front of you without backing up and shift clicking the whole time. The problem I'm having is, the inventory count gets off, and I end up placing phantom blocks if you do actions too quickly. Here is the code that works, but doesn't work. There really is nothing too special about it. I've used .tryPlaceItemIntoWorld, and iStack.getItem().onUseblahblahblah. Both decriment the count, but the client doesn't get the update. I just added in the player.inventoryContainer.detectAndSendChanges() but I haven't seen anyone else use that. I THINK it works now, but I feel there must be a better way, and I'm not sure I"m not going to continue to get duplication, and phantom blocks. @Override public ItemStack onItemRightClick(ItemStack cStack, World world, EntityPlayer player) { if (!originSet) return cStack; player.swingItem(); Block bBlock = null; int iLoc = -1; int mySide = -1; if (originSet) { if (!player.isSneaking()) { mySide = originSide; } else { mySide = flipSide(originSide); } } for (int i = 0; i < player.inventory.mainInventory.length; ++i) { if (player.inventory.mainInventory[i] != null) { bBlock = Block.getBlockFromItem(player.inventory.mainInventory[i].getItem()); if (bBlock.getMaterial().blocksMovement()) { iStack = player.inventory.getStackInSlot(i); iLoc = i; break; } } } if (iStack != null) { int myPosY = originY; int myPosX = originX; int myPosZ = originZ; Block block = world.getBlock(originX, originY, originZ); while (block.getMaterial().blocksMovement()) { if (mySide == 0) { myPosY++; } if (mySide == 1) { myPosY--; } if (mySide == 2) { myPosZ++; } if (mySide == 3) { myPosZ--; } if (mySide == 4) { myPosX++; } if (mySide == 5) { myPosX--; } block = world.getBlock(myPosX, myPosY, myPosZ); } if (myPosY > 0 && player.getPlayerCoordinates().getDistanceSquared(myPosX, myPosY, myPosZ) < 12) { if (iStack.stackSize <= 0) { return cStack; } if (iStack.tryPlaceItemIntoWorld(player, world, myPosX, myPosY, myPosZ, mySide, originF1, originF2, originF3)) { player.inventoryContainer.detectAndSendChanges(); if (iStack.stackSize <= 0) { // iStack = null; player.inventory.mainInventory[iLoc] = null; player.inventoryContainer.detectAndSendChanges(); } } return cStack; } return cStack; } return cStack; }
-
Yeah, I get that. I guess there is no callback or standard routine that is clearing the inventory. It must be cleared someplace. I've not found the inventory.slot == null deal in the source yet. For now I'll just keep clearing it how I'm doing it. Remember the slot, and clear it.
-
I'm creating an item that places blocks from your inventory. The idea of the item is, if you click side 0, it places on side 1 of the furthest solid block in that direction. If you click side 2, it places on the furthest block on side 3. etc etc. (So you can stand in one place, and build a line of blocks away from you, above you, or below you, by simply clicking a 'source' block, and it will use your inventory and build out.) I've built things that place blocks before, no big deal. I was trying to streamline it, put in more checks for world protection, valid placement, and things like that. So I was reusing a bunch of code from ItemBlock.class. Why reinvent the wheel? Use the default minecraft checks to do the heavy lifting. At the end of the day, my OnUse grabs an ItemStack from inventory, not an ItemBlock. I'm just trying to find the 'hook' that clears the inventory of an item when the itemstack/itemblock stack count ==0; Sure I could remember what inventory slot I grabbed, and then go back into the player inventory and null that. I'm just looking for a more elegant way of dealing with it, since I don't see any of the default minecraft code using the brute force player.inventory.maineinventory[x] = null; Is there some method I should call? Here is what I'm currently doing to place the block, and I'm not sure I like it. iStack.tryPlaceItemIntoWorld(player, world, myPosX, myPosY, myPosZ, mySide, f1, f2, f3)) It decrements the stack to 0, and all that, it just doesn't destroy the stack from the inventory if I hit 0. --CodeWrecker
-
Baby horse already finds, and follow adult horse. You could override that method, and change the logic. I'm not sure what you mean by.... "control". You want to throw a skeleton on a horse, and have him ride it? When I added my chicken fall logic, you don't need to re-write everything. Just add it in, and then call the super(onLivingUpdate) or what have you. @Override onUpdate() blah blah blah add add add super(onUpdate) something along those lines. So you don't have to rebuild all the 'default' horse behavior, like grazing, etc.
-
I too made a custom horse!!! However I found it is MUCH easier to just extend horse, and then ONLY change the very specific things you want on the horse. So for example... My horse ONLY ADDS to the on update event to add chicken floating, and null out falling damage. Everything else is 100% stock horse. Looking at most of this code, I don't see why you're overriding ALL of it. Just change things with your constructor if you want your horse faster, or something like that. Or am I missing the point. (It would simplify your entire endeavor.)
-
So I wrote a snip of code to catch players falling out of the neither and overworld, and place them back someplace safe. Now I haven't had a lot of falling out of world problems since 1.6.4. But it was on my list of things to solve when I got around to modding. For starters, I realize there MUST be better ways of doing this. This is functional, and after trying to get the world in some global variable, and thinking of calling several player "safe spawn" functions, I went with this hack. My concern is... This is called for every LivingUpdateEvent (yuck). It has to hook the correct variables (I'd prefer to use some constants.) I call some random dimension checks. (Getting the correct player dim based on bed, seems to be some NBT Forge hack.) So other than the things I hate about it, it's functional, and gets rid of a long standing pet peeve of mine... Falling out of a world for no good reason. What changes/functions would streamline this? @SubscribeEvent public void checkUpdate(LivingUpdateEvent event) { if (event.entityLiving instanceof EntityPlayer && event.entity.posY < -60.0D) { if(!(event.entityLiving.dimension == 0 || event.entityLiving.dimension == -1)){ return; } OverWorld = DimensionManager.getWorld(0); spawn = OverWorld.getSpawnPoint(); EntityPlayerMP playerMP = (EntityPlayerMP) event.entity; if (((EntityPlayer) event.entityLiving).getBedLocation(0) != null) { spawn = ((EntityPlayer) event.entityLiving).getBedLocation(0); } System.out.println("Saving the day!"); event.entityLiving.fallDistance = 0; if (event.entity.worldObj != OverWorld) { playerMP.mcServer.getConfigurationManager().transferPlayerToDimension(playerMP, 0); } event.entityLiving.setPositionAndUpdate(spawn.posX, spawn.posY + .1, spawn.posZ);