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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations