Posted June 23, 20178 yr I'm trying to make a mob ward that prevents mobs from spawning within a set area for 1.12. I was hoping someone could point me to example code that checks to see if mob is within x distances of block. So far this is what I've been able to adapt from old 1.7 mods. Spoiler EventHandler Spoiler public class EventHandlerServer { public static String debug; public static List<TileEntity> wardPositions; public static boolean isInRangeOfWard(final Entity entity) { for (final TileEntity coord : EventHandlerServer.wardPositions) { if (coord.getWorld().provider.getDimension() == entity.world.provider.getDimension() && entity.world.getTileEntity(coord.getPos()) instanceof IMobWard) { final TileEntity tile = entity.world.getTileEntity(coord.getPos()); final double distanceSq = tile.getDistanceSq(entity.posX, entity.posY,entity.posZ); if (distanceSq <= ((IMobWard)tile).getMobWardRangeSquared()) { return true; } continue; } } return false; } @SubscribeEvent public void mobWardDenySpawn(final LivingSpawnEvent.CheckSpawn event) { if (event.getResult() == Event.Result.ALLOW) { return; } if (event.getEntityLiving().isCreatureType(EnumCreatureType.MONSTER, false) && isInRangeOfWard(event.getEntity())) { event.setResult(Event.Result.DENY); } } } TileEntity Spoiler public class TileEntityMobWardTalisman extends TileEntity implements IMobWard { @Override public double getMobWardRangeSquared() { if (this.getBlockType() instanceof BlockMobWardTalisman) { return 4096; } return 0; } public void invalidate() { EventHandlerServer.wardPositions.remove(this); super.invalidate(); } public void onChunkUnload() { super.onChunkUnload(); EventHandlerServer.wardPositions.remove(this); } public void validate() { final TileEntity myCoord = this; for (int i = 0; i < EventHandlerServer.wardPositions.size(); ++i) { final TileEntity coord = EventHandlerServer.wardPositions.get(i); if (myCoord == coord) { return; } } EventHandlerServer.wardPositions.add(myCoord); } } Edited June 23, 20178 yr by Stroam You don't need to point out what's wrong with the programmer. I already know. Now what's wrong with the code?
June 23, 20178 yr Author Was trying to adapt it from https://github.com/sameer/. I kinda figured I needed a better example. I'll try that and see how it goes. Thanks for your help and very quick replies as usual. You don't need to point out what's wrong with the programmer. I already know. Now what's wrong with the code?
June 23, 20178 yr Author We all got to start from somewhere. You don't need to point out what's wrong with the programmer. I already know. Now what's wrong with the code?
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.