Search in sources :

Example 1 with EntityArmorStand

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);
                }
            }
        }
    }
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) ItemStack(net.minecraft.item.ItemStack)

Example 2 with EntityArmorStand

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;
}
Also used : Entity(org.spongepowered.api.entity.Entity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityLiving(net.minecraft.entity.EntityLiving) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) EntityEnderPearl(net.minecraft.entity.item.EntityEnderPearl) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) EntityPainting(net.minecraft.entity.item.EntityPainting) PositionOutOfBoundsException(org.spongepowered.api.util.PositionOutOfBoundsException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with EntityArmorStand

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();
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand)

Example 4 with EntityArmorStand

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;
}
Also used : Entity(net.minecraft.entity.Entity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) Template(net.minecraft.world.gen.structure.template.Template) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 5 with EntityArmorStand

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();
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand)

Aggregations

EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)11 ArrayList (java.util.ArrayList)4 Entity (net.minecraft.entity.Entity)4 EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)4 ItemStack (net.minecraft.item.ItemStack)4 BlockPos (net.minecraft.util.math.BlockPos)4 EntityBoat (net.minecraft.entity.item.EntityBoat)3 EntityItemFrame (net.minecraft.entity.item.EntityItemFrame)3 EntityPig (net.minecraft.entity.passive.EntityPig)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3 EntityMob (net.minecraft.entity.monster.EntityMob)2 TileEntity (net.minecraft.tileentity.TileEntity)2 World (net.minecraft.world.World)2 EntityMountable (org.valkyrienskies.mod.common.entity.EntityMountable)2 Vector (ValkyrienWarfareBase.API.Vector)1 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)1 EntityMountingWeaponBase (ValkyrienWarfareCombat.Entity.EntityMountingWeaponBase)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1