Posted December 20, 20159 yr I'm trying to fix a few spawn bypasses in mods, notably ArsMagica2. For block placing, I was able to use ForgeEventFactory.onPlayerBlockPlace and ForgeEventFactory.onPlayerMultiBlockPlace. It's a bit tedious, but it does the job. What about entity attack? Notably, how can I detect if a player can attack an entity in an area?
December 20, 20159 yr There's also an event (BlockBreakEvent?) for breaking blocks, for reference. 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.
December 21, 20159 yr Author Thanks for your answers! Original code is here: https://github.com/LemADEC/ArsMagica2/blob/master/src/main/java/am2/AMEventHandler.java#L583 @SubscribeEvent public void onEntityHurt(LivingHurtEvent event){ ... Entity entitySource = event.source.getSourceOfDamage(); if ( entitySource instanceof EntityPlayer && ((EntityPlayer)entitySource).inventory.armorInventory[2] != null && ((EntityPlayer)entitySource).inventory.armorInventory[2].getItem() == ItemsCommonProxy.earthGuardianArmor && ((EntityPlayer)entitySource).getCurrentEquippedItem() == null ){ event.ammount += 4; double deltaZ = event.entityLiving.posZ - entitySource.posZ; double deltaX = event.entityLiving.posX - entitySource.posX; double angle = Math.atan2(deltaZ, deltaX); double speed = ((EntityPlayer)entitySource).isSprinting() ? 3 : 2; double vertSpeed = ((EntityPlayer)entitySource).isSprinting() ? 0.5 : 0.325; if (event.entityLiving instanceof EntityPlayer){ AMNetHandler.INSTANCE.sendVelocityAddPacket(event.entityLiving.worldObj, event.entityLiving, speed * Math.cos(angle), vertSpeed, speed * Math.sin(angle)); }else{ event.entityLiving.motionX += (speed * Math.cos(angle)); event.entityLiving.motionZ += (speed * Math.sin(angle)); event.entityLiving.motionY += vertSpeed; } event.entityLiving.worldObj.playSoundAtEntity(event.entityLiving, "arsmagica2:spell.cast.earth", 0.4f, event.entityLiving.worldObj.rand.nextFloat() * 0.1F + 0.9F); } ... } I've tried using AttackEntityEvent as such: ... Entity entitySource = event.source.getSourceOfDamage(); if ( entitySource instanceof EntityPlayer && ((EntityPlayer)entitySource).inventory.armorInventory[2] != null && ((EntityPlayer)entitySource).inventory.armorInventory[2].getItem() == ItemsCommonProxy.earthGuardianArmor && ((EntityPlayer)entitySource).getCurrentEquippedItem() == null){ if (!MinecraftForge.EVENT_BUS.post(new AttackEntityEvent((EntityPlayer)entitySource, event.entity))){ event.ammount += 4; double deltaZ = event.entityLiving.posZ - entitySource.posZ; double deltaX = event.entityLiving.posX - entitySource.posX; double angle = Math.atan2(deltaZ, deltaX); double speed = ((EntityPlayer)entitySource).isSprinting() ? 3 : 2; double vertSpeed = ((EntityPlayer)entitySource).isSprinting() ? 0.5 : 0.325; if (event.entityLiving instanceof EntityPlayer){ AMNetHandler.INSTANCE.sendVelocityAddPacket(event.entityLiving.worldObj, event.entityLiving, speed * Math.cos(angle), vertSpeed, speed * Math.sin(angle)); }else{ event.entityLiving.motionX += (speed * Math.cos(angle)); event.entityLiving.motionZ += (speed * Math.sin(angle)); event.entityLiving.motionY += vertSpeed; } event.entityLiving.worldObj.playSoundAtEntity(event.entityLiving, "arsmagica2:spell.cast.earth", 0.4f, event.entityLiving.worldObj.rand.nextFloat() * 0.1F + 0.9F); } } ... Sadly, it doesn't seem to get cancelled whether I'm inside or outside a protected area (spawn with WorldGuard in my case).
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.