Advertisement
Guest User

Untitled

a guest
Aug 25th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.50 KB | None | 0 0
  1. /*
  2.   This file is part of AvatarMod.
  3.    
  4.   AvatarMod is free software: you can redistribute it and/or modify
  5.   it under the terms of the GNU General Public License as published by
  6.   the Free Software Foundation, either version 3 of the License, or
  7.   (at your option) any later version.
  8.  
  9.   AvatarMod is distributed in the hope that it will be useful,
  10.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.   GNU General Public License for more details.
  13.  
  14.   You should have received a copy of the GNU General Public License
  15.   along with AvatarMod. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package com.crowsofwar.avatar.common;
  18.  
  19. import com.crowsofwar.avatar.AvatarInfo;
  20. import com.crowsofwar.avatar.common.entity.mob.EntityAirbender;
  21. import com.crowsofwar.avatar.common.entity.mob.EntityFirebender;
  22. import com.crowsofwar.avatar.common.entity.mob.EntityHumanBender;
  23. import net.minecraft.entity.Entity;
  24. import net.minecraft.entity.passive.EntityVillager;
  25. import net.minecraft.util.math.AxisAlignedBB;
  26. import net.minecraft.util.math.ChunkPos;
  27. import net.minecraft.village.Village;
  28. import net.minecraft.world.World;
  29. import net.minecraft.world.gen.structure.MapGenVillage;
  30. import net.minecraftforge.event.terraingen.InitMapGenEvent;
  31. import net.minecraftforge.event.terraingen.InitMapGenEvent.EventType;
  32. import net.minecraftforge.fml.common.Mod;
  33. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  34.  
  35. import java.util.List;
  36. import java.util.Map;
  37. import java.util.Random;
  38.  
  39. /**
  40.  * @author CrowsOfWar
  41.  */
  42. @Mod.EventBusSubscriber(modid = AvatarInfo.MOD_ID)
  43. public class HumanBenderSpawner {
  44.  
  45.     @SubscribeEvent
  46.     public static void modifyVillageSpawner(InitMapGenEvent e) {
  47.  
  48.         if (e.getType() == EventType.VILLAGE) {
  49.             // TODO See if this messes up superflat world options
  50.             e.setNewGen(new MapGenVillageWithHumanbenders());
  51.  
  52.  
  53.         }
  54.  
  55.     }
  56.  
  57.     private static class MapGenVillageWithHumanbenders extends MapGenVillage {
  58.  
  59.         public MapGenVillageWithHumanbenders() {
  60.             super();
  61.         }
  62.  
  63.         public MapGenVillageWithHumanbenders(Map<String, String> map) {
  64.             super(map);
  65.         }
  66.  
  67.         @Override
  68.         public synchronized boolean generateStructure(World worldIn, Random randomIn, ChunkPos chunkCoord) {
  69.             /*boolean result =**/ super.generateStructure(worldIn, randomIn, chunkCoord);
  70.             //if (result) {
  71.             boolean hasBenders = false;
  72.  
  73.  
  74.                 // This list contains villagers in that structure
  75.                 List<EntityVillager> villagers = worldIn.getEntities(EntityVillager.class, villager -> {
  76.                     assert villager != null;
  77.                     return new ChunkPos(villager.getPosition()).equals(chunkCoord);
  78.                 });
  79.  
  80.                 // To attempt to have all humanbenders be same type, check if
  81.                 // there are nearby humanbenders
  82.                 // If there are just copy their type
  83.                 AxisAlignedBB aabb = new AxisAlignedBB(villagers.get(0).posX + 100, villagers.get(0).posY + 100, villagers.get(0).posZ + 100,
  84.                         villagers.get(0).posX - 100, villagers.get(0).posY - 100, villagers.get(0).posZ - 100);
  85.                 List<EntityHumanBender> nearbyBenders = worldIn.getEntitiesWithinAABB(EntityHumanBender.class,
  86.                         aabb);
  87.                 Village village = worldIn.getVillageCollection()
  88.                         .getNearestVillage(chunkCoord.getBlock(0, 0, 0), 200);
  89.  
  90.                 if (village != null) {
  91.                     EntityHumanBender airbender = new EntityAirbender(worldIn);
  92.                     airbender.setPosition(village.getCenter().getX(), village.getCenter().getY(), village.getCenter().getZ());
  93.                     hasBenders = true;
  94.                 }
  95.  
  96.  
  97.                     for (Entity e : villagers) {
  98.                         int i = rand.nextInt(3) + 1;
  99.                         if (i == 3) {
  100.                             EntityHumanBender b = new EntityAirbender(worldIn);
  101.                             b.setPosition(villagers.get(0).posX, villagers.get(0).posY, villagers.get(0).posZ);
  102.                         }
  103.                     }
  104.  
  105.  
  106.  
  107.  
  108.                 double chance = 100;
  109.                 Random rand = new Random();
  110.                 if (!villagers.isEmpty()/* && rand.nextDouble() * 100 < chance**/) {
  111.  
  112.  
  113.                     boolean firebender;
  114.  
  115.                     if (nearbyBenders.isEmpty()) {
  116.                         firebender = new Random().nextBoolean();
  117.                     } else {
  118.                         firebender = nearbyBenders.get(0) instanceof EntityFirebender;
  119.                         hasBenders = true;
  120.                     }
  121.  
  122.                     for (Entity e : villagers) {
  123.                         int i = rand.nextInt(3) + 1;
  124.                         if (i == 3) {
  125.                             EntityHumanBender bender = firebender ? new EntityFirebender(worldIn)
  126.                                     : new EntityAirbender(worldIn);
  127.                             bender.copyLocationAndAnglesFrom(e);
  128.                             worldIn.spawnEntity(bender);
  129.                             hasBenders = true;
  130.                         }
  131.                     }
  132.                 }
  133.             //}
  134.  
  135.             return hasBenders;
  136.         }
  137.  
  138.     }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement