Jump to content

[1.16.5] New Mob Spawns Not Spawning when run via jar file


thelion1997

Recommended Posts

The new mob spawns properly when run from Intellij but not from the minecraft launcher using the jar. 

 

The strangest part is that the other two mobs I added spawn as expected in both cases. I have included the code used to register the spawns below.

 

@Mod.EventBusSubscriber(modid = GreekMyths.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class EntitySpawning {

    @SubscribeEvent(priority = EventPriority.HIGH)
    public static void addBiomeSpawns(final BiomeLoadingEvent event) {
        if(event.getCategory() == Biome.Category.OCEAN) {
            addSpawns(event, ModEntities.HIPPOCAMPUS.get(), 100, 1, 2);
        }
        addSpawns(event, ModEntities.GREEKVILLAGER.get(), 100, 1, 3);
        addSpawns(event, ModEntities.PEGASUS.get(), 100, 1, 3);
    }

    private static void addSpawns(final BiomeLoadingEvent biome, final EntityType<?> entity, final int chance, final int min, final int max) {

        if (biome.getCategory() == Biome.Category.NETHER) {

        } else if (biome.getCategory() == Biome.Category.THEEND) {

        } else {
            biome.getSpawns().withSpawner(entity.getClassification(), new MobSpawnInfo.Spawners(entity, chance, min, max));
        }
    }

}

 

Also, you are still able to summon the mob using commands. 

Any thoughts?

Link to comment
Share on other sites

I don't have a repo set up yet. It is the hippocampus entity which is not spawning. Here is the class which registers the entities if it is helpful.

 

@Mod.EventBusSubscriber(modid = GreekMyths.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEntities {

    public static final EntityClassification MOD_FREINDLY = EntityClassification.create("ModFriendly", "ModFriendly", 20, true, true, 128);
    public static final EntityClassification MOD_WATER_CREATURE = EntityClassification.create("ModWater", "ModWater", 20, true, true, 128);
    public static final EntityClassification MOD_FREINDLY_CREATURE = EntityClassification.create("ModFriendlyCreature", "ModFriendlyCreature", 10, true, true, 128);


    public static final RegistryObject<EntityType<?>> GREEKVILLAGER = register("greekvillager_entity", () -> EntityType.Builder.create(GreekVillagerEntity::new, MOD_FREINDLY).build(new ResourceLocation(GreekMyths.MOD_ID, "greekvillager_entity").toString()));

    public static final RegistryObject<EntityType<?>> HIPPOCAMPUS = register("hippocampus_entity", () -> EntityType.Builder.create(HippocampusEntity::new, MOD_WATER_CREATURE).size(1.2f, 1.3f).build(new ResourceLocation(GreekMyths.MOD_ID, "hippocampus_entity").toString()));

    public static final RegistryObject<EntityType<?>> PEGASUS = register("pegasus_entity", () -> EntityType.Builder.create(PegasusEntity::new, MOD_FREINDLY_CREATURE).size(1.36f, 1.6f).build(new ResourceLocation(GreekMyths.MOD_ID, "pegasus_entity").toString()));



//    public static final RegistryObject<Item> GREEK_VILLAGER_SPAWN_EGG = Registration.ITEMS.register("greek_villager_spawn_egg", () ->
//            new SpawnEggItem(GREEKVILLAGER.get(), 0x2f5882, 0x6f1499, new Item.Properties().group(GreekMyths.ITEM_GROUP)));

    public static void register() {
    }

    public static <T extends EntityType<?>> RegistryObject<T> register(String name, Supplier<T> entity) {
        RegistryObject<T> ret = Registration.ENTITIES.register(name, entity);
        return ret;
    }

    @SubscribeEvent
    public static void setupEntityHandler(final FMLCommonSetupEvent event) {
        event.enqueueWork(() -> {
            setupEntity((EntityType<MobEntity>)GREEKVILLAGER.get(),GreekVillagerEntity::getAttributes, GreekVillagerEntity::canSpawnOn);
            setupEntity((EntityType<MobEntity>)HIPPOCAMPUS.get(), HippocampusEntity::getAttributes, HippocampusEntity::canSpawnOn);
            setupEntity((EntityType<MobEntity>)PEGASUS.get(), PegasusEntity::getAttributes, PegasusEntity::canSpawnOn);
        });
    }

    public static <T extends MobEntity> void setupEntity(final EntityType<T> entityType, final Supplier<AttributeModifierMap.MutableAttribute> mapSupplier,
                                                          @Nullable final EntitySpawnPlacementRegistry.IPlacementPredicate<T> placementPredicate){

        GlobalEntityTypeAttributes.put((EntityType<? extends LivingEntity>) entityType, mapSupplier.get().create());

        final EntitySpawnPlacementRegistry.PlacementType placementType = entityType.getClassification() == MOD_WATER_CREATURE ? EntitySpawnPlacementRegistry.PlacementType.IN_WATER : EntitySpawnPlacementRegistry.PlacementType.ON_GROUND;
        final EntitySpawnPlacementRegistry.IPlacementPredicate<T> placement = (entity, world, reason, pos, rand) -> placementPredicate.test(entity, world, reason, pos, rand);
        EntitySpawnPlacementRegistry.register(entityType, placementType, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, placement);
    }
}

 

Link to comment
Share on other sites

For some reason the canSpawnOn function wasn't running properly from the jar. It seems to have clashed with where I set spawn placement type to inWater. 

 public static boolean canSpawnOn(final EntityType<? extends MobEntity> entity, final IWorld world,
                                     final SpawnReason reason, final BlockPos pos, final Random rand) {
        if (pos.getY() > 25) {
            Optional<RegistryKey<Biome>> optional = world.func_242406_i(pos);
            return (Objects.equals(optional, Optional.of(Biomes.OCEAN)) ||
                    Objects.equals(optional, Optional.of(Biomes.DEEP_OCEAN)) ||
                    Objects.equals(optional, Optional.of(Biomes.WARM_OCEAN)) ||
                    Objects.equals(optional, Optional.of(Biomes.DEEP_WARM_OCEAN)) ||
                    Objects.equals(optional, Optional.of(Biomes.LUKEWARM_OCEAN)) ||
                    Objects.equals(optional, Optional.of(Biomes.DEEP_LUKEWARM_OCEAN)) ||
                    Objects.equals(optional, Optional.of(Biomes.COLD_OCEAN)) ||
                    Objects.equals(optional, Optional.of(Biomes.DEEP_COLD_OCEAN)) ||
                    Objects.equals(optional, Optional.of(Biomes.DEEP_OCEAN))) && world.getFluidState(pos).isTagged(FluidTags.WATER);
        } else {
            return false;
        }
    }

 

I got this code mostly from the dolphinEntity class but modified it slightly. I tried changing this and ended up with this. I also changed the name of the function as I think there may have been an inheritance issue. This is what I ended up with.

 

public static boolean canHippocampusSpawnOn(final EntityType<? extends MobEntity> entity, final IWorld world,
                                     final SpawnReason reason, final BlockPos pos, final Random rand) {
        if (pos.getY() <= 25 || pos.getY() >= world.getSeaLevel()) {
            return false;
        }

        RegistryKey<Biome> biome = world.func_242406_i(pos).orElse(Biomes.PLAINS);
        return (BiomeDictionary.hasType(biome, BiomeDictionary.Type.OCEAN)) && world.getFluidState(pos).isTagged(FluidTags.WATER);
    }

 

This seems to have fixed the issue. Thanks again!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.