Everything posted by MrArcane111
-
[SOLVED] Problems With Tick Handlers (Casting World to Object[])
Okay, I see what you're saying. However, there is no need to be snarky. I was just stating how I did it (and looking back at it, I would have used the worldObj, but this was some old code from my GitHub page that I used). I welcome your new information --I enjoy improving as a coder. I am certainly (by a great magnitude) not the best programmer, nor do I claim to be; I just saw a person here who needed an answer, and I gave the only one I knew. Thank you for all the work you do for the Modding Support. Have a great evening (at least, it is here).
-
HarvestDropsEvent - Removing and Adding Drops
So would for(int size = 0; size < event.drops.size(); size++) { ItemStack stack = event.drops.get(size).getEntityItem(); } be somewhere along those lines? Correct me if I'm wrong, but the int size is grabbing the ItemStack ArrayList size and then getting an EntityItem instance of it. So how would that assist me in removing the drop as an item index? Thanks.
-
HarvestDropsEvent - Removing and Adding Drops
I've made an enchantment that has a chance to smelt blocks when mined, however, I have run into a snag: adding drops is no problem, but removing them is. Here is my code: @ForgeSubscribe public void onHarvestBlocks(BlockEvent.HarvestDropsEvent event) { EntityPlayer player = event.harvester; ItemStack heldItem = player.inventory.getCurrentItem(); Block block = event.block; flameTouchAmount = EnchantmentHelper.getEnchantmentLevel(ArcaneEnchantments.flameTouch.effectId, heldItem); if(heldItem == null) { return; } else if(flameTouchAmount > 0) { isFlameTouched = true; } if(isFlameTouched = true) { if(player.worldObj.rand.nextInt(2) == 0) { // So I was going to use FurnaceRecipes, but then I decided against it because this way gives me more flexibility if(block == Block.oreIron) { event.drops.add(new ItemStack(Item.ingotIron, 1)); event.drops.remove(15); } if(block == Block.oreGold) { event.drops.add(new ItemStack(Item.ingotGold, 1)); event.drops.remove(Block.oreGold); } } } } The "event.drops.remove" has two options: an item index or an Object. I have tried various ways for each but either they do not work, or they crash the game because of an ArrayList error. If anyone point me in the right direction, that would be fantastic. I hope you have a great day, and thank you for taking the time to read this post/help me out.
-
[SOLVED] Problems With Tick Handlers (Casting World to Object[])
@diesieben07 It's not bull if it works. I do not see anything wrong with it at all. Alternatively, you could just send it to the Client Side by creating a separate TickHandler. If I did not answer the original question, please explain to me why instead of just relating my methods to mere garbage.
-
Homing Arrow (Entity Bounding Box Issues)
Okay, well, I checked out the Ghast code, and this is what I've got now: double d = target.posX - arrow.posX; double d1 = target.boundingBox.minY + (double) (target.height / 2.0F) - (arrow.posY + (double) (arrow.height / 2.0F)); double d2 = target.posZ - arrow.posZ; It's certainly a lot cleaner and more accurate, but there are still some weird bounding box glitches. I still cannot determine whether it is the game's rendering issues or my homing code.
-
[SOLVED] Problems With Tick Handlers (Casting World to Object[])
Not sure if this exactly helps, but if you want to add a cast for World (and EntityPlayer) within a server Tick Handler, I've found this method effective: ArrayList list = (ArrayList) MinecraftServer.getServer().getConfigurationManager().playerEntityList; Iterator iterator = list.iterator(); while (iterator.hasNext()) { EntityPlayerMP player = (EntityPlayerMP) iterator.next(); WorldServer world = MinecraftServer.getServer().worldServerForDimension(player.dimension); // Add your stuff in here... } If this doesn't help you, maybe this will help someone else. This is just what I do for casting the World object in my ServerTickHandlers. Ciao!
-
Homing Arrow (Entity Bounding Box Issues)
The EntityJoinedWorld Event will call if it is a homing arrow, however, the entity event is called every time the specified entity is updated; I do not believe the EntityJoinedWorld event does that. Thanks for the Fireball suggestion. I will check it out and post my results here.
-
Need someone to teach me forge api
First, I would recommend learning Java basics before delving into APIs. Second, I would read the tutorials associated with the Forge API basics. Third, I would read the Javadocs for the Forge API. Fourth, I would look on GitHub for open-source mods that include Forge integration for insight. Lastly, I would begin coding, having drawn all of the above mentioned details.
-
Homing Arrow (Entity Bounding Box Issues)
Okay, so I have already successfully added the Homing Enchantment code to my mod, and all the methods related are being called correctly. I've added the homing code into an EntityEvent (I grabbed an instance of the EntityArrow), and when I fire the bow, the arrow locates the closest entity, and zooms to the entity's location. The problem I have is where the arrow lands up. I intended for the arrow to land in the relative center of the mob, but I have been unsuccessful. I've been using the bounding boxes of the entity as a guide, but to no avail. Usually, the arrow ends up hitting the mob, then rendering near the mob's feet. It is really an odd occurrence. Anyway, here is the code for the arrow: @ForgeSubscribe public void arrowInAir(EntityEvent event) { if(event.entity instanceof EntityArrow) { EntityArrow arrow = (EntityArrow) event.entity; // To whomever reads this, other than myself, I am terribly sorry for the mess of code below...ugh... if(isHoming == true) { if(target == null || target.velocityChanged || !target.canEntityBeSeen(arrow)) { double d = arrow.posX; double d1 = arrow.posY; double d2 = arrow.posZ; double d3 = 6 * homingAmount; double d4 = -1D; EntityLiving entityliving = null; List list = arrow.worldObj.getEntitiesWithinAABB(net.minecraft.entity.EntityLiving.class, arrow.boundingBox.expand(d3, d3, d3)); for(int i = 0; i < list.size(); i++) { EntityLiving entityliving1 = (EntityLiving) list.get(i); if(entityliving1 == arrow.shootingEntity) { continue; } double d5 = entityliving1.getDistance(d, d1, d2); if((d3 < 0.0D || d5 < d3 * d3) && (d4 == -1D || d5 < d4) && entityliving1.canEntityBeSeen(arrow)) { d4 = d5; entityliving = entityliving1; } } target = entityliving; } if(target != null) { // All these fancy calculations guarantee that it will hit an entity dead on double d = (target.boundingBox.minX + (target.boundingBox.maxX - target.boundingBox.minX) / 2D) - arrow.posX; double d1 = (target.boundingBox.minY + (target.boundingBox.maxY - target.boundingBox.minY) / 2D) - arrow.posY; double d2 = (target.boundingBox.minZ + (target.boundingBox.maxZ - target.boundingBox.minZ) / 2D) - arrow.posZ;*/ arrow.setThrowableHeading(d, d1, d2, 1.5F, 0.0F); //homingAmount = 0; } } Thanks to anyone who can help. This site has an amazing support group, and I am thankful for that.
-
[Partially Solved] HELP: Strange PlayerEvent Phenomenon
Alright, a little update: I have figured out how to call the player's jump action, even without calling the key code of the Minecraft class too. In the LivingEvent, there is a LivingJumpEvent, which I am now using. Here is my code: @ForgeSubscribe public void playerFallen(LivingJumpEvent event) { EntityLivingBase living = event.entityLiving; EntityPlayer player = (EntityPlayer) living; ItemStack stack = player.inventory.armorItemInSlot(0); if(EnchantmentHelper.getEnchantmentLevel(ArcaneEnchantments.jumpBoost.effectId, stack) > 0) { if(player.motionY > 0.0D) { player.motionY += 0.069; } } } Granted, the higher jump effect is still not working quite yet, but I believe I am on the road to success. It just took some fresh eyes and a break from coding to figure it out. Thank you guys for your assistance, and I hope anybody reading this in the future can fix their problem as well!
-
[Partially Solved] HELP: Strange PlayerEvent Phenomenon
Yes, both if-statements are being executed correctly...only when the player is trying to break a block and is jumping. There are many player events, but the PlayerEvent is the main one, correct? Also, as I said above, code like player.setInvisible(true); works correctly without having to try breaking blocks. I have looked at the Forge Hook page, and it is perfectly valid, I believe, to use a hook with the PlayerEvent. I am just utterly perplexed.
-
[Partially Solved] HELP: Strange PlayerEvent Phenomenon
I am creating a mod that adds more enchantments to the game. I am using the Forge Hooks (which are amazing, by the way) to insert the new effects of the enchantment into the base classes. One of my added enchantments was a jump boost which would increase the player's jump height if the boots contain the corresponding enchantment. I've discovered something very odd, however, with the PlayerEvent hook: @ForgeSubscribe @SideOnly(Side.CLIENT) public void playerFallen(PlayerEvent event) { Minecraft minecraft = Minecraft.getMinecraft(); EntityPlayer player = event.entityPlayer; ItemStack stack = player.inventory.armorItemInSlot(0); if(EnchantmentHelper.getEnchantmentLevel(ArcaneEnchantments.jumpBoost.effectId, stack) > 0) { canJumpBoost = true; } if(canJumpBoost == true && Keyboard.isKeyDown(minecraft.gameSettings.keyBindJump.keyCode) && player.motionY > 0.0D) { player.motionY += 0.069; } } (Brief note: the canJumpBoost boolean is publicly declared in my hook container class.) The code works fine except for one thing: the jump boost only takes effect when you are trying to break a block. As far as I can tell, the PlayerEvent has no fields or arguments which require the player to be breaking blocks in order to execute an action. In fact, when I plug in EntityPlayer booleans such as player.setInvisible(true); it works just fine. Also, I add "System.out" within my if-statements to make sure the method is being called --which it is. If any of you could help me figure out what is going on here, I would be much obliged. Thank you for taking the time to read this, and have a wonderful day.
-
[Solved!] Getting a player instance in ServerTickHandler
I was actually able to solve the problem. If any of you are interested, here's how I got a server instance of the player and the world: if(type.equals(EnumSet.of(TickType.SERVER))) { ArrayList list = (ArrayList) MinecraftServer.getServer().getConfigurationManager().playerEntityList; Iterator iterator = list.iterator(); while(iterator.hasNext()) { EntityPlayerMP player = (EntityPlayerMP) iterator.next(); WorldServer world = MinecraftServer.getServer().worldServerForDimension(player.dimension); } }
-
[Solved!] Getting a player instance in ServerTickHandler
Well, I would like for all players to be in.
-
[Solved!] Getting a player instance in ServerTickHandler
I would like to get an EntityPlayer instance inside my ServerTickHandler. So far, I've tried to use a static reference from another class, like this: EntityPlayer player = ClimbingGloveEngine.player; But all that does is pull a NullPointerException. I've seen people getting an instance of the player by using the tickData: EntityPlayer player = (EntityPlayer) tickData[1]; But that also causes an error: an out of bounds. If someone could please help me get a server instance of the player, that would be fantastic. I really don't want to use packets. Thanks for your help!
IPS spam blocked by CleanTalk.