Search in sources :

Example 1 with com.tntmodders.takumi.entity.mobs

use of com.tntmodders.takumi.entity.mobs in project takumicraft by TNTModders.

the class TakumiEntityCore method register.

public static void register() {
    // CREATURE_TAKUMI = EnumHelper.addCreatureType("creature_takumi", EntityTakumiAbstractCreeper.class, 100, Material.AIR, false, true);
    // WATER_TAKUMI = EnumHelper.addCreatureType("water_takumi", EntityTakumiAbstractCreeper.class, 25, Material.WATER, false, false);
    Biome.REGISTRY.iterator().forEachRemaining(biome -> biomes.add(biome));
    biomes.remove(Biomes.HELL);
    biomes.remove(Biomes.VOID);
    /*List<Class> files = TakumiUtils.getListClass("com/tntmodders/takumi/entity/mobs/");*/
    ArrayList<EntityHolder> entityHolders = new ArrayList<>();
    for (Class clazz : CLASS_LIST) {
        try {
            /*ClassLoader loader = TakumiCraftCore.class.getClassLoader();
                //Class clazz = loader.loadClass("com.tntmodders.takumi.entity.mobs." + file.getName().replaceAll(".class", ""));*/
            ITakumiEntity entity = (ITakumiEntity) clazz.getConstructor(World.class).newInstance((World) null);
            entityHolders.add(new EntityHolder(clazz, entity));
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
    // List <File> files = TakumiUtils.getListFile("com/tntmodders/takumi/entity/mobs/");
    /*for (File file : files) {
            try {
                ClassLoader loader = TakumiCraftCore.class.getClassLoader();
                Class clazz = loader.loadClass("com.tntmodders.takumi.entity.mobs." + file.getName().replaceAll(".class", ""));
                ITakumiEntity entity = (ITakumiEntity) clazz.getConstructor(World.class).newInstance((World) null);
                entityHolders.add(new EntityHolder(clazz, entity));
            } catch (Exception e) {
                //e.printStackTrace();
            }
        }*/
    entityHolders.sort(new EntityComparator());
    for (EntityHolder holder : entityHolders) {
        Class clazz = holder.clazz;
        ITakumiEntity entity = holder.entity;
        if (!entity.canRegister()) {
            break;
        }
        ResourceLocation location = new ResourceLocation(TakumiCraftCore.MODID, entity.getRegisterName());
        EntityRegistry.registerModEntity(location, clazz, location.getResourcePath(), entity.getRegisterID(), TakumiCraftCore.TakumiInstance, 64, 2, true, entity.getPrimaryColor(), entity.getSecondaryColor());
        if (entity.isCustomSpawn()) {
            try {
                entity.customSpawn();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (entity.takumiRank().getSpawnWeight() != 0 && !entity.isAnimal()) {
            Biome.REGISTRY.iterator().forEachRemaining(biome -> {
                if (!(biome instanceof BiomeOcean) && biome != Biomes.HELL && biome != Biomes.VOID && biome != Biomes.SKY) {
                    EntityRegistry.addSpawn(clazz, entity.takumiRank().getSpawnWeight(), 10, 30, EnumCreatureType.MONSTER, biome);
                }
            });
            entity.additionalSpawn();
        }
        if (FMLCommonHandler.instance().getSide().isClient()) {
            TakumiClientCore.registerEntityRender(clazz, entity);
        }
        entityList.add(entity);
        TakumiCraftCore.LOGGER.info("Registered entity on ID " + entity.getRegisterID() + " : " + location.getResourcePath() + " , " + entity.takumiRank().name() + " and " + entity.takumiType().name());
        File packFile = FMLCommonHandler.instance().findContainerFor(TakumiCraftCore.TakumiInstance).getSource();
        File oldFile = null;
        String assetS = "assets/takumicraft/advancements/slay";
        for (File f : TakumiUtils.getListFile(assetS)) {
            if (f.getName().contains("slay_.json")) {
                oldFile = f;
                break;
            }
        }
        if (oldFile != null) {
            ClassLoader loader = TakumiCraftCore.class.getClassLoader();
            URL url = loader.getResource(assetS);
            if (!Objects.equals(url.getProtocol(), "jar")) {
                String[] strings = { oldFile.getAbsolutePath().replaceAll(".json", ""), oldFile.getAbsolutePath().split("out")[0] + "src" + oldFile.getAbsolutePath().split("out")[1].replaceAll("production", "main").replaceAll("minecraft", "resources").replaceAll(".json", "") };
                for (String sPath : strings) {
                    String sResource = sPath + entity.getRegisterName() + ".json";
                    File file = new File(sResource);
                    try {
                        file.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    FileReader h_fr;
                    String buf = "";
                    String h_s;
                    try {
                        h_fr = new FileReader(oldFile);
                        BufferedReader h_br = new BufferedReader(h_fr);
                        while (true) {
                            h_s = h_br.readLine();
                            if (h_s == null) {
                                break;
                            }
                            h_s = h_s.replaceAll("minecraft:creeper", "takumicraft:" + entity.getRegisterName());
                            h_s = h_s.replaceAll("creeper_hoge", entity.getRegisterName());
                            buf = buf + h_s;
                        }
                        h_fr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        FileWriter writer = new FileWriter(file);
                        writer.write(buf);
                        writer.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    itemRegister();
    if (FMLCommonHandler.instance().getSide().isClient()) {
        renderRegister();
    }
}
Also used : java.util(java.util) TakumiClientCore(com.tntmodders.takumi.core.client.TakumiClientCore) EntityTransCreeper(com.tntmodders.takumi.entity.mobs.boss.EntityTransCreeper) URL(java.net.URL) RenderLlamaCreeperSpit(com.tntmodders.takumi.client.render.RenderLlamaCreeperSpit) RenderTakumiTNTPrimed(com.tntmodders.takumi.client.render.RenderTakumiTNTPrimed) FMLCommonHandler(net.minecraftforge.fml.common.FMLCommonHandler) RenderAttackBlock(com.tntmodders.takumi.client.render.RenderAttackBlock) ITakumiEntity(com.tntmodders.takumi.entity.ITakumiEntity) EntityShulkerBullet(net.minecraft.entity.projectile.EntityShulkerBullet) EntityArrow(net.minecraft.entity.projectile.EntityArrow) RenderSnowball(net.minecraft.client.renderer.entity.RenderSnowball) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) RenderShulkerBullet(net.minecraft.client.renderer.entity.RenderShulkerBullet) RenderingRegistry(net.minecraftforge.fml.client.registry.RenderingRegistry) com.tntmodders.takumi.entity.item(com.tntmodders.takumi.entity.item) EntityKingCreeper(com.tntmodders.takumi.entity.mobs.boss.EntityKingCreeper) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) RenderArrow(net.minecraft.client.renderer.entity.RenderArrow) EnumHelper(net.minecraftforge.common.util.EnumHelper) TakumiUtils(com.tntmodders.takumi.utils.TakumiUtils) Items(net.minecraft.init.Items) World(net.minecraft.world.World) TakumiCraftCore(com.tntmodders.takumi.TakumiCraftCore) EnumCreatureType(net.minecraft.entity.EnumCreatureType) java.io(java.io) Material(net.minecraft.block.material.Material) IMob(net.minecraft.entity.monster.IMob) BiomeOcean(net.minecraft.world.biome.BiomeOcean) com.tntmodders.takumi.entity.mobs(com.tntmodders.takumi.entity.mobs) Biomes(net.minecraft.init.Biomes) ResourceLocation(net.minecraft.util.ResourceLocation) RenderDarkVillager(com.tntmodders.takumi.client.render.RenderDarkVillager) EntityDarkVillager(com.tntmodders.takumi.entity.mobs.noncreeper.EntityDarkVillager) Biome(net.minecraft.world.biome.Biome) EntityRegistry(net.minecraftforge.fml.common.registry.EntityRegistry) ITakumiEntity(com.tntmodders.takumi.entity.ITakumiEntity) World(net.minecraft.world.World) URL(java.net.URL) BiomeOcean(net.minecraft.world.biome.BiomeOcean) ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

TakumiCraftCore (com.tntmodders.takumi.TakumiCraftCore)1 RenderAttackBlock (com.tntmodders.takumi.client.render.RenderAttackBlock)1 RenderDarkVillager (com.tntmodders.takumi.client.render.RenderDarkVillager)1 RenderLlamaCreeperSpit (com.tntmodders.takumi.client.render.RenderLlamaCreeperSpit)1 RenderTakumiTNTPrimed (com.tntmodders.takumi.client.render.RenderTakumiTNTPrimed)1 TakumiClientCore (com.tntmodders.takumi.core.client.TakumiClientCore)1 ITakumiEntity (com.tntmodders.takumi.entity.ITakumiEntity)1 com.tntmodders.takumi.entity.item (com.tntmodders.takumi.entity.item)1 com.tntmodders.takumi.entity.mobs (com.tntmodders.takumi.entity.mobs)1 EntityKingCreeper (com.tntmodders.takumi.entity.mobs.boss.EntityKingCreeper)1 EntityTransCreeper (com.tntmodders.takumi.entity.mobs.boss.EntityTransCreeper)1 EntityDarkVillager (com.tntmodders.takumi.entity.mobs.noncreeper.EntityDarkVillager)1 TakumiUtils (com.tntmodders.takumi.utils.TakumiUtils)1 java.io (java.io)1 URL (java.net.URL)1 java.util (java.util)1 Material (net.minecraft.block.material.Material)1 Minecraft (net.minecraft.client.Minecraft)1 RenderArrow (net.minecraft.client.renderer.entity.RenderArrow)1 RenderShulkerBullet (net.minecraft.client.renderer.entity.RenderShulkerBullet)1