use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class AdjustSkillCitizenMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony) {
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(citizenId);
if (citizenData == null) {
Log.getLogger().warn("AdjustSkillCitizenMessage citizenData is null");
return;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
Log.getLogger().warn("AdjustSkillCitizenMessage entity citizen is null");
return;
}
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
final boolean isCreative = player.isCreative();
if (!isCreative) {
Log.getLogger().warn("AdjustSkillCitizenMessage player must be creative.");
return;
}
citizenData.getCitizenSkillHandler().incrementLevel(skill, quantity);
citizenData.markDirty();
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class RecallSingleCitizenMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(citizenId);
citizenData.setLastPosition(building.getPosition());
Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
citizenData.updateEntityIfNecessary();
optionalEntityCitizen = citizenData.getEntity();
}
if (optionalEntityCitizen.isPresent() && optionalEntityCitizen.get().getTicksExisted() == 0) {
citizenData.updateEntityIfNecessary();
}
final BlockPos loc = building.getID();
if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), colony.getWorld(), loc)) {
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerhuts.recallFail");
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen 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());
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class CitizenData method applyResearchEffects.
@Override
public void applyResearchEffects() {
if (getEntity().isPresent()) {
final AbstractEntityCitizen citizen = getEntity().get();
// Applies entity related research effects.
citizen.getNavigation().getPathingOptions().setCanUseRails(((EntityCitizen) citizen).canPathOnRails());
citizen.getNavigation().getPathingOptions().setCanClimbVines(((EntityCitizen) citizen).canClimbVines());
final AttributeModifier speedModifier = new AttributeModifier(RESEARCH_BONUS_MULTIPLIER, colony.getResearchManager().getResearchEffects().getEffectStrength(WALKING), AttributeModifier.Operation.MULTIPLY_TOTAL);
AttributeModifierUtils.addModifier(citizen, speedModifier, Attributes.MOVEMENT_SPEED);
final AttributeModifier healthModLevel = new AttributeModifier(HEALTH_BOOST.toString(), colony.getResearchManager().getResearchEffects().getEffectStrength(HEALTH_BOOST), AttributeModifier.Operation.ADDITION);
AttributeModifierUtils.addHealthModifier(citizen, healthModLevel);
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class RenderBipedCitizen method render.
@Override
public void render(@NotNull final AbstractEntityCitizen citizen, final float limbSwing, final float partialTicks, @NotNull final MatrixStack matrixStack, @NotNull final IRenderTypeBuffer renderTypeBuffer, final int light) {
setupMainModelFrom(citizen);
final CitizenModel<AbstractEntityCitizen> citizenModel = model;
final ItemStack mainHandStack = citizen.getMainHandItem();
final ItemStack offHandStack = citizen.getOffhandItem();
final BipedModel.ArmPose armPoseMainHand = getArmPoseFrom(citizen, mainHandStack);
final BipedModel.ArmPose armPoseOffHand = getArmPoseFrom(citizen, offHandStack);
updateArmPose(citizen, citizenModel, armPoseMainHand, armPoseOffHand);
if (isItGhostTime) {
RenderSystem.enableBlend();
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 0.3F);
super.render(citizen, limbSwing, partialTicks, matrixStack, renderTypeBuffer, light);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1F);
RenderSystem.disableBlend();
} else {
super.render(citizen, limbSwing, partialTicks, matrixStack, renderTypeBuffer, light);
}
}
Aggregations