Search in sources :

Example 11 with EntityCitizen

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());
                }
            }
        }
    }
}
Also used : AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) ChunkPos(net.minecraft.util.math.ChunkPos) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) World(net.minecraft.world.World) ClientWorld(net.minecraft.client.world.ClientWorld) ServerWorld(net.minecraft.world.server.ServerWorld) Chunk(net.minecraft.world.chunk.Chunk) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 12 with EntityCitizen

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);
    }
}
Also used : MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) Matrix4f(net.minecraft.util.math.vector.Matrix4f) NewBobberEntity(com.minecolonies.coremod.entity.NewBobberEntity) Matrix3f(net.minecraft.util.math.vector.Matrix3f) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) ItemStack(net.minecraft.item.ItemStack)

Example 13 with EntityCitizen

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;
}
Also used : java.util(java.util) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) ALL_CITIZENS_ARE_SLEEPING(com.minecolonies.api.util.constant.TranslationConstants.ALL_CITIZENS_ARE_SLEEPING) BedHandlingModule(com.minecolonies.coremod.colony.buildings.modules.BedHandlingModule) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) Function(java.util.function.Function) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) CitizenData(com.minecolonies.coremod.colony.CitizenData) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) Network(com.minecolonies.coremod.Network) ICitizenDataManager(com.minecolonies.api.colony.ICitizenDataManager) EntityUtils(com.minecolonies.api.util.EntityUtils) ICitizenManager(com.minecolonies.api.colony.managers.interfaces.ICitizenManager) CitizenSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent) Constants(com.minecolonies.api.util.constant.Constants) ColonyViewRemoveCitizenMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveCitizenMessage) ListNBT(net.minecraft.nbt.ListNBT) Entity(net.minecraft.entity.Entity) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) CITIZEN_CAP(com.minecolonies.api.research.util.ResearchConstants.CITIZEN_CAP) Colony(com.minecolonies.coremod.colony.Colony) WorkAtHomeBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkAtHomeBuildingModule) World(net.minecraft.world.World) ModEntities(com.minecolonies.api.entity.ModEntities) JobUndertaker(com.minecolonies.coremod.colony.jobs.JobUndertaker) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) AbstractCivilianEntity(com.minecolonies.api.entity.citizen.AbstractCivilianEntity) ICivilianData(com.minecolonies.api.colony.ICivilianData) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) MineColonies(com.minecolonies.coremod.MineColonies) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NBTUtils(com.minecolonies.api.util.NBTUtils) IColony(com.minecolonies.api.colony.IColony) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) ColonyViewCitizenViewMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewCitizenViewMessage) TAG_CITIZENS(com.minecolonies.api.util.constant.NbtTagConstants.TAG_CITIZENS) COM_MINECOLONIES_COREMOD_MOURN(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_MOURN) TAG_ID(com.minecolonies.api.util.constant.NbtTagConstants.TAG_ID) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CitizenSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenSpawnedEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with EntityCitizen

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());
                }
            }
        }
    }
}
Also used : AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) ChunkPos(net.minecraft.util.math.ChunkPos) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) World(net.minecraft.world.World) ClientWorld(net.minecraft.client.world.ClientWorld) ServerWorld(net.minecraft.world.server.ServerWorld) Chunk(net.minecraft.world.chunk.Chunk) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 15 with EntityCitizen

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;
}
Also used : EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)24 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)18 ICitizenData (com.minecolonies.api.colony.ICitizenData)12 ItemStack (net.minecraft.item.ItemStack)10 BlockPos (net.minecraft.util.math.BlockPos)10 NotNull (org.jetbrains.annotations.NotNull)10 CircleParticleEffectMessage (com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)6 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)6 Network (com.minecolonies.coremod.Network)6 AbstractJobGuard (com.minecolonies.coremod.colony.jobs.AbstractJobGuard)6 StreamParticleEffectMessage (com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage)6 IItemHandler (net.minecraftforge.items.IItemHandler)6 Nullable (org.jetbrains.annotations.Nullable)6 ImmutableList (com.google.common.collect.ImmutableList)4 TypeToken (com.google.common.reflect.TypeToken)4 IColony (com.minecolonies.api.colony.IColony)4 IColonyManager (com.minecolonies.api.colony.IColonyManager)4 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)4