use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by Minecolonies.
the class RenderFishHook method render.
@Override
public void render(final Entity entityIn, final float entityYaw, final float partialTicks, @NotNull final MatrixStack matrixStackIn, @NotNull final IRenderTypeBuffer bufferIn, final int packedLightIn) {
NewBobberEntity bobber = (NewBobberEntity) entityIn.getEntity();
if (bobber != null && bobber.getAngler() != null) {
final EntityCitizen citizen = bobber.getAngler();
matrixStackIn.pushPose();
matrixStackIn.pushPose();
matrixStackIn.scale(0.5F, 0.5F, 0.5F);
matrixStackIn.mulPose(this.entityRenderDispatcher.cameraOrientation());
matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(180.0F));
final MatrixStack.Entry matrixstack$entry = matrixStackIn.last();
final Matrix4f matrix4f = matrixstack$entry.pose();
final Matrix3f matrix3f = matrixstack$entry.normal();
final IVertexBuilder ivertexbuilder = bufferIn.getBuffer(RENDER_TYPE);
vertex(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 0.0F, 0, 0, 1);
vertex(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 1.0F, 0, 1, 1);
vertex(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 1.0F, 1, 1, 0);
vertex(ivertexbuilder, matrix4f, matrix3f, packedLightIn, 0.0F, 1, 0, 0);
matrixStackIn.popPose();
int i = citizen.getMainArm() == HandSide.RIGHT ? 1 : -1;
final ItemStack itemstack = citizen.getMainHandItem();
if (!(itemstack.getItem() instanceof net.minecraft.item.FishingRodItem)) {
i = -i;
}
final float f2 = MathHelper.lerp(partialTicks, citizen.yBodyRotO, citizen.yBodyRot) * ((float) Math.PI / 180F);
final double d0 = MathHelper.sin(f2);
final double d1 = MathHelper.cos(f2);
final double d2 = (double) i * 0.35D;
double d4 = MathHelper.lerp(partialTicks, citizen.xo, citizen.getX()) - d1 * d2 - d0 * 0.8D;
double d5 = citizen.yo + (double) citizen.getEyeHeight() + (citizen.getY() - citizen.yo) * (double) partialTicks - 0.45D;
double d6 = MathHelper.lerp(partialTicks, citizen.zo, citizen.getZ()) - d0 * d2 + d1 * 0.8D;
float f3 = citizen.isCrouching() ? -0.1875F : 0.0F;
double d9 = MathHelper.lerp(partialTicks, entityIn.xo, entityIn.getX());
double d10 = MathHelper.lerp(partialTicks, entityIn.yo, entityIn.getY()) + 0.25D;
double d8 = MathHelper.lerp(partialTicks, entityIn.zo, entityIn.getZ());
float f4 = (float) (d4 - d9);
float f5 = (float) (d5 - d10) + f3;
float f6 = (float) (d6 - d8);
final IVertexBuilder ivertexbuilder1 = bufferIn.getBuffer(RenderType.lines());
final Matrix4f matrix4f1 = matrixStackIn.last().pose();
for (int k = 0; k < 16; ++k) {
stringVertex(f4, f5, f6, ivertexbuilder1, matrix4f1, fraction(k, 16));
stringVertex(f4, f5, f6, ivertexbuilder1, matrix4f1, fraction(k + 1, 16));
}
matrixStackIn.popPose();
super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
}
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by Minecolonies.
the class CommandCitizenTriggerWalkTo method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
return 0;
}
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
final ILocationArgument targetLocation = Vec3Argument.getCoordinates(context, POS_ARG);
final BlockPos targetPos = targetLocation.getBlockPos(context.getSource());
if (context.getSource().getLevel() == entityCitizen.level) {
if (entityCitizen instanceof EntityCitizen && entityCitizen.getCitizenJobHandler().getColonyJob() != null) {
final AbstractEntityAIBasic basic = ((AbstractEntityAIBasic) entityCitizen.getCitizenJobHandler().getColonyJob().getWorkerAI());
basic.setWalkTo(targetPos);
basic.registerTarget(new AIOneTimeEventTarget(AIWorkerState.WALK_TO));
} else {
entityCitizen.getNavigation().moveTo(targetPos.getX(), targetPos.getY(), targetPos.getZ(), 1f);
}
}
return 1;
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by Minecolonies.
the class EntityMercenary method doPush.
@Override
protected void doPush(final Entity entityIn) {
if (slapTimer == 0 && entityIn instanceof PlayerEntity) {
slapTimer = SLAP_INTERVAL;
entityIn.hurt(new EntityDamageSource("slap", this), 1.0f);
this.swing(Hand.OFF_HAND);
}
if (slapTimer == 0 && entityIn instanceof EntityCitizen && colony != null && ((EntityCitizen) entityIn).isActive()) {
slapTimer = SLAP_INTERVAL;
final IItemHandler handler = ((EntityCitizen) entityIn).getItemHandlerCitizen();
final ItemStack stack = handler.extractItem(rand.nextInt(handler.getSlots()), 5, false);
if (!ItemStackUtils.isEmpty(stack)) {
this.swing(Hand.OFF_HAND);
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "com.minecolonies.coremod.mercenary.mercenaryStealCitizen", entityIn.getName().getString(), stack.getHoverName().getString());
}
}
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by Minecolonies.
the class EntityAIWorkHealer method freeCure.
/**
* Do free cure magic.
*
* @return the next state to go to.
*/
private IAIState freeCure() {
if (currentPatient == null) {
return DECIDE;
}
final ICitizenData data = getOwnBuilding().getColony().getCitizenManager().getCivilian(currentPatient.getId());
if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
currentPatient = null;
return DECIDE;
}
final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
if (walkToBlock(citizen.blockPosition())) {
progressTicks = 0;
return FREE_CURE;
}
progressTicks++;
if (progressTicks < MAX_PROGRESS_TICKS) {
Network.getNetwork().sendToTrackingEntity(new StreamParticleEffectMessage(worker.position().add(0, 2, 0), citizen.position(), ParticleTypes.HEART, progressTicks % MAX_PROGRESS_TICKS, MAX_PROGRESS_TICKS), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 2, 0), ParticleTypes.HEART, progressTicks), worker);
return getState();
}
progressTicks = 0;
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
citizen.getCitizenDiseaseHandler().cure();
currentPatient.setState(Patient.PatientState.TREATED);
currentPatient = null;
return DECIDE;
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by Minecolonies.
the class EntityAIWorkHealer method requestCure.
/**
* Request the cure for a given patient.
*
* @return the next state to go to.
*/
private IAIState requestCure() {
if (currentPatient == null) {
return DECIDE;
}
final ICitizenData data = getOwnBuilding().getColony().getCitizenManager().getCivilian(currentPatient.getId());
if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
currentPatient = null;
return DECIDE;
}
final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
if (walkToBlock(citizen.blockPosition())) {
return REQUEST_CURE;
}
final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
if (diseaseName.isEmpty()) {
currentPatient.setState(Patient.PatientState.REQUESTED);
currentPatient = null;
return DECIDE;
}
final ImmutableList<IRequest<? extends Stack>> list = getOwnBuilding().getOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(Stack.class));
final ImmutableList<IRequest<? extends Stack>> completed = getOwnBuilding().getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class));
for (final ItemStack cure : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName).getCure()) {
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), cure::sameItem) && !InventoryUtils.hasItemInItemHandler(getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), cure::sameItem)) {
boolean hasRequest = false;
for (final IRequest<? extends Stack> request : list) {
if (request.getRequest().getStack().sameItem(cure)) {
hasRequest = true;
break;
}
}
for (final IRequest<? extends Stack> request : completed) {
if (request.getRequest().getStack().sameItem(cure)) {
hasRequest = true;
break;
}
}
if (!hasRequest) {
worker.getCitizenData().createRequestAsync(new Stack(cure, REQUEST_COUNT, 1));
}
}
}
currentPatient.setState(Patient.PatientState.REQUESTED);
currentPatient = null;
return DECIDE;
}
Aggregations