use of net.minecraft.entity.item.EntityArmorStand in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method requestEntityToBuildingIfRequired.
/**
* Adds entities to the builder building if he needs it.
*/
private void requestEntityToBuildingIfRequired(final Template.EntityInfo entityInfo) {
if (entityInfo != null) {
final Entity entity = getEntityFromEntityInfoOrNull(entityInfo);
if (entity != null) {
final List<ItemStack> request = new ArrayList<>();
if (entity instanceof EntityItemFrame) {
final ItemStack stack = ((EntityItemFrame) entity).getDisplayedItem();
if (!InventoryUtils.isItemStackEmpty(stack)) {
stack.setCount(1);
request.add(stack);
}
request.add(new ItemStack(Items.ITEM_FRAME, 1));
} else if (entity instanceof EntityArmorStand) {
request.add(entity.getPickedResult(new RayTraceResult(worker)));
entity.getArmorInventoryList().forEach(request::add);
} else if (entity instanceof EntityMob) {
//Don't try to request the monster.
} else {
request.add(entity.getPickedResult(new RayTraceResult(worker)));
}
for (final ItemStack stack : request) {
final BuildingBuilder building = (BuildingBuilder) getOwnBuilding();
if (stack != null && stack.getItem() != null) {
building.addNeededResource(stack, 1);
}
}
}
}
}
use of net.minecraft.entity.item.EntityArmorStand in project SpongeCommon by SpongePowered.
the class MixinWorld method createEntity.
private Entity createEntity(EntityType type, Vector3d position, boolean naturally) throws IllegalArgumentException, IllegalStateException {
checkNotNull(type, "The entity type cannot be null!");
checkNotNull(position, "The position cannot be null!");
Entity entity = null;
Class<? extends Entity> entityClass = type.getEntityClass();
double x = position.getX();
double y = position.getY();
double z = position.getZ();
if (entityClass.isAssignableFrom(EntityPlayerMP.class) || entityClass.isAssignableFrom(MultiPartEntityPart.class)) {
// Unable to construct these
throw new IllegalArgumentException("Cannot construct " + type.getId() + " please look to using entity types correctly!");
}
net.minecraft.world.World world = (net.minecraft.world.World) (Object) this;
// Not all entities have a single World parameter as their constructor
if (entityClass.isAssignableFrom(EntityLightningBolt.class)) {
entity = (Entity) new EntityLightningBolt(world, x, y, z, false);
} else if (entityClass.isAssignableFrom(EntityEnderPearl.class)) {
EntityArmorStand tempEntity = new EntityArmorStand(world, x, y, z);
tempEntity.posY -= tempEntity.getEyeHeight();
entity = (Entity) new EntityEnderPearl(world, tempEntity);
((EnderPearl) entity).setShooter(ProjectileSource.UNKNOWN);
}
// set them is to use the more specialised constructor).
if (entityClass.isAssignableFrom(EntityFallingBlock.class)) {
entity = (Entity) new EntityFallingBlock(world, x, y, z, Blocks.SAND.getDefaultState());
} else if (entityClass.isAssignableFrom(EntityItem.class)) {
entity = (Entity) new EntityItem(world, x, y, z, new ItemStack(Blocks.STONE));
}
if (entity == null) {
try {
entity = ConstructorUtils.invokeConstructor(entityClass, this);
((net.minecraft.entity.Entity) entity).setPosition(x, y, z);
} catch (Exception e) {
throw new RuntimeException("There was an issue attempting to construct " + type.getId(), e);
}
}
if (naturally && entity instanceof EntityLiving) {
// Adding the default equipment
((EntityLiving) entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(x, y, z)), null);
}
if (entity instanceof EntityPainting) {
// This is default when art is null when reading from NBT, could
// choose a random art instead?
((EntityPainting) entity).art = EnumArt.KEBAB;
}
return entity;
}
use of net.minecraft.entity.item.EntityArmorStand in project Tropicraft by Tropicraft.
the class RenderArmorMask method render.
/*
* Arguments f0 to f5 are explained at:
* http://schwarzeszeux.tumblr.com/post/14176343101/minecraft-modeling-animation-part-2-of-x
*/
@Override
public void render(Entity entity, float f0, float f1, float f2, float f3, float f4, float f5) {
EntityLivingBase livingEntity = (EntityLivingBase) entity;
// livingEntity.rotationYawHead - livingEntity.rotationYaw;
float rotationYaw = f3;
if (livingEntity instanceof EntityArmorStand) {
rotationYaw = livingEntity.rotationYawHead;
}
/*
Don't call super class' render method, let the renderMask function handle it!
SetRotationAngles might me necessary, but I'm not sure.
*/
this.setRotationAngles(f0, f1, f2, rotationYaw, f4, f5, entity);
GlStateManager.pushMatrix();
if (entity.isSneaking()) {
GlStateManager.translate(0, 0.25f, 0);
}
// Set head rotation to mask
GlStateManager.rotate(rotationYaw, 0, 1, 0);
GlStateManager.rotate(f4, 1, 0, 0);
// Flip mask to face away from the player
GlStateManager.rotate(180, 0, 1, 0);
// put it in the middle in front of the face, eyeholes at (Steve's) eye height
GlStateManager.translate(-0.025F, 0.1F, 0.3F);
/*
renderMask handles the rendering of the mask model, but it doesn't set the texture.
Setting the texture is handled in the item class.
*/
mask.renderMask(this.maskType);
GlStateManager.popMatrix();
}
use of net.minecraft.entity.item.EntityArmorStand in project minecolonies by Minecolonies.
the class AbstractEntityAIStructure method spawnEntity.
/**
* Iterates through all entities and spawns them
* Suppressing Sonar Rule Squid:S3047
* The rule thinks we can merge the two forge loops iterating over resources
* But in this case the rule does not apply because that would destroy the logic.
*/
@SuppressWarnings(MULTIPLE_LOOPS_OVER_THE_SAME_SET_SHOULD_BE_COMBINED)
private Boolean spawnEntity(@NotNull final Structure.StructureBlock currentBlock) {
final Template.EntityInfo entityInfo = currentBlock.entity;
if (entityInfo == null) {
return true;
}
worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.spawning"));
final Entity entity = ItemStackUtils.getEntityFromEntityInfoOrNull(entityInfo, world);
if (entity != null && !isEntityAtPosition(entity, world)) {
final List<ItemStack> request = new ArrayList<>();
if (entity instanceof EntityItemFrame) {
final ItemStack stack = ((EntityItemFrame) entity).getDisplayedItem();
if (!ItemStackUtils.isEmpty(stack)) {
ItemStackUtils.changeSize(stack, 1);
request.add(stack);
}
request.add(new ItemStack(Items.ITEM_FRAME, 1));
} else if (entity instanceof EntityArmorStand) {
request.add(entity.getPickedResult(new RayTraceResult(worker)));
entity.getArmorInventoryList().forEach(request::add);
entity.getHeldEquipment().forEach(request::add);
} else {
request.add(entity.getPickedResult(new RayTraceResult(worker)));
}
if (!Configurations.gameplay.builderInfiniteResources) {
if (PlacementHandlers.checkForListInInvAndRequest(this, new ArrayList<>(request))) {
return false;
}
// Surpress
for (final ItemStack stack : request) {
if (ItemStackUtils.isEmpty(stack)) {
continue;
}
final int slot = worker.findFirstSlotInInventoryWith(stack.getItem(), stack.getItemDamage());
if (slot != -1) {
new InvWrapper(getInventory()).extractItem(slot, 1, false);
reduceNeededResources(stack);
}
}
}
entity.setUniqueId(UUID.randomUUID());
entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
if (!world.spawnEntity(entity)) {
Log.getLogger().info("Failed to spawn entity");
}
}
return true;
}
use of net.minecraft.entity.item.EntityArmorStand in project minecolonies by Minecolonies.
the class ItemStackUtils method getListOfStackForEntity.
/**
* Adds entities to the builder building if he needs it.
* @param entityInfo the entity info object.
* @param world the world.
* @param placer the entity placer.
* @return a list of stacks.
*/
public static List<ItemStack> getListOfStackForEntity(final Template.EntityInfo entityInfo, final World world, final Entity placer) {
if (entityInfo != null) {
final Entity entity = getEntityFromEntityInfoOrNull(entityInfo, world);
if (entity != null) {
final List<ItemStack> request = new ArrayList<>();
if (entity instanceof EntityItemFrame) {
final ItemStack stack = ((EntityItemFrame) entity).getDisplayedItem();
if (!ItemStackUtils.isEmpty(stack)) {
ItemStackUtils.setSize(stack, 1);
request.add(stack);
}
request.add(new ItemStack(Items.ITEM_FRAME, 1));
} else if (entity instanceof EntityArmorStand) {
request.add(entity.getPickedResult(new RayTraceResult(placer)));
entity.getArmorInventoryList().forEach(request::add);
entity.getHeldEquipment().forEach(request::add);
} else if (!(entity instanceof EntityMob)) {
request.add(entity.getPickedResult(new RayTraceResult(placer)));
}
return request;
}
}
return Collections.emptyList();
}
Aggregations