Search in sources :

Example 1 with EntityRegistration

use of net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration in project MorePlanets by SteveKunG.

the class ClientProxyMP method handleSpaceFishHookSpawning.

private static void handleSpaceFishHookSpawning() {
    EntityRegistration entityRegistration = EntityRegistry.instance().lookupModSpawn(EntitySpaceFishHook.class, false);
    Function<EntitySpawnMessage, Entity> handler = input -> {
        int entityID = 0;
        double posX = 0;
        double posY = 0;
        double posZ = 0;
        WorldClient world = FMLClientHandler.instance().getWorldClient();
        try {
            entityID = ReflectionHelper.findField(EntitySpawnMessage.class, "throwerId").getInt(input);
            posX = ReflectionHelper.findField(EntitySpawnMessage.class, "rawX").getDouble(input);
            posY = ReflectionHelper.findField(EntitySpawnMessage.class, "rawY").getDouble(input);
            posZ = ReflectionHelper.findField(EntitySpawnMessage.class, "rawZ").getDouble(input);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Entity angler = world.getEntityByID(entityID);
        if (angler instanceof EntityPlayer) {
            Entity entity = new EntitySpaceFishHook(world, (EntityPlayer) angler, posX, posY, posZ);
            return entity;
        }
        return null;
    };
    entityRegistration.setCustomSpawning(handler, false);
}
Also used : ParticleAlienMinerSpark(stevekung.mods.moreplanets.module.planets.diona.client.particle.ParticleAlienMinerSpark) BiomeColorHelper(net.minecraft.world.biome.BiomeColorHelper) ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) Item(net.minecraft.item.Item) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) ClientRegisterHelper(stevekung.mods.moreplanets.util.helper.ClientRegisterHelper) ColorHelper(stevekung.mods.moreplanets.util.helper.ColorHelper) ItemRendererTieredRocket(stevekung.mods.moreplanets.util.client.renderer.item.ItemRendererTieredRocket) Side(net.minecraftforge.fml.relauncher.Side) ClientEventHandler(stevekung.mods.moreplanets.core.event.ClientEventHandler) ParticleDarkPortal(stevekung.mods.moreplanets.module.planets.diona.client.particle.ParticleDarkPortal) ParticleFallingDustMP(stevekung.mods.moreplanets.util.client.particle.ParticleFallingDustMP) MPSchematics(stevekung.mods.moreplanets.init.MPSchematics) ParticleInfectedSpore(stevekung.mods.moreplanets.module.planets.nibiru.client.particle.ParticleInfectedSpore) ParticleKoentusMeteor(stevekung.mods.moreplanets.module.moons.koentus.client.particle.ParticleKoentusMeteor) Function(com.google.common.base.Function) ModelLoaderRegistry(net.minecraftforge.client.model.ModelLoaderRegistry) EntitySpawnMessage(net.minecraftforge.fml.common.network.internal.FMLMessage.EntitySpawnMessage) MPItems(stevekung.mods.moreplanets.init.MPItems) ParticleAlienBerry(stevekung.mods.moreplanets.module.planets.nibiru.client.particle.ParticleAlienBerry) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) TileEntityItemStackRenderer(net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ParticleInfectedGuardianAppearance(stevekung.mods.moreplanets.module.planets.nibiru.client.particle.ParticleInfectedGuardianAppearance) EnumParticleTypes(net.minecraft.util.EnumParticleTypes) ParticleLiquidDrip(stevekung.mods.moreplanets.util.client.particle.ParticleLiquidDrip) CompatibilityManagerMP(stevekung.mods.moreplanets.util.CompatibilityManagerMP) ParticleBreakingMC(stevekung.mods.moreplanets.util.client.particle.ParticleBreakingMC) ParticleLavaMC(stevekung.mods.moreplanets.util.client.particle.ParticleLavaMC) EnumParticleTypesMP(stevekung.mods.moreplanets.util.EnumParticleTypesMP) ReflectionHelper(net.minecraftforge.fml.relauncher.ReflectionHelper) WorldClient(net.minecraft.client.multiplayer.WorldClient) IMorePlanetsBoss(stevekung.mods.moreplanets.util.IMorePlanetsBoss) stevekung.mods.moreplanets.client.renderer(stevekung.mods.moreplanets.client.renderer) DionaBlocks(stevekung.mods.moreplanets.module.planets.diona.blocks.DionaBlocks) ImmutableList(com.google.common.collect.ImmutableList) Minecraft(net.minecraft.client.Minecraft) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Entity(net.minecraft.entity.Entity) FronosBlocks(stevekung.mods.moreplanets.module.planets.fronos.blocks.FronosBlocks) CommonRegisterHelper(stevekung.mods.moreplanets.util.helper.CommonRegisterHelper) NibiruBlocks(stevekung.mods.moreplanets.module.planets.nibiru.blocks.NibiruBlocks) EntitySpaceFishHook(stevekung.mods.moreplanets.entity.projectile.EntitySpaceFishHook) BlockColors(net.minecraft.client.renderer.color.BlockColors) ParticleCrystallizeFlame(stevekung.mods.moreplanets.module.planets.diona.client.particle.ParticleCrystallizeFlame) ColorizerGrass(net.minecraft.world.ColorizerGrass) EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) Particle(net.minecraft.client.particle.Particle) ItemBlock(net.minecraft.item.ItemBlock) EntityRegistry(net.minecraftforge.fml.common.registry.EntityRegistry) Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntitySpaceFishHook(stevekung.mods.moreplanets.entity.projectile.EntitySpaceFishHook) EntitySpawnMessage(net.minecraftforge.fml.common.network.internal.FMLMessage.EntitySpawnMessage) WorldClient(net.minecraft.client.multiplayer.WorldClient) EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

Example 2 with EntityRegistration

use of net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration in project Random-Things by lumien231.

the class EntityUtil method getEntityName.

public static String getEntityName(Entity entity) {
    String entityName = null;
    entityName = EntityList.getEntityString(entity);
    if (entityName == null) {
        EntityRegistration registration = EntityRegistry.instance().lookupModSpawn(entity.getClass(), false);
        if (registration != null) {
            entityName = registration.getEntityName();
        }
    }
    return entityName;
}
Also used : EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

Example 3 with EntityRegistration

use of net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration in project BiomesOPlenty by Glitchfiend.

the class ModEntities method createEntityByID.

public static Entity createEntityByID(int bopEntityId, World worldIn) {
    Entity entity = null;
    ModContainer mc = FMLCommonHandler.instance().findContainerFor(BiomesOPlenty.instance);
    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, bopEntityId);
    if (er != null) {
        Class<? extends Entity> clazz = er.getEntityClass();
        try {
            if (clazz != null) {
                entity = clazz.getConstructor(new Class[] { World.class }).newInstance(new Object[] { worldIn });
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
    if (entity == null) {
        BiomesOPlenty.logger.warn("Skipping BOP Entity with id " + bopEntityId);
    }
    return entity;
}
Also used : Entity(net.minecraft.entity.Entity) ModContainer(net.minecraftforge.fml.common.ModContainer) EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

Example 4 with EntityRegistration

use of net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration in project MinecraftForge by MinecraftForge.

the class EntitySpawnHandler method spawnEntity.

private void spawnEntity(FMLMessage.EntitySpawnMessage spawnMsg) {
    ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
    if (er == null) {
        throw new RuntimeException("Could not spawn mod entity ModID: " + spawnMsg.modId + " EntityID: " + spawnMsg.modEntityTypeId + " at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ") Please contact mod author or server admin.");
    }
    WorldClient wc = FMLClientHandler.instance().getWorldClient();
    Class<? extends Entity> cls = er.getEntityClass();
    try {
        Entity entity;
        if (er.hasCustomSpawning()) {
            entity = er.doCustomSpawning(spawnMsg);
        } else {
            entity = cls.getConstructor(World.class).newInstance(wc);
            int offset = spawnMsg.entityId - entity.getEntityId();
            entity.setEntityId(spawnMsg.entityId);
            entity.setUniqueId(spawnMsg.entityUUID);
            entity.setLocationAndAngles(spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
            if (entity instanceof EntityLiving) {
                ((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
            }
            Entity[] parts = entity.getParts();
            if (parts != null) {
                for (int j = 0; j < parts.length; j++) {
                    parts[j].setEntityId(parts[j].getEntityId() + offset);
                }
            }
        }
        EntityTracker.updateServerPosition(entity, spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ);
        EntityPlayerSP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
        if (entity instanceof IThrowableEntity) {
            Entity thrower = clientPlayer.getEntityId() == spawnMsg.throwerId ? clientPlayer : wc.getEntityByID(spawnMsg.throwerId);
            ((IThrowableEntity) entity).setThrower(thrower);
        }
        if (spawnMsg.dataWatcherList != null) {
            entity.getDataManager().setEntryValues(spawnMsg.dataWatcherList);
        }
        if (spawnMsg.throwerId > 0) {
            entity.setVelocity(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
        }
        if (entity instanceof IEntityAdditionalSpawnData) {
            ((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
        }
        wc.addEntityToWorld(spawnMsg.entityId, entity);
    } catch (Exception e) {
        FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ")");
        throw Throwables.propagate(e);
    }
}
Also used : IEntityAdditionalSpawnData(net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData) Entity(net.minecraft.entity.Entity) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) ModContainer(net.minecraftforge.fml.common.ModContainer) EntityLiving(net.minecraft.entity.EntityLiving) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) WorldClient(net.minecraft.client.multiplayer.WorldClient) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

Example 5 with EntityRegistration

use of net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration in project Random-Things by lumien231.

the class EntityUtil method getEntityName.

public static String getEntityName(Class entityClass) {
    String entityName = "NO_NAME";
    entityName = EntityRegistry.getEntry(entityClass).getName();
    if (entityName == null) {
        EntityRegistration registration = EntityRegistry.instance().lookupModSpawn(entityClass, false);
        if (registration != null) {
            entityName = registration.getEntityName();
        }
    }
    return entityName;
}
Also used : EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

Aggregations

EntityRegistration (net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)6 Entity (net.minecraft.entity.Entity)4 WorldClient (net.minecraft.client.multiplayer.WorldClient)3 Function (com.google.common.base.Function)2 Minecraft (net.minecraft.client.Minecraft)2 BlockColors (net.minecraft.client.renderer.color.BlockColors)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Item (net.minecraft.item.Item)2 ItemBlock (net.minecraft.item.ItemBlock)2 BiomeColorHelper (net.minecraft.world.biome.BiomeColorHelper)2 ModelBakeEvent (net.minecraftforge.client.event.ModelBakeEvent)2 ModelRegistryEvent (net.minecraftforge.client.event.ModelRegistryEvent)2 TextureStitchEvent (net.minecraftforge.client.event.TextureStitchEvent)2 ModelLoaderRegistry (net.minecraftforge.client.model.ModelLoaderRegistry)2 FMLClientHandler (net.minecraftforge.fml.client.FMLClientHandler)2 ModContainer (net.minecraftforge.fml.common.ModContainer)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EntityRegistry (net.minecraftforge.fml.common.registry.EntityRegistry)2 Side (net.minecraftforge.fml.relauncher.Side)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2