use of com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler in project minecolonies by Minecolonies.
the class CitizenData method triggerInteraction.
@Override
public void triggerInteraction(@NotNull final IInteractionResponseHandler handler) {
if (!this.citizenChatOptions.containsKey(handler.getInquiry())) {
this.citizenChatOptions.put(handler.getInquiry(), handler);
for (final IInteractionResponseHandler childHandler : handler.genChildInteractions()) {
this.citizenChatOptions.put(childHandler.getInquiry(), (ServerCitizenInteraction) childHandler);
}
markDirty();
}
}
use of com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler in project minecolonies by Minecolonies.
the class InteractionResponseHandlerManager method createFrom.
@Nullable
@Override
public IInteractionResponseHandler createFrom(@NotNull final ICitizen citizen, @NotNull final CompoundNBT compound) {
final ResourceLocation handlerType = compound.getAllKeys().contains(NbtTagConstants.TAG_HANDLER_TYPE) ? new ResourceLocation(Constants.MOD_ID, compound.getString(NbtTagConstants.TAG_HANDLER_TYPE)) : ModInteractionResponseHandlers.STANDARD;
final IInteractionResponseHandler handler = IInteractionResponseHandlerRegistry.getInstance().getValue(handlerType).getProducer().apply(citizen);
if (handler != null) {
try {
handler.deserializeNBT(compound);
} catch (final RuntimeException ex) {
Log.getLogger().error(String.format("An Interaction %s has thrown an exception during loading, its state cannot be restored. Report this to the mod author", handlerType), ex);
return null;
}
} else {
Log.getLogger().warn(String.format("Unknown Interaction type '%s' or missing constructor of proper format.", handlerType));
}
return handler;
}
use of com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler in project minecolonies by ldtteam.
the class CitizenData method triggerInteraction.
@Override
public void triggerInteraction(@NotNull final IInteractionResponseHandler handler) {
if (!this.citizenChatOptions.containsKey(handler.getInquiry())) {
this.citizenChatOptions.put(handler.getInquiry(), handler);
for (final IInteractionResponseHandler childHandler : handler.genChildInteractions()) {
this.citizenChatOptions.put(childHandler.getInquiry(), (ServerCitizenInteraction) childHandler);
}
markDirty();
}
}
use of com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler in project minecolonies by ldtteam.
the class CitizenData method serializeViewNetworkData.
@Override
public void serializeViewNetworkData(@NotNull final PacketBuffer buf) {
buf.writeUtf(name);
buf.writeBoolean(female);
buf.writeInt(getEntity().map(AbstractEntityCitizen::getId).orElse(-1));
buf.writeBoolean(paused);
buf.writeBoolean(isChild);
buf.writeBoolean(homeBuilding != null);
if (homeBuilding != null) {
buf.writeBlockPos(homeBuilding.getID());
}
buf.writeBoolean(workBuilding != null);
if (workBuilding != null) {
buf.writeBlockPos(workBuilding.getID());
}
// If the entity is not present we assumes standard values.
buf.writeFloat(getEntity().map(AbstractEntityCitizen::getHealth).orElse(MAX_HEALTH));
buf.writeFloat(getEntity().map(AbstractEntityCitizen::getMaxHealth).orElse(MAX_HEALTH));
buf.writeDouble(getSaturation());
buf.writeDouble(citizenHappinessHandler.getHappiness(getColony()));
buf.writeNbt(citizenSkillHandler.write());
buf.writeUtf((job != null) ? job.getJobRegistryEntry().getTranslationKey() : "");
buf.writeInt(colony.getID());
final CompoundNBT compound = new CompoundNBT();
compound.put("inventory", inventory.write(new ListNBT()));
buf.writeNbt(compound);
buf.writeBlockPos(lastPosition);
if (colony.getWorld() != null) {
final List<IInteractionResponseHandler> subInteractions = citizenChatOptions.values().stream().filter(e -> e.isVisible(colony.getWorld())).collect(Collectors.toList());
buf.writeInt(subInteractions.size());
for (final IInteractionResponseHandler interactionHandler : subInteractions) {
buf.writeNbt(interactionHandler.serializeNBT());
}
} else {
buf.writeInt(0);
}
final CompoundNBT happinessCompound = new CompoundNBT();
citizenHappinessHandler.write(happinessCompound);
buf.writeNbt(happinessCompound);
buf.writeInt(status != null ? status.getId() : -1);
buf.writeBoolean(job != null);
if (job != null) {
job.serializeToView(buf);
}
if (colony.getCitizenManager().getCivilian(partner) == null) {
partner = 0;
}
siblings.removeIf(s -> colony.getCitizenManager().getCivilian(s) == null);
children.removeIf(c -> colony.getCitizenManager().getCivilian(c) == null);
buf.writeInt(partner);
buf.writeInt(siblings.size());
for (int sibling : siblings) {
buf.writeInt(sibling);
}
buf.writeInt(children.size());
for (int child : children) {
buf.writeInt(child);
}
buf.writeUtf(parents.getA());
buf.writeUtf(parents.getB());
}
Aggregations