Search in sources :

Example 1 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class CitizenData method setJob.

/**
     * Sets the job of this citizen.
     *
     * @param job Job of the citizen.
     */
public void setJob(final AbstractJob job) {
    this.job = job;
    @Nullable final EntityCitizen localEntity = getCitizenEntity();
    if (localEntity != null) {
        localEntity.onJobChanged(job);
    }
    markDirty();
}
Also used : EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class RenderFishHook method doRender.

/**
     * Render a fishing hook entity in the world
     * This class uses some GL11 stuff
     * and seems hard to document...
     *
     * @param entity    the hook to render
     * @param x         the x position
     * @param y         the y position
     * @param z         the z position
     * @param entityYaw the angle thrown
     */
@Override
public void doRender(@NotNull final EntityFishHook entity, final double x, final double y, final double z, final float entityYaw, final float partialTicks) {
    GlStateManager.pushMatrix();
    GlStateManager.translate((float) x, (float) y, (float) z);
    GlStateManager.enableRescaleNormal();
    GlStateManager.scale(0.5F, 0.5F, 0.5F);
    this.bindEntityTexture(entity);
    final Tessellator tessellator = Tessellator.getInstance();
    final VertexBuffer vertexBuffer = tessellator.getBuffer();
    GlStateManager.rotate((float) (180.0D - this.renderManager.playerViewY), 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
    vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL);
    vertexBuffer.pos(-0.5D, -0.5D, 0.0D).tex(0.0625D, 0.1875D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexBuffer.pos(0.5D, -0.5D, 0.0D).tex(0.125D, 0.1875D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexBuffer.pos(0.5D, 0.5D, 0.0D).tex(0.125D, 0.125D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexBuffer.pos(-0.5D, 0.5D, 0.0D).tex(0.0625D, 0.125D).normal(0.0F, 1.0F, 0.0F).endVertex();
    tessellator.draw();
    GlStateManager.disableRescaleNormal();
    GlStateManager.popMatrix();
    EntityCitizen citizen = entity.getCitizen();
    //Check if he is a fisherman -> Through his texture
    if (citizen == null) {
        for (@NotNull final Object citizenX : entity.world.getEntitiesWithinAABB(EntityCitizen.class, entity.getEntityBoundingBox().expand(10, 10, 10))) {
            if (((EntityCitizen) citizenX).getModelID().textureBase.contains("Fisherman")) {
                citizen = (EntityCitizen) citizenX;
                break;
            }
        }
    }
    if (citizen != null) {
        final double orientation = citizen.getSwingProgress(partialTicks);
        final double finalOrientation = Math.sin(Math.sqrt(orientation) * Math.PI);
        @NotNull final Vec3d Vec3d = new Vec3d(-0.36D, 0.03D, 0.35D);
        Vec3d.rotatePitch((float) (-((double) citizen.prevRotationPitch + ((double) citizen.rotationPitch - (double) citizen.prevRotationPitch) * partialTicks) * Math.PI / Literals.HALF_CIRCLE));
        Vec3d.rotateYaw((float) (-((double) citizen.prevRotationYaw + ((double) citizen.rotationYaw - (double) citizen.prevRotationYaw) * partialTicks) * Math.PI / Literals.HALF_CIRCLE));
        Vec3d.rotateYaw((float) (finalOrientation * 0.5D));
        Vec3d.rotatePitch((float) (-finalOrientation * 0.7D));
        final double thirdPersonOffset = (citizen.prevRenderYawOffset + ((double) citizen.renderYawOffset - citizen.prevRenderYawOffset) * partialTicks) * Math.PI / Literals.HALF_CIRCLE;
        final double correctedPosX = citizen.prevPosX + (citizen.posX - citizen.prevPosX) * (double) partialTicks - MathHelper.cos((float) thirdPersonOffset) * 0.35D - MathHelper.sin((float) thirdPersonOffset) * 0.8D;
        final double correctedPosY = citizen.prevPosY + citizen.getEyeHeight() + (citizen.posY - citizen.prevPosY) * (double) partialTicks - 0.45D;
        final double correctedPosZ = citizen.prevPosZ + (citizen.posZ - citizen.prevPosZ) * (double) partialTicks - MathHelper.sin((float) thirdPersonOffset) * 0.35D + MathHelper.cos((float) thirdPersonOffset) * 0.8D;
        final double eyeHeight = citizen.isSneaking() ? -0.1875D : 0.0D;
        final double distX = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks;
        final double distY = entity.posY + 0.25;
        final double distZ = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks;
        final double correctionX = correctedPosX - distX;
        final double correctionY = correctedPosY - distY + eyeHeight;
        final double correctionZ = correctedPosZ - distZ;
        GlStateManager.disableTexture2D();
        GlStateManager.disableLighting();
        vertexBuffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
        for (int l = 0; l <= 16; ++l) {
            final double var = (double) l / 16.0;
            vertexBuffer.pos(x + correctionX * var, y + correctionY * (var * var + var) * 0.5D + 0.25D, z + correctionZ * var).color(0, 0, 0, 255).endVertex();
        }
        tessellator.draw();
        GlStateManager.enableLighting();
        GlStateManager.enableTexture2D();
        super.doRender(entity, x, y, z, entityYaw, partialTicks);
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) NotNull(org.jetbrains.annotations.NotNull) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class ColonyManager method deleteColony.

/**
     * Delete a colony and kill all citizens/purge all buildings.
     *
     * @param id the colonies id.
     */
public static void deleteColony(final int id) {
    try {
        final Colony colony = getColony(id);
        Log.getLogger().info("Deleting colony " + id);
        colonies.remove(id);
        coloniesByWorld.get(colony.getDimension()).remove(colony);
        final Set<World> colonyWorlds = new HashSet<>();
        Log.getLogger().info("Removing citizens for " + id);
        for (final CitizenData citizenData : new ArrayList<>(colony.getCitizens().values())) {
            Log.getLogger().info("Kill Citizen " + citizenData.getName());
            final EntityCitizen entityCitizen = citizenData.getCitizenEntity();
            if (entityCitizen != null) {
                final World world = entityCitizen.getEntityWorld();
                citizenData.getCitizenEntity().onDeath(CONSOLE_DAMAGE_SOURCE);
                colonyWorlds.add(world);
            }
        }
        Log.getLogger().info("Removing buildings for " + id);
        for (final AbstractBuilding building : new ArrayList<>(colony.getBuildings().values())) {
            final BlockPos location = building.getLocation();
            Log.getLogger().info("Delete Building at " + location);
            building.destroy();
            for (final World world : colonyWorlds) {
                if (world.getBlockState(location).getBlock() instanceof AbstractBlockHut) {
                    Log.getLogger().info("Found Block, deleting " + world.getBlockState(location).getBlock());
                    world.setBlockToAir(location);
                }
            }
        }
        Log.getLogger().info("Done with " + id);
    } catch (final RuntimeException e) {
        Log.getLogger().warn("Deleting Colony " + id + " errored:", e);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 4 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class BuildingBuilder method updateAvailableResources.

/**
     * Update the available resources.
     * <p>
     * which are needed for the build and in the builder's chest or inventory
     */
private void updateAvailableResources() {
    final EntityCitizen builder = getWorkerEntity();
    InventoryCitizen builderInventory = null;
    if (builder != null) {
        builderInventory = builder.getInventoryCitizen();
    }
    for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
        final BuildingBuilderResource resource = entry.getValue();
        resource.setAvailable(0);
        if (builderInventory != null) {
            resource.addAvailable(InventoryUtils.getItemCountInItemHandler(new InvWrapper(builderInventory), resource.getItem(), resource.getDamageValue()));
        }
        final TileEntity chestInventory = this.getTileEntity();
        if (chestInventory != null) {
            resource.addAvailable(InventoryUtils.getItemCountInProvider(chestInventory, resource.getItem(), resource.getDamageValue()));
        }
        //Count in the additional chests as well
        if (builder != null) {
            for (final BlockPos pos : getAdditionalCountainers()) {
                final TileEntity entity = builder.world.getTileEntity(pos);
                if (entity instanceof TileEntityChest) {
                    resource.addAvailable(InventoryUtils.getItemCountInProvider(entity, resource.getItem(), resource.getDamageValue()));
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class KillCitizenCommand method executeSpecializedCode.

@Override
void executeSpecializedCode(@NotNull final MinecraftServer server, final ICommandSender sender, final Colony colony, final int citizenId) {
    final CitizenData citizenData = colony.getCitizen(citizenId);
    final EntityCitizen entityCitizen = citizenData.getCitizenEntity();
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizenData.getId(), citizenData.getName())));
    final BlockPos position = entityCitizen.getPosition();
    sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
    sender.sendMessage(new TextComponentString(REMOVED_MESSAGE));
    server.addScheduledTask(() -> entityCitizen.onDeath(CONSOLE_DAMAGE_SOURCE));
}
Also used : CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)12 BlockPos (net.minecraft.util.math.BlockPos)7 CitizenData (com.minecolonies.coremod.colony.CitizenData)4 TextComponentString (net.minecraft.util.text.TextComponentString)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)2 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 Colony (com.minecolonies.coremod.colony.Colony)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 JobGuard (com.minecolonies.coremod.colony.jobs.JobGuard)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 AbstractAISkeleton (com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton)1 InventoryCitizen (com.minecolonies.coremod.inventory.InventoryCitizen)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)1 EntityMob (net.minecraft.entity.monster.EntityMob)1