Search in sources :

Example 21 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class AbstractCraftingBuildingModule method fullFillRecipe.

@Override
public boolean fullFillRecipe(final IRecipeStorage storage) {
    final List<IItemHandler> handlers = building.getHandlers();
    final ICitizenData data = building.getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == jobEntry).getFirstCitizen();
    if (data == null || !data.getEntity().isPresent()) {
        // we shouldn't hit this case, but just in case...
        return storage.fullfillRecipe(building.getColony().getWorld(), handlers);
    }
    final AbstractEntityCitizen worker = data.getEntity().get();
    final int primarySkill = worker.getCitizenData().getCitizenSkillHandler().getLevel(building.getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == jobEntry).getPrimarySkill());
    final int luck = (int) (((primarySkill + 1) * 2) - Math.pow((primarySkill + 1) / 10.0, 2));
    LootContext.Builder builder = (new LootContext.Builder((ServerWorld) building.getColony().getWorld()).withParameter(LootParameters.ORIGIN, worker.position()).withParameter(LootParameters.THIS_ENTITY, worker).withParameter(LootParameters.TOOL, worker.getMainHandItem()).withRandom(worker.getRandom()).withLuck((float) luck));
    return storage.fullfillRecipe(builder.create(RecipeStorage.recipeLootParameters), handlers);
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IItemHandler(net.minecraftforge.items.IItemHandler) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) SettingKey(com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) RECIPE_IMPROVED(com.minecolonies.api.util.constant.TranslationConstants.RECIPE_IMPROVED) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) CraftingType(com.minecolonies.api.crafting.registry.CraftingType) ListNBT(net.minecraft.nbt.ListNBT) ImmutableSet(com.google.common.collect.ImmutableSet) PublicWorkerCraftingProductionResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingProductionResolver) TAG_RECIPES(com.minecolonies.api.util.constant.NbtTagConstants.TAG_RECIPES) Predicate(java.util.function.Predicate) TAG_DISABLED_RECIPES(com.minecolonies.api.util.constant.NbtTagConstants.TAG_DISABLED_RECIPES) LootParameters(net.minecraft.loot.LootParameters) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) com.minecolonies.api.crafting(com.minecolonies.api.crafting) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) com.minecolonies.api.colony.buildings.modules(com.minecolonies.api.colony.buildings.modules) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) PublicWorkerCraftingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingRequestResolver) CRAFTING_REDUCEABLE(com.minecolonies.api.util.constant.TagConstants.CRAFTING_REDUCEABLE) ISettingKey(com.minecolonies.api.colony.buildings.modules.settings.ISettingKey) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) IWareHouse(com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse) ItemStack(net.minecraft.item.ItemStack) LootContext(net.minecraft.loot.LootContext) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) com.minecolonies.api.util(com.minecolonies.api.util) RECIPES(com.minecolonies.api.research.util.ResearchConstants.RECIPES) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) ModTags(com.minecolonies.api.items.ModTags) IColonyManager(com.minecolonies.api.colony.IColonyManager) Tuple(net.minecraft.util.Tuple) CrafterRecipeSetting(com.minecolonies.coremod.colony.buildings.modules.settings.CrafterRecipeSetting) Blocks(net.minecraft.block.Blocks) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) PacketBuffer(net.minecraft.network.PacketBuffer) IJob(com.minecolonies.api.colony.jobs.IJob) IItemHandler(net.minecraftforge.items.IItemHandler) LootContext(net.minecraft.loot.LootContext) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 22 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class JobDataManager method createViewFrom.

@Override
public IJobView createViewFrom(final IColonyView colony, final ICitizenDataView citizenDataView, final PacketBuffer networkBuffer) {
    final ResourceLocation jobName = new ResourceLocation(networkBuffer.readUtf(32767));
    final JobEntry entry = IJobRegistry.getInstance().getValue(jobName);
    if (entry == null) {
        Log.getLogger().error(String.format("Unknown job type '%s'.", jobName), new Exception());
        return null;
    }
    final IJobView view = entry.getJobViewProducer().get().apply(colony, citizenDataView);
    if (view != null) {
        view.deserialize(networkBuffer);
    }
    return view;
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) IJobView(com.minecolonies.api.colony.jobs.IJobView) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 23 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class ModSoundEvents method registerSounds.

/**
 * Register the {@link SoundEvent}s.
 *
 * @param registry the registry to register at.
 */
public static void registerSounds(final IForgeRegistry<SoundEvent> registry) {
    for (final JobEntry job : IJobRegistry.getInstance().getValues()) {
        if (job.getRegistryName().getNamespace().equals(Constants.MOD_ID) && !job.getRegistryName().getPath().equals("placeholder")) {
            final Map<EventType, Tuple<SoundEvent, SoundEvent>> map = new HashMap<>();
            for (final EventType soundEvents : EventType.values()) {
                final SoundEvent maleSoundEvent = ModSoundEvents.getSoundID("mob." + job.getRegistryName().getPath() + ".male." + soundEvents.name().toLowerCase(Locale.US));
                final SoundEvent femaleSoundEvent = ModSoundEvents.getSoundID("mob." + job.getRegistryName().getPath() + ".female." + soundEvents.name().toLowerCase(Locale.US));
                registry.register(maleSoundEvent);
                registry.register(femaleSoundEvent);
                map.put(soundEvents, new Tuple<>(maleSoundEvent, femaleSoundEvent));
            }
            CITIZEN_SOUND_EVENTS.put(job.getRegistryName().getPath(), map);
        }
    }
    final Map<EventType, Tuple<SoundEvent, SoundEvent>> citizenMap = new HashMap<>();
    for (final EventType soundEvents : EventType.values()) {
        final SoundEvent maleSoundEvent = ModSoundEvents.getSoundID("mob.citizen.male." + soundEvents.name().toLowerCase(Locale.US));
        final SoundEvent femaleSoundEvent = ModSoundEvents.getSoundID("mob.citizen.female." + soundEvents.name().toLowerCase(Locale.US));
        registry.register(maleSoundEvent);
        registry.register(femaleSoundEvent);
        citizenMap.put(soundEvents, new Tuple<>(maleSoundEvent, femaleSoundEvent));
    }
    CITIZEN_SOUND_EVENTS.put("citizen", citizenMap);
    final Map<EventType, Tuple<SoundEvent, SoundEvent>> childMap = new HashMap<>();
    for (final EventType soundEvents : EventType.values()) {
        final SoundEvent maleSoundEvent = ModSoundEvents.getSoundID("mob.child.male." + soundEvents.name().toLowerCase(Locale.US));
        final SoundEvent femaleSoundEvent = ModSoundEvents.getSoundID("mob.child.female." + soundEvents.name().toLowerCase(Locale.US));
        registry.register(maleSoundEvent);
        registry.register(femaleSoundEvent);
        childMap.put(soundEvents, new Tuple<>(maleSoundEvent, femaleSoundEvent));
    }
    CITIZEN_SOUND_EVENTS.put("child", childMap);
    registry.register(TavernSounds.tavernTheme);
    for (final RaiderType raiderType : RaiderType.values()) {
        final SoundEvent raiderHurt = ModSoundEvents.getSoundID("mob." + raiderType.name().toLowerCase(Locale.US) + ".hurt");
        final SoundEvent raiderDeath = ModSoundEvents.getSoundID("mob." + raiderType.name().toLowerCase(Locale.US) + ".death");
        final SoundEvent raiderSay = ModSoundEvents.getSoundID("mob." + raiderType.name().toLowerCase(Locale.US) + ".say");
        registry.register(raiderHurt);
        registry.register(raiderDeath);
        registry.register(raiderSay);
        final Map<RaiderSounds.RaiderSoundTypes, SoundEvent> sounds = new HashMap<>();
        sounds.put(RaiderSounds.RaiderSoundTypes.HURT, raiderHurt);
        sounds.put(RaiderSounds.RaiderSoundTypes.DEATH, raiderDeath);
        sounds.put(RaiderSounds.RaiderSoundTypes.SAY, raiderSay);
        RaiderSounds.raiderSounds.put(raiderType, sounds);
    }
    registry.register(RaidSounds.WARNING);
    registry.register(RaidSounds.WARNING_EARLY);
    registry.register(RaidSounds.VICTORY);
    registry.register(RaidSounds.VICTORY_EARLY);
    registry.register(RaidSounds.AMAZON_RAID);
    registry.register(RaidSounds.DESERT_RAID);
    registry.register(RaidSounds.DESERT_RAID_WARNING);
    registry.register(MercenarySounds.mercenaryAttack);
    registry.register(MercenarySounds.mercenaryCelebrate);
    registry.register(MercenarySounds.mercenaryDie);
    registry.register(MercenarySounds.mercenaryHurt);
    registry.register(MercenarySounds.mercenarySay);
    registry.register(MercenarySounds.mercenaryStep);
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) SoundEvent(net.minecraft.util.SoundEvent) HashMap(java.util.HashMap) RaiderType(com.minecolonies.api.entity.mobs.RaiderType) Tuple(com.minecolonies.api.util.Tuple)

Example 24 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class PrivateWorkerCraftingProductionResolverFactory method deserialize.

@Override
public PrivateWorkerCraftingProductionResolver deserialize(IFactoryController controller, PacketBuffer buffer) throws Throwable {
    final IToken<?> token = controller.deserialize(buffer);
    final ILocation location = controller.deserialize(buffer);
    final JobEntry entry = buffer.readRegistryId();
    return new PrivateWorkerCraftingProductionResolver(location, token, entry);
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) PrivateWorkerCraftingProductionResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PrivateWorkerCraftingProductionResolver) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation)

Example 25 with JobEntry

use of com.minecolonies.api.colony.jobs.registry.JobEntry in project minecolonies by Minecolonies.

the class PrivateWorkerCraftingRequestResolverFactory method deserialize.

@NotNull
@Override
public PrivateWorkerCraftingRequestResolver deserialize(@NotNull final IFactoryController controller, @NotNull final CompoundNBT nbt) {
    final IToken<?> token = controller.deserialize(nbt.getCompound(NBT_TOKEN));
    final ILocation location = controller.deserialize(nbt.getCompound(NBT_LOCATION));
    final JobEntry entry = IJobRegistry.getInstance().getValue(new ResourceLocation(nbt.getString(NBT_JOB)));
    return new PrivateWorkerCraftingRequestResolver(location, token, entry);
}
Also used : JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) ResourceLocation(net.minecraft.util.ResourceLocation) PrivateWorkerCraftingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.PrivateWorkerCraftingRequestResolver) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)37 ResourceLocation (net.minecraft.util.ResourceLocation)18 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)16 NotNull (org.jetbrains.annotations.NotNull)13 Nullable (org.jetbrains.annotations.Nullable)7 PublicWorkerCraftingRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingRequestResolver)6 ICitizenData (com.minecolonies.api.colony.ICitizenData)5 IColony (com.minecolonies.api.colony.IColony)5 PublicWorkerCraftingProductionResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.PublicWorkerCraftingProductionResolver)5 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)4 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)3 RaiderType (com.minecolonies.api.entity.mobs.RaiderType)3 PrivateWorkerCraftingRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.PrivateWorkerCraftingRequestResolver)3 PacketBuffer (net.minecraft.network.PacketBuffer)3 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 com.minecolonies.api.colony.buildings.modules (com.minecolonies.api.colony.buildings.modules)2 ISettingKey (com.minecolonies.api.colony.buildings.modules.settings.ISettingKey)2 BuildingEntry (com.minecolonies.api.colony.buildings.registry.BuildingEntry)2 IWareHouse (com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse)2