use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.
the class EventHandler method onEnteringChunkEntity.
/**
* Event called when the player enters a new chunk.
*
* @param event the event.
*/
@SubscribeEvent
public static void onEnteringChunkEntity(@NotNull final EntityEvent.EnteringChunk event) {
if (MineColonies.getConfig().getServer().pvp_mode.get() && event.getEntity() instanceof EntityCitizen) {
if (event.getEntity().level == null || !WorldUtil.isEntityChunkLoaded(event.getEntity().level, new ChunkPos(event.getNewChunkX(), event.getNewChunkZ())) || !WorldUtil.isEntityChunkLoaded(event.getEntity().level, new ChunkPos(event.getOldChunkX(), event.getOldChunkZ()))) {
return;
}
final EntityCitizen entityCitizen = (EntityCitizen) event.getEntity();
if (entityCitizen.getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard) {
final World world = entityCitizen.getCommandSenderWorld();
final Chunk chunk = world.getChunk(event.getNewChunkX(), event.getNewChunkZ());
final IColonyTagCapability chunkCapability = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
if (chunkCapability != null && chunkCapability.getOwningColony() != 0 && entityCitizen.getCitizenColonyHandler().getColonyId() != chunkCapability.getOwningColony()) {
final IColony colony = IColonyManager.getInstance().getColonyByWorld(chunkCapability.getOwningColony(), entityCitizen.level);
if (colony != null) {
colony.addGuardToAttackers(entityCitizen, ((IGuardBuilding) entityCitizen.getCitizenColonyHandler().getWorkBuilding()).getPlayerToFollowOrRally());
}
}
}
}
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.
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 CitizenManager method spawnCitizenOnPosition.
@NotNull
private ICitizenData spawnCitizenOnPosition(@Nullable final ICitizenData data, @NotNull final World world, final boolean force, final BlockPos spawnPoint) {
ICitizenData citizenData = data;
if (citizenData == null) {
citizenData = createAndRegisterCivilianData();
if (getMaxCitizens() >= getCurrentCitizenCount() && !force) {
if (maxCitizensFromResearch() <= getCurrentCitizenCount()) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "block.blockhuttownhall.messagemaxsize.research", colony.getName());
} else {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "block.blockhuttownhall.messagemaxsize.config", colony.getName());
}
}
colony.getEventDescriptionManager().addEventDescription(new CitizenSpawnedEvent(spawnPoint, citizenData.getName()));
}
final EntityCitizen entity = (EntityCitizen) ModEntities.CITIZEN.create(world);
entity.setPos(spawnPoint.getX() + HALF_BLOCK, spawnPoint.getY() + SLIGHTLY_UP, spawnPoint.getZ() + HALF_BLOCK);
world.addFreshEntity(entity);
entity.getCitizenColonyHandler().registerWithColony(citizenData.getColony().getID(), citizenData.getId());
colony.getProgressManager().progressCitizenSpawn(citizens.size(), citizens.values().stream().filter(tempDate -> tempDate.getJob() != null).collect(Collectors.toList()).size());
markDirty();
return citizenData;
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by Minecolonies.
the class EventHandler method onEnteringChunkEntity.
/**
* Event called when the player enters a new chunk.
*
* @param event the event.
*/
@SubscribeEvent
public static void onEnteringChunkEntity(@NotNull final EntityEvent.EnteringChunk event) {
if (MineColonies.getConfig().getServer().pvp_mode.get() && event.getEntity() instanceof EntityCitizen) {
if (event.getEntity().level == null || !WorldUtil.isEntityChunkLoaded(event.getEntity().level, new ChunkPos(event.getNewChunkX(), event.getNewChunkZ())) || !WorldUtil.isEntityChunkLoaded(event.getEntity().level, new ChunkPos(event.getOldChunkX(), event.getOldChunkZ()))) {
return;
}
final EntityCitizen entityCitizen = (EntityCitizen) event.getEntity();
if (entityCitizen.getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard) {
final World world = entityCitizen.getCommandSenderWorld();
final Chunk chunk = world.getChunk(event.getNewChunkX(), event.getNewChunkZ());
final IColonyTagCapability chunkCapability = chunk.getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
if (chunkCapability != null && chunkCapability.getOwningColony() != 0 && entityCitizen.getCitizenColonyHandler().getColonyId() != chunkCapability.getOwningColony()) {
final IColony colony = IColonyManager.getInstance().getColonyByWorld(chunkCapability.getOwningColony(), entityCitizen.level);
if (colony != null) {
colony.addGuardToAttackers(entityCitizen, ((IGuardBuilding) entityCitizen.getCitizenColonyHandler().getWorkBuilding()).getPlayerToFollowOrRally());
}
}
}
}
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by Minecolonies.
the class JobBasedRecipeCategory method createCitizenWithJob.
@NotNull
private static EntityCitizen createCitizenWithJob(@NotNull final IJob<?> job) {
final EntityCitizen citizen = new EntityCitizen(ModEntities.CITIZEN, Minecraft.getInstance().level);
citizen.setFemale(citizen.getRandom().nextBoolean());
citizen.setTextureId(citizen.getRandom().nextInt(255));
citizen.getEntityData().set(EntityCitizen.DATA_TEXTURE_SUFFIX, CitizenData.SUFFIXES.get(citizen.getRandom().nextInt(CitizenData.SUFFIXES.size())));
citizen.setModelId(job.getModel());
return citizen;
}
Aggregations