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();
}
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);
}
}
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);
}
}
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()));
}
}
}
}
}
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));
}
Aggregations